[FLINK-35276][table] Fix incorrect sort order for floating-point negative zero in generated comparators#28383
Open
Au-Miner wants to merge 1 commit into
Open
[FLINK-35276][table] Fix incorrect sort order for floating-point negative zero in generated comparators#28383Au-Miner wants to merge 1 commit into
Au-Miner wants to merge 1 commit into
Conversation
…tive zero in generated comparators
Collaborator
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.
What is the purpose of the change
The generated sort comparator in
GenerateUtils.scalauses the ternary expression(a > b ? 1 : a < b ? -1 : 0)for FLOAT and DOUBLE types, which treats0.0and-0.0as equal. This causesSortCodeGeneratorTest.testMultiKeysto fail intermittently when random test data contains negative zero, because the Java reference sort usesFloat.compare()/Double.compare()which distinguish+0.0from-0.0.Brief change log
GenerateUtils.scala: Split FLOAT and DOUBLE out of the integer comparison branch; generateFloat.compare()/Double.compare()calls instead of the ternary expressionSortCodeGeneratorTest.java: AddtestFloatNegativeZeroSortKey()with deterministic0.0f/-0.0ftest data to verify the fix without relying on random seed probabilityVerifying this change
This change added a new test
SortCodeGeneratorTest#testFloatNegativeZeroSortKeythat constructs rows with0.0fand-0.0fsort keys and asserts the generated comparator produces the same order as the Java reference sort.The existing
testMultiKeys(100 random iterations) also covers this path and will no longer flake.Does this pull request potentially affect one of the following parts
@Public(Evolving): noFloat.compare()/Double.compare()are JIT intrinsics with negligible overhead compared to the previous ternary expressionDocumentation