Repository navigation
GH-46183: [C++][Compute] Make is_in and index_in treat -0.0 and +0.0 as equal - #54915
Open
sankalpsthakur wants to merge 1 commit into
Open
sankalpsthakur wants to merge 1 commit into
sankalpsthakur wants to merge 1 commit into
Conversation
… +0.0 as equal is_in and index_in look floating-point values up through their unsigned integer bit patterns, so -0.0 and +0.0 were different keys although they compare equal. A Parquet column that only holds zeros has statistics min=-0.0 and max=+0.0, which the dataset layer turns into the guarantee `x == -0.0`. That folded `x IN (0.0)` to false and silently dropped every row of the fragment. Fold -0.0 into +0.0, for both the value set and the probed values, when the value set is floating point.
|
|
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.
Rationale for this change
is_inandindex_inlook floating-point values up through their unsigned integer bit patterns, so-0.0and+0.0are different keys even thoughequaltreats them as the same value:This silently drops rows from dataset scans. The Parquet format asks writers to put
-0.0in the min and+0.0in the max statistic when the computed value is zero, so a column that only holds zeros gets min=-0.0, max=+0.0.EvaluateStatisticsAsExpressionturns that into the guaranteex == -0.0,SimplifyWithGuaranteesubstitutesxby-0.0and constant-foldsx IN (0.0)through theis_inkernel, which says false, so the whole fragment is skipped:The reporter's analysis in the issue traced the empty result to the signed zero in the Parquet statistics.
What changes are included in this PR?
SetLookupStateinscalar_set_lookup.ccfolds the bit pattern of-0.0into+0.0, both when the value set is built and when values are probed, if the value set is floating-point. Integers of the same width are not touched (their smallest value has the same bit pattern as-0.0).I did not change
ScalarHelper<float/double>::ComputeHashinhashing.h, which is where the issue discussion pointed. These kernels do not use it:InitStateVisitormaps every fixed-width numeric type to an unsigned integer state, so it isScalarMemoTable<uint64_t>that hashes doubles here. AndScalarMemoTableis also the table behindunique,value_counts,dictionary_encode,DictionaryBuilderand the Parquet dictionary encoder, where merging-0.0into0.0would silently change stored values (a dictionary-encoded Parquet column keeps the sign of zero across a round trip today; see also ARROW-10211). So this only makes set membership agree withequal. NaN handling, the other hash-based kernels and the Acero hash join / group_by (which still keep the two zeros apart) are unchanged.Are these changes tested?
Yes: C++ tests for
is_inandindex_inon float and double (single, chunked and duplicated value sets, and integer guards) inscalar_set_lookup_test.cc,Expression.SimplifyIsInSignedZerofor the dataset guarantee path, and two pytests (test_is_in_index_in_signed_zero,test_filter_isin_signed_zero). They fail without the change.Are there any user-facing changes?
is_inandindex_inon float and double now match-0.0with+0.0and the reverse, asequaldoes.This PR contains a "Critical Fix". It fixes (b), a bug that caused incorrect data to be produced: dataset filters using
isinon a float column silently returned no rows for fragments whose values are all zero.Was AI used for this PR?
PR code and description written by:
Reviewed before submission by:
AI disclosure: Claude Code wrote the fix, the tests and this description; the tests were run with and without the change before submitting.