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, 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:
-
TIMESTAMPfield columns truncate/saturate decimal literals and disagree across pushdown, projection, and deduplicatedIN:- Projection (
calc-commonsTypeServices.IN_MULTI_COLUMN_TRANSFORMER_SERVICE,case TIMESTAMP) castsDoubleLiteral/FloatLiteraldirectly via(long). - Pushdown (
ConvertPredicateToFilterVisitor.constructInSet/constructCompareFilter->datanodeTypeServices.getTimestampValue) also castsDoubleLiteraldirectly via(long)and rejectsFloatLiteral. - With exact
TIMESTAMPcomparison inCompareBinaryColumnTransformer(Fix multi-value IN on INT32/INT64 fields in the table model #19277), a deduplicated listSELECT ts IN (9223372036854775808.0, 9223372036854775808.0)evaluates tofalseforLong.MAX_VALUE, whileSELECT ts IN (9223372036854775808.0, 0)evaluates totrue. WHERE ts IN (1, 2.5),SELECT ts IN (1, 2.5), andWHERE ts = 2.5truncate2.5to2and wrongly matchts = 2.
- Projection (
-
FLOATandDOUBLEcolumns fail on integer (LongLiteral) items in non-pushed-downIN/NOT IN/ projections:calc-commonsTypeServices.IN_MULTI_COLUMN_TRANSFORMER_SERVICE(case FLOATandcase DOUBLE) casts any non-FloatLiteraldirectly toDoubleLiteral, throwingClassCastException: LongLiteral cannot be cast to DoubleLiteralfor queries such asSELECT d_col IN (1, 2)orWHERE f_col NOT IN (1, 2)(whereas pushed-downWHERE d_col IN (1, 2)works viagetDoubleValue).
-
GenericLiteral(TIMESTAMP/INT64) inINT32/INT64INlists and pushed-down=:ExpressionAnalyzeracceptsint64_col IN (20, CAST(30 AS TIMESTAMP))(IrExpressionInterpreterfoldsCAST(30 AS TIMESTAMP)toGenericLiteral("TIMESTAMP", "30")).SELECT int64_col IN (CAST(30 AS TIMESTAMP), CAST(30 AS TIMESTAMP))deduplicates to=and succeeds in projection, whereasSELECT/WHERE int64_col IN (20, CAST(30 AS TIMESTAMP))fails (GenericLiteralis rejected bygetIntegralInListValueandgetLongValue).
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?
TIMESTAMPfield comparisons andINlists handle decimal/float literals and the2^63upper bound with the same exact semantics asINT64, consistently acrossWHERE,SELECT, and deduplicatedIN.FLOATandDOUBLEINlists accept integer (LongLiteral) literals in both pushdown and projection/NOT INpaths (respecting precision/rounding rules).GenericLiteralnumeric literals (TIMESTAMP,INT64) behave consistently across single-value=and multi-valueIN.
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?
Are you willing to submit a PR?
- I'm willing to submit a PR!
Activity