Description
Search before asking
- I searched in the issues and found nothing similar.
Version
master (table model), discovered while reviewing #19277.
Describe the bug and provide the minimal reproduce step
In the table model, BETWEEN predicates on INT32 and INT64 fields have two bugs mirroring the IN and comparison bugs addressed in #16917 and #19277:
-
Filter pushdown (
ConvertPredicateToFilterVisitor.constructBetweenFilter):
Lines 576–582 callgetValue((Literal) minValue, type)andgetValue((Literal) maxValue, type)directly:- Out-of-range
LongLiteralbounds on anINT32column are narrowed via(int), wrapping to unrelated integers (e.g.WHERE int32_col BETWEEN 1 AND 4294967298becomesBETWEEN 1 AND 2). - Decimal (
DoubleLiteral/FloatLiteral) bounds onINT32/INT64columns throwClassCastException: DoubleLiteral cannot be cast to LongLiteral(e.g.WHERE int32_col BETWEEN 1 AND 2.5,WHERE int64_col BETWEEN 1 AND 9223372036854775808.0).
- Out-of-range
-
Projection / non-pushdown (
BetweenColumnTransformer):
Lines 110–119 iniotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/transformation/dag/column/ternary/BetweenColumnTransformer.javacompare all numeric types viagetDouble(...), roundingINT64/TIMESTAMPvalues above2^53.- For
int64_col = 9223372036854775807(Long.MAX_VALUE),SELECT int64_col BETWEEN 9223372036854775808.0 AND 9223372036854775808.0evaluates totrue, andSELECT int64_col BETWEEN 9007199254740992 AND 9007199254740992evaluates totruefor9007199254740993.
- For
Minimal repro:
CREATE DATABASE test_between;
USE test_between;
CREATE TABLE t(i INT32 FIELD, l INT64 FIELD);
INSERT INTO t(time, i, l) VALUES (1, 1, 9007199254740993), (2, 2, 9223372036854775807), (3, 10, 10);
-- Wraps 4294967298 to 2 and misses row 3 (i = 10)
SELECT time, i FROM t WHERE i BETWEEN 1 AND 4294967298;
-- ClassCastException: DoubleLiteral cannot be cast to LongLiteral
SELECT time, i FROM t WHERE i BETWEEN 1 AND 2.5;
SELECT time, l FROM t WHERE l BETWEEN 1 AND 9223372036854775808.0;
-- Precision loss through double: returns true for Long.MAX_VALUE and 9007199254740993
SELECT time, l BETWEEN 9223372036854775808.0 AND 9223372036854775808.0 FROM t;
SELECT time, l BETWEEN 9007199254740992 AND 9007199254740992 FROM t;What did you expect to see?
x BETWEEN a AND b produces the exact same result as x >= a AND x <= b in both filter pushdown and projection/non-pushdown paths, without integer wrap-around, ClassCastException, or INT64 double-rounding precision loss.
What did you see instead?
Wrong rows for out-of-range INT32 bounds, ClassCastException for decimal bounds in WHERE, and false true results for INT64 values above 2^53 in BetweenColumnTransformer.
Anything else?
Are you willing to submit a PR?
- I'm willing to submit a PR!
Activity