fix: evaluate the right operand of AND, OR and IN only for rows the left side has not decided #7326
All Vouch review confidence checks passed
Residual risk 0.18 = Change Risk (0.45) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.45 · 442 lines diff across 5 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 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.365
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #7326"
general
weight: 0.35
sunchao
Which issue does this PR close?
Closes #6823.
Part of #6006.
Rationale for this change
Spark evaluates
AND,ORand the candidates ofINlazily: a later operand runs only for the rows that the earlier ones have not decided. Comet evaluates every operand over the whole batch, so under ANSI mode an operand that can raise throws on a row Spark never evaluates. Withvholding 0 to 3 on a Parquet table and ANSI on, each of these raisedDIVIDE_BY_ZEROin Comet and returned rows in Spark:v != 0 AND 100 / v > 1v = 0 OR 100 / v > 1v IN (0, 100 / v)CASE WHEN,IFandcoalescealready match Spark.What changes are included in this PR?
LazyLogical(native/spark-expr/src/conditional_funcs/lazy_logical.rs) evaluates the right operand ofANDandORonly for the rows the left operand has not decided, which are the rows where it is not false forANDand not true forOR. It shares the column projection and masked evaluation ofNullShortCircuit, so skipping rows filters no other column.spark_comparisoncreates it forANDandOR.cannot_failcheck. Otherwise the expression stays a plainBinaryExpr, so the common case has no extra cost.lazy_in_listrewritesv IN (c1, c2, ...)into a chain when a candidate after the first can fail. A run of candidates that cannot fail stays oneIN, keeping its hash set, and each candidate that can fail is a lazy equality.NOT INis the negation of that chain. This applies only when the value is cheap and cannot fail, because the chain evaluates it once per term. The terms are joined in a balanced tree, so a long list is no deeper than its logarithm. Other shapes keep the existing whole-batch evaluation.This does not cover the rest of #6006: aggregate
FILTER, operator-level masks, and the compatibility guide section.How are these changes tested?
lazy_logical.rscoverANDandORon rows the left side decides, a NULL left operand, a batch with no decided rows, an empty batch, a scalar left operand, a right operand that reads no column, an infallible right operand staying aBinaryExpr, and theINandNOT INrewrite, including floats. Thedatafusion-comet-spark-exprlib suite passes (1334 tests) andcargo clippy -D warningsis clean.expressions/conditional/logical_lazy_ansi.sqlruns the cases above, chains, nesting underNOT, andINwith a failing cast. It also has controls where a row Spark does evaluate must still raiseDIVIDE_BY_ZEROorCAST_INVALID_INPUT. It passes withCometSqlFileTestSuiteon Spark 4.1, along with the existingconditional/andpredicatesSQL files.native/spark-expr/benches/lazy_logical.rscompares the eager and lazy forms at 0 to 100% pending rows, andINlists of 2, 8 and 64 candidates. Lazy evaluation is up to 3-4x faster when few rows are pending, and within noise of eager evaluation otherwise. A 64-candidateINwith one fallible candidate is 2.3x faster than DataFusion's.