fix: normalize signed zero in nested float array comparisons - #5235
Open
divyankshah wants to merge 1 commit into
Open
fix: normalize signed zero in nested float array comparisons#5235divyankshah wants to merge 1 commit into
divyankshah wants to merge 1 commit into
Conversation
Arrow's nested comparator uses total order, where -0.0 and 0.0 are distinct, but Spark's ordering.equiv treats them as equal, while still treating NaN as equal to itself. Normalize negative zero in nested float leaves before building the comparator so arrays_overlap and array_position match Spark's semantics. Ref apache#5191
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Closes #5191.
Rationale for this change
Arrow's nested comparator (
make_comparator, used byarrays_overlap's nested path andarray_position's nested fallback) orders floats by total order, where-0.0and0.0are distinct. Spark'sordering.equiv(used for structural equality of nested elements) checks numeric equality first, so-0.0 == 0.0there, whileNaN == NaNstill holds in both.What changes are included in this PR?
nested_float_normalize.rs: recursively rebuilds nested (List/LargeList/FixedSizeList/Struct) arrays with-0.0normalized to0.0in Float32/Float64 leaves, leaving NaN untouched.arrays_overlap.rs: normalize both sides before building the nested comparator; updatetest_nested_float_total_orderto assert-0.0and0.0now overlap; addtest_struct_float_field_signed_zero_overlapcovering a struct field.array_position.rs: normalize both sides before building the fallback comparator; updatetest_nested_float_and_null_position(result changes from[2, 2, 1]to[2, 1, 1]since row 1's-0.0vs0.0now matches at position 1); addtest_struct_float_field_signed_zero_positioncovering a struct field.Note: #5194 is a separate issue (#5101, comparator-hoisting for perf) but touches the same comparator-construction code path. Happy to rebase on top of whichever lands first.
How are these changes tested?
cargo test -p datafusion-comet-spark-expr— all 600+ tests pass, including the new/updated ones above.cargo clippy -p datafusion-comet-spark-expr --lib -- -D warnings— clean.cargo fmt -p datafusion-comet-spark-expr -- --check— clean.cargo check --workspace— clean.