Skip to content

fix(spec): reject non-finite partition values when writing DataFile JSON - #3529

Open
ninglinLiu wants to merge 2 commits into
apache:mainfrom
ninglinLiu:fix/reject-nonfinite-json-literals
Open

ninglinLiu wants to merge 2 commits into
apache:mainfrom
ninglinLiu:fix/reject-nonfinite-json-literals

Conversation

@ninglinLiu

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

#3476 fixed the first half of the issue (valid floats such as 123.456 being rejected on read). This PR covers the second half: non-finite partition values silently becoming null.

What changes are included in this PR?

JSON has no representation for NaN or ±Infinity, and serde_json writes them as null. So serialize_data_file_to_json turned a non-finite float or double partition value into null, and deserialize_data_file_from_json then read it back as a null partition value, with no error anywhere. That is how the incorrect metadata in the issue got committed.

serialize_data_file_to_json now checks the partition tuple before serializing and returns a DataInvalid error naming the partition field when a float or double value is not finite, instead of writing null. Finite values are unchanged. The Avro manifest path is not touched, since Avro stores these values exactly.

Are these changes tested?

Yes. test_data_file_to_json_rejects_non_finite_partition_values round-trips a data file with finite float and double partition values, and checks that NaN, +Infinity (float) and NaN, -Infinity (double) are rejected with an error naming the field. The test fails on main and passes with the change. cargo test -p iceberg --lib spec::manifest and cargo clippy -p iceberg --all-targets -- -D warnings pass.

This PR was prepared with AI assistance and reviewed/tested by the author.

This branch has not been deployed

No deployments
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.

JSON data-file helpers reject valid floats and silently corrupt non-finite partition values

1 participant