Skip to content

[Bug] [Table model] Multi-value IN on TIMESTAMP, FLOAT, and DOUBLE columns mishandles mixed numeric literals #19436

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, CommonMetadataUtils.isTwoTypeComparable allows comparing any two types in {INT32, INT64, TIMESTAMP, FLOAT, DOUBLE}, and ExpressionAnalyzer.visitInPredicate does not insert casts for IN lists. Outside of INT32/INT64 with Long/Double/Float literals (addressed in #19277), several numeric IN combinations still produce wrong results or exceptions:

  1. TIMESTAMP field columns truncate/saturate decimal literals and disagree across pushdown, projection, and deduplicated IN:

    • Projection (calc-commons TypeServices.IN_MULTI_COLUMN_TRANSFORMER_SERVICE, case TIMESTAMP) casts DoubleLiteral/FloatLiteral directly via (long).
    • Pushdown (ConvertPredicateToFilterVisitor.constructInSet / constructCompareFilter -> datanode TypeServices.getTimestampValue) also casts DoubleLiteral directly via (long) and rejects FloatLiteral.
    • With exact TIMESTAMP comparison in CompareBinaryColumnTransformer (Fix multi-value IN on INT32/INT64 fields in the table model #19277), a deduplicated list SELECT ts IN (9223372036854775808.0, 9223372036854775808.0) evaluates to false for Long.MAX_VALUE, while SELECT ts IN (9223372036854775808.0, 0) evaluates to true.
    • WHERE ts IN (1, 2.5), SELECT ts IN (1, 2.5), and WHERE ts = 2.5 truncate 2.5 to 2 and wrongly match ts = 2.
  2. FLOAT and DOUBLE columns fail on integer (LongLiteral) items in non-pushed-down IN / NOT IN / projections:

    • calc-commons TypeServices.IN_MULTI_COLUMN_TRANSFORMER_SERVICE (case FLOAT and case DOUBLE) casts any non-FloatLiteral directly to DoubleLiteral, throwing ClassCastException: LongLiteral cannot be cast to DoubleLiteral for queries such as SELECT d_col IN (1, 2) or WHERE f_col NOT IN (1, 2) (whereas pushed-down WHERE d_col IN (1, 2) works via getDoubleValue).
  3. GenericLiteral (TIMESTAMP / INT64) in INT32/INT64 IN lists and pushed-down =:

    • ExpressionAnalyzer accepts int64_col IN (20, CAST(30 AS TIMESTAMP)) (IrExpressionInterpreter folds CAST(30 AS TIMESTAMP) to GenericLiteral("TIMESTAMP", "30")).
    • SELECT int64_col IN (CAST(30 AS TIMESTAMP), CAST(30 AS TIMESTAMP)) deduplicates to = and succeeds in projection, whereas SELECT/WHERE int64_col IN (20, CAST(30 AS TIMESTAMP)) fails (GenericLiteral is rejected by getIntegralInListValue and getLongValue).

Minimal repro:

CREATE DATABASE test_in_numeric_types;
USE test_in_numeric_types;
CREATE TABLE t(ts TIMESTAMP FIELD, f FLOAT FIELD, d DOUBLE FIELD, l INT64 FIELD);
INSERT INTO t(time, ts, f, d, l) VALUES (1, 2, 1.0, 1.0, 30);
INSERT INTO t(time, ts, f, d, l) VALUES (2, 9223372036854775807, 2.0, 2.0, 9223372036854775807);

-- Wrongly matches row 1 (ts = 2)
SELECT time, ts FROM t WHERE ts IN (1, 2.5);
SELECT time, ts IN (1, 2.5) FROM t;
SELECT time, ts FROM t WHERE ts = 2.5;

-- Wrongly matches row 2 (ts = Long.MAX_VALUE)
SELECT time, ts FROM t WHERE ts IN (9223372036854775808.0, 0);
SELECT time, ts IN (9223372036854775808.0, 0) FROM t;

-- ClassCastException: LongLiteral cannot be cast to DoubleLiteral
SELECT time, d IN (1, 2) FROM t;
SELECT time, f FROM t WHERE f NOT IN (1, 2);

-- Fails despite ExpressionAnalyzer accepting it and single-value SELECT working
SELECT time, l IN (20, CAST(30 AS TIMESTAMP)) FROM t;

What did you expect to see?

  • TIMESTAMP field comparisons and IN lists handle decimal/float literals and the 2^63 upper bound with the same exact semantics as INT64, consistently across WHERE, SELECT, and deduplicated IN.
  • FLOAT and DOUBLE IN lists accept integer (LongLiteral) literals in both pushdown and projection/NOT IN paths (respecting precision/rounding rules).
  • GenericLiteral numeric literals (TIMESTAMP, INT64) behave consistently across single-value = and multi-value IN.

What did you see instead?

Wrong rows on TIMESTAMP columns (2.5 -> 2, 2^63 -> Long.MAX_VALUE), ClassCastException on FLOAT/DOUBLE IN with integer literals, and SemanticException/ClassCastException on GenericLiteral items.

Anything else?

Related to #19276 / #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