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
Comparisons against a NaN floating-point literal (e.g. CAST('NaN' AS DOUBLE)) on INT32/INT64 columns behave inconsistently across filter pushdown, projection, and deduplicated NOT IN:
-
Ordered comparisons in
ConvertPredicateToFilterVisitor.constructCompareFilter/constructFilterFromDouble:
NaNfails both range checks (NaN >= 0x1p63andNaN < Long.MIN_VALUEare bothfalse) and falls through intoconstructFilterFromDouble. For<,<=,>,>=,(long) Math.ceil(Double.NaN)and(long) Math.floor(Double.NaN)evaluate to0L, silently turningint64_col < CAST('NaN' AS DOUBLE)intoint64_col < 0instead of always-false. -
!= NaNinconsistency between pushdown /PushDownNegationsandCompareBinaryColumnTransformer:PushDownNegationsExpressionRewriterrewritesNOT (x = NaN)tox != NaN.- In pushdown,
constructFilterFromDouble(NOT_EQUAL, NaN, ...)returnsValueIsNotNullOperator(matches all non-NULL rows). - In projection,
CompareBinaryColumnTransformerinitializesflag = falseand skipstransform(...)when either side isNaN, soCompareNonEqualColumnTransformerreturnsfalseforx != NaN. - As a result,
SELECT int64_col NOT IN (CAST('NaN' AS DOUBLE), 0)returnstrueforint64_col = 29, whileSELECT int64_col NOT IN (CAST('NaN' AS DOUBLE), CAST('NaN' AS DOUBLE))(deduplicated toNOT (int64_col = NaN)->int64_col != NaN) returnsfalsefor29, andWHERE int64_col NOT IN (CAST('NaN' AS DOUBLE), CAST('NaN' AS DOUBLE))returns row29.
Minimal repro:
CREATE DATABASE test_nan_cmp;
USE test_nan_cmp;
CREATE TABLE t(l INT64 FIELD);
INSERT INTO t(time, l) VALUES (1, -10), (2, 0), (3, 29), (4, NULL);
-- Wrongly returns row 1 (l = -10) because (long) Math.ceil(NaN) == 0
SELECT time, l FROM t WHERE l < CAST('NaN' AS DOUBLE);
SELECT time, l FROM t WHERE l >= CAST('NaN' AS DOUBLE);
-- Inconsistent NOT IN / != results for row 3 (l = 29):
SELECT time, l FROM t WHERE l NOT IN (CAST('NaN' AS DOUBLE), CAST('NaN' AS DOUBLE));
SELECT time, l NOT IN (CAST('NaN' AS DOUBLE), 0) AS m FROM t;
SELECT time, l NOT IN (CAST('NaN' AS DOUBLE), CAST('NaN' AS DOUBLE)) AS m FROM t;What did you expect to see?
- Ordered comparisons (
<,<=,>,>=) againstNaNin pushdown returnFalseLiteralFilter(empty result), matching projection. != NaNandNOT IN (NaN, ...)have consistent semantics across pushdown, projection,PushDownNegations, andCompareNonEqualColumnTransformer.
What did you see instead?
l < CAST('NaN' AS DOUBLE)andl >= CAST('NaN' AS DOUBLE)treatNaNas0.WHERE l NOT IN (NaN, NaN)andSELECT l NOT IN (NaN, 0)disagree withSELECT l NOT IN (NaN, NaN)/SELECT l != NaN.
Anything else?
Are you willing to submit a PR?
- I'm willing to submit a PR!
Activity