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
When a multi-value IN predicate in the table model contains any non-literal expression (e.g. another column, arithmetic expression, or non-folded CAST), ColumnTransformerBuilder.visitInPredicate puts the non-literal items into valueColumnTransformerList and evaluates them in In*MultiColumnTransformer.satisfy(List<Column> childrenColumns, int index).
There are two bugs in these transformers:
-
Wrong index passed to
isNull(...)in all sixIn*MultiColumnTransformersubclasses:InInt32MultiColumnTransformer.java:48InInt64MultiColumnTransformer.java:48InFloatMultiColumnTransformer.java:48InDoubleMultiColumnTransformer.java:48InBinaryMultiColumnTransformer.java:49InBooleanMultiColumnTransformer.java:48
Every subclass checks
if (!valueColumn.isNull(i))(using the operand loop variablei) instead ofif (!valueColumn.isNull(index))(the row index). When aTsBlockhaspositionCount <= i(for example, a 1-row block with a single non-literal item ati = 1),valueColumn.isNull(1)throwsArrayIndexOutOfBoundsException; otherwise it reads the NULL flag of the wrong row. -
Unchecked narrowing, truncation, and saturation for mixed-type numeric expressions in
InInt32MultiColumnTransformerandInInt64MultiColumnTransformer:InInt32MultiColumnTransformer.java:50callsvalueType.getInt(valueColumn, index):- An
INT64column value outsideINT32range wraps via(int)(e.g.4294967326wraps to30). - A
DOUBLE/FLOATexpression truncates toward zero via(int)(e.g.29.5truncates to29).
- An
InInt64MultiColumnTransformer.java:50callsvalueType.getLong(valueColumn, index):- A
DOUBLE/FLOATexpression truncates toward zero (29.5 -> 29) and saturates>= 2^63ontoLong.MAX_VALUE.
- A
Minimal repro:
CREATE DATABASE test_in_expr;
USE test_in_expr;
CREATE TABLE t(i INT32 FIELD, l INT64 FIELD, d DOUBLE FIELD);
INSERT INTO t(time, i, l, d) VALUES (1, 30, 4294967326, 30.5);
INSERT INTO t(time, i, l, d) VALUES (2, 29, 9223372036854775807, 9223372036854775808.0);
-- Wrongly matches row 1 because 4294967326 narrows to 30
SELECT time, i FROM t WHERE i IN (20, l);
-- Wrongly matches both rows because i + 0.5 truncates to i
SELECT time, i FROM t WHERE i IN (20, i + 0.5);
-- Wrongly matches row 2 because 9223372036854775808.0 saturates to Long.MAX_VALUE
SELECT time, l FROM t WHERE l IN (0, d);What did you expect to see?
isNull(index)is checked for the current row rather than the operand indexi.- Non-literal numeric items in
INlists follow the same exact comparison semantics as=: out-of-range integers, non-integral floating-point values, and>= 2^63doubles do not matchINT32/INT64values.
What did you see instead?
ArrayIndexOutOfBoundsExceptionon short blocks (e.g. 1-rowTsBlock) or wrong NULL handling when evaluating non-literalINitems.- False matches due to
(int)/(long)narrowing, truncation, and saturation inInInt32MultiColumnTransformerandInInt64MultiColumnTransformer.
Anything else?
Related to #19276 / #19277, which fixes literal-only multi-value IN lists on INT32/INT64 fields.
Note also that InMultiColumnTransformer currently returns false instead of NULL when a non-literal candidate evaluates to NULL and no other item matches (SQL three-valued logic for IN/NOT IN).
Are you willing to submit a PR?
- I'm willing to submit a PR!
Activity