Skip to content

[Bug] [Table model] Inconsistent NaN comparison semantics between filter pushdown, projection, and NOT IN #19439

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

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:

  1. Ordered comparisons in ConvertPredicateToFilterVisitor.constructCompareFilter / constructFilterFromDouble:
    NaN fails both range checks (NaN >= 0x1p63 and NaN < Long.MIN_VALUE are both false) and falls through into constructFilterFromDouble. For <, <=, >, >=, (long) Math.ceil(Double.NaN) and (long) Math.floor(Double.NaN) evaluate to 0L, silently turning int64_col < CAST('NaN' AS DOUBLE) into int64_col < 0 instead of always-false.

  2. != NaN inconsistency between pushdown / PushDownNegations and CompareBinaryColumnTransformer:

    • PushDownNegationsExpressionRewriter rewrites NOT (x = NaN) to x != NaN.
    • In pushdown, constructFilterFromDouble(NOT_EQUAL, NaN, ...) returns ValueIsNotNullOperator (matches all non-NULL rows).
    • In projection, CompareBinaryColumnTransformer initializes flag = false and skips transform(...) when either side is NaN, so CompareNonEqualColumnTransformer returns false for x != NaN.
    • As a result, SELECT int64_col NOT IN (CAST('NaN' AS DOUBLE), 0) returns true for int64_col = 29, while SELECT int64_col NOT IN (CAST('NaN' AS DOUBLE), CAST('NaN' AS DOUBLE)) (deduplicated to NOT (int64_col = NaN) -> int64_col != NaN) returns false for 29, and WHERE int64_col NOT IN (CAST('NaN' AS DOUBLE), CAST('NaN' AS DOUBLE)) returns row 29.

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 (<, <=, >, >=) against NaN in pushdown return FalseLiteralFilter (empty result), matching projection.
  • != NaN and NOT IN (NaN, ...) have consistent semantics across pushdown, projection, PushDownNegations, and CompareNonEqualColumnTransformer.

What did you see instead?

  • l < CAST('NaN' AS DOUBLE) and l >= CAST('NaN' AS DOUBLE) treat NaN as 0.
  • WHERE l NOT IN (NaN, NaN) and SELECT l NOT IN (NaN, 0) disagree with SELECT l NOT IN (NaN, NaN) / SELECT l != NaN.

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