Repository navigation
Conversation
The comparison and BETWEEN evaluators (table-model column transformers, constant folding in IrExpressionInterpreter and the tree-model transformers) used Double.compare, which orders -0.0 before 0.0. The pushed-down TsFile value filters use primitive comparison, so a row holding -0.0 matched WHERE v = 0.0 but not WHERE v = 0.0 OR dev = 'x'. Compare through a shared CommonTransformUtils.compare(double, double) that returns 0 when the values are ==, and otherwise falls back to Double.compare, so NaN handling is unchanged. Fixes apache#19441
Contributor
Author
|
The CI workflows for this PR are waiting for approval since it comes from a fork. Could a maintainer approve them when convenient? The new unit test and both affected IT classes pass locally. |
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.
Description
Fixes #19441
Problem
For FLOAT/DOUBLE values equal to
-0.0, the result of a comparison depended on whether the predicate was pushed down:-0.0 == 0.0.Double.compare, which orders-0.0before0.0.So a row holding
-0.0matchedWHERE v = 0.0, but notWHERE v = 0.0 OR dev = 'nope'(that predicate stays in aFilternode). Projections such asSELECT v = 0.0and constant folding (SELECT -0.0 = 0.0) reportedfalse. This affected both the table and tree models.Change
I added
CommonTransformUtils.compare(double, double)next to the existingcompare(Binary, Binary):It differs from
Double.compareonly for the pair-0.0/0.0.==is never true for NaN, so NaN still goes throughDouble.compareand keeps its current results (NaN semantics are discussed separately in #19439).The evaluators that used
Double.comparenow call this helper:CompareBinaryColumnTransformerandBetweenColumnTransformer(calc-commons, table model)IrExpressionInterpreter.evaluateNumericComparison(constant folding)Compare{EqualTo,NonEqual,LessThan,LessEqual,GreaterThan,GreaterEqual}TransformerandBetweenTransformer(tree model)Ordering code (sort, ORDER BY, extreme aggregation) is not changed.
Before / after
I ran the same statements on a standalone server built from
96a0c6d(before) and from this branch (after).WHERE v = 0.0(pushed down)WHERE v = 0.0 OR dev = 'nope'WHERE v >= 0.0 OR dev = 'nope'WHERE v < 0.0 OR dev = 'nope'WHERE f = 0.0 OR dev = 'nope'(FLOAT)v = 0.0, v <> 0.0, v < 0.0, v >= 0.0, v BETWEEN 0.0 AND 1.0for t1SELECT -0.0 = 0.0, -0.0 < 0.0SELECT v FROM root.zsg.d1 WHERE v * 1.0 = 0.0WHERE v = 0.0)v = 0.0, v < 0.0, v >= 0.0for -0.0After the fix (table model):
Tests
FloatingPointCompareColumnTransformerTestcovers DOUBLE and FLOAT over the column-0.0, 0.0, NaN, 1.0, testing=,<>,<,<=,>,>=, reversed operands,BETWEENandNOT BETWEEN. The NaN rows assert the current results, so they stay unchanged. On96a0c6dthe test fails for both types:arrays first differed at element [0]; expected:<true> but was:<false>. With this change it passes.IoTDBFilterTableIT#testSignedZeroComparisonchecks that pushed-down and non-pushed-down predicates return the same rows, and covers projections andSELECT -0.0 = 0.0.IoTDBFilterIT#testSignedZeroComparison(tree model) checks thatWHERE v = 0.0andWHERE v * 1.0 = 0.0agree, and covers projected comparisons.Commands I ran locally (JDK 25, macOS arm64):
./mvnw -o package -pl distribution -am -Drat.skip=true '-Dtest=FloatingPointCompareColumnTransformerTest,ArithmeticAndCompareBinaryColumnTransformerTest,*Transformer*Test,*ExpressionInterpreter*Test,*Between*Test,*ConstantFold*Test' -Dsurefire.failIfNoSpecifiedTests=false./mvnw -o test -pl iotdb-core/calc-commons -am '-Dtest=org/apache/iotdb/calc/**/*' -Dsurefire.failIfNoSpecifiedTests=false./mvnw -o verify -DskipUTs -Dit.test=IoTDBFilterTableIT -pl integration-test -am -PTableSimpleIT -P with-integration-tests ...@IgnoreontestFilterWithUDTF../mvnw -o verify -DskipUTs -Dit.test=IoTDBFilterIT -pl integration-test -am -PClusterIT -P with-integration-tests ..../mvnw -o test-compile -pl iotdb-core/datanode -am -P with-zh-locale -DskipTestsThis PR has:
Key changed/added classes (or packages if there are too many classes) in this PR
CommonTransformUtilsCompareBinaryColumnTransformer,BetweenColumnTransformerIrExpressionInterpreterCompare*Transformer,BetweenTransformer