fix: evaluate guarded divisors and logarithm arguments once #7730
All Vouch review confidence checks passed
Residual risk 0.17 = Change Risk (0.43) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.43 · 361 lines diff across 4 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.352
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #7730"
general
weight: 0.35
viirya
Which issue does this PR close?
Closes #7671.
Rationale for this change
Comet used
IF(x = 0, NULL, x)for non-ANSI divisors andIF(x <= 0, NULL, x)for logarithm arguments. The condition evaluatesxover the batch. The value branch evaluates it again on the rows that passed the check. For a stateful expression such asmonotonically_increasing_id(), those evaluations can assign different values to the same row. A divisor that passed the check can then be zero when the arithmetic kernel uses it.What changes are included in this PR?
/,divand%, and non-positive values forln,log10andlog2. The math kernel consumes the values the guard checked. Both signs of zero match, and NaNs pass through.INevaluation when its children qualify.CometAtan2as its input preprocessing example.#7785 tracks a separate problem on the dividend side. Spark skips the dividend when the divisor is NULL or when a zero divisor yields NULL. #7456 proposes evaluating the divisor first and is relevant to that follow-up.
branch-1.2still evaluates these guarded operands twice. I marked this PR as abackport-1.2candidate. Trying the patch against8afafe4fproduced conflicts limited to imports inplanner.rsandcase_when.rsand a comment incase_when.rs. I suggest backporting the native guard with its regression tests after this lands onmain.How are these changes tested?
monotonically_increasing_id()over a single Parquet file in two-row batches. Separate queries exercise nativetry_divideand decimal/with the same stateful divisor. The arithmetic queries cross a zero divisor, and the logarithm inputs cycle through −1, 0 and 1.Local checks cover Rust and Scala formatting and
git diff --check. Hosted CI runs the test suites.Post-merge follow-up #7807 adds the requested Rust tests for the numeric guards and the optional negative-zero input to each of the
ln,log10andlog2Parquet fixtures. The merge queue run for this PR passed Spark 4.1 Catalyst, SQL core and Hive.