fix: skip IN candidates for a NULL or fallible value under ANSI #7741
All Vouch review confidence checks passed
Residual risk 0.28 = Change Risk (0.52) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #7741"
general
weight: 0.35
comphead
Which issue does this PR close?
Closes #7675.
Rationale for this change
With ANSI mode on, a query such as v IN (0, CAST(s AS INT)) fails in Comet with CAST_INVALID_INPUT on rows where Spark returns a result. Spark's In returns NULL for a NULL value without evaluating any candidate, and stops at the first match. Comet still evaluated a candidate in two cases: when the value was NULL, and when the value could itself fail, such as v + 1, where the lazy rewrite gave up and the eager DataFusion in_list evaluated every candidate over the batch.
What changes are included in this PR?
The lazy IN rewrite now accepts any deterministic value, not only one that cannot fail. The value is evaluated once per term, which is safe because a deterministic value returns the same result each time, and a row that fails on the value fails on the first term, as in Spark.
For a nullable value, the OR chain sits under CASE WHEN value IS NOT NULL, so a row whose value is NULL gets NULL without any candidate running. NOT IN negates the whole expression, so it is NULL on those rows too.
How are these changes tested?
Three queries in logical_lazy_ansi.sql run against a table with rows (0, 'bad'), (NULL, 'bad') and (2, '2'): v IN (0, CAST(s AS INT)), the same with NOT IN, and (v + 1) IN (1, CAST(s AS INT)). The suite compares Comet's answer with Spark's.
Before the fix, on upstream main 0e8c133b03187ebe229b0a7e1c1d8560fd824204 with only the new SQL cases added, using Spark 4.1 and JDK 17:
After the fix, with the native library rebuilt by make core, the same SQL file passes. To show the rows themselves, a temporary suite (source below, not part of this PR) runs the three queries under ANSI, prints Comet's operators and rows next to Spark's, and calls checkSparkAnswerAndOperator on each, which asserts that the whole plan ran in Comet:
Before the fix, the first query fails as shown above instead of returning these rows.
<details>
<summary>Reproducer source: Issue7675ReproSuite.scala</summary>
</details>