Skip to content

fix: reject non-finite floating-point default values#810

Open
huan233usc wants to merge 1 commit into
apache:mainfrom
huan233usc:fix/reject-nan-inf-default
Open

fix: reject non-finite floating-point default values#810
huan233usc wants to merge 1 commit into
apache:mainfrom
huan233usc:fix/reject-nan-inf-default

Conversation

@huan233usc

Copy link
Copy Markdown
Contributor

What

A float / double column default of NaN or ±Infinity passes SchemaField::Validate but cannot survive a metadata round-trip: the JSON serializer emits a non-finite number as null, which reads back as an absent default. The declared default is silently lost (and, because the key is present but null, the reader then errors on it).

How

ValidateDefault now rejects a non-finite floating default (std::isfinite on the float/double value) with a clear "value must be finite" error, so an unrepresentable default is caught up front rather than silently dropped on serialization.

Testing

SchemaFieldTest.ValidateRejectsNonFiniteFloatingDefault (NaN, +Inf, -Inf) and ValidateAcceptsFiniteFloatingDefault, verified fail-without / pass-with. Full schema_test passes (551 tests).

@evindj evindj left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me. For my own understanding how is the caller supposed to handle this error?

// it as `null`, which reads back as an absent default. Reject it so the default is not
// silently lost when the metadata round-trips.
const auto& literal_value = value.value();
const bool non_finite = (std::holds_alternative<float>(literal_value) &&

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mentioned NaN in the PR description but doesn't seem to handle that, is that intentional?

@zhjwpku

zhjwpku commented Jul 5, 2026

Copy link
Copy Markdown
Collaborator

I think java impl has the same issue, created a PR to strict the validation apache/iceberg#17106

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants