Skip to content

[Bug] [Table model] BETWEEN on INT32/INT64 fields wraps out-of-range integers, fails on decimal literals, and loses INT64 precision #19438

Backlog

Description

@JackieTien97

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:

  1. Filter pushdown (ConvertPredicateToFilterVisitor.constructBetweenFilter):
    Lines 576–582 call getValue((Literal) minValue, type) and getValue((Literal) maxValue, type) directly:

    • Out-of-range LongLiteral bounds on an INT32 column are narrowed via (int), wrapping to unrelated integers (e.g. WHERE int32_col BETWEEN 1 AND 4294967298 becomes BETWEEN 1 AND 2).
    • Decimal (DoubleLiteral/FloatLiteral) bounds on INT32/INT64 columns throw ClassCastException: DoubleLiteral cannot be cast to LongLiteral (e.g. WHERE int32_col BETWEEN 1 AND 2.5, WHERE int64_col BETWEEN 1 AND 9223372036854775808.0).
  2. Projection / non-pushdown (BetweenColumnTransformer):
    Lines 110–119 in iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/transformation/dag/column/ternary/BetweenColumnTransformer.java compare all numeric types via getDouble(...), rounding INT64/TIMESTAMP values above 2^53.

    • For int64_col = 9223372036854775807 (Long.MAX_VALUE), SELECT int64_col BETWEEN 9223372036854775808.0 AND 9223372036854775808.0 evaluates to true, and SELECT int64_col BETWEEN 9007199254740992 AND 9007199254740992 evaluates to true for 9007199254740993.

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?

Related to #16917 and #19277.

Are you willing to submit a PR?

  • I'm willing to submit a PR!

Activity

  1. added
    bug
    on Nov 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions