fix: preserve make_date evaluation across lazy operators #7283
All Vouch review confidence checks passed
Residual risk 0.22 = Change Risk (0.50) × (1 − Review Confidence (0.57)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.50 · 632 lines diff across 7 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.386
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #7283"
general
weight: 0.35
sunchao
Which issue does this PR close?
Related to #6741. Part 3 of the split of #7117, following merged #7260 and #7261. The native Date32 overflow correction remains a separate follow-up.
Rationale for this change
With ANSI mode enabled, an input iterator can yield a valid date row followed by a row with month 13. Spark's
LIMIT 1stops before evaluating the invalid date; a native projection can evaluate both rows in a batch and throw. Conditional projections and other lazy consumers can expose the same difference.What changes are included in this PR?
make_dateprojections and consumers, including limits, filters, samples, joins, aggregates, ordered limits, window group limits,mapPartitions, andDataset.rdd. Native scans and independent materialization boundaries remain available.spark.comet.exec.makeDate.operatorFallback.enabled(defaulttrue) and document its tradeoff. Setting it tofalseallows these native operators to evaluate dates on rows Spark would skip; expression-level safeguards and invalid-date handling remain in effect.CometDatetimeExpressionBenchmark --make-date-only.Start in MakeDateEvaluation.scala: the main review questions are where row demand stops at materialization boundaries, which projection outputs Spark may defer, and whether falling back preserves broadcast reuse and logical-plan links. CometExecRule.scala applies that decision before join rewrites and native conversion.
How are these changes tested?
CometExecRuleSuitetests and bothmake_datetests inCometTemporalExpressionSuitepass, including skipped invalid-month errors, deferred sibling casts, arithmetic over nullable date aliases, AQE/reused broadcasts, native eager controls, and the opt-out.967d09b52694d64c423012ed7dcc8f7ec6e20413(CI run). This PR changes no native source. Its build is Cargoci(release-derived, LTO off, debug assertions on), targeting x86-64-v3.run-spark-4.1-testsandrun-all-spark-profilesfor Spark SQL and version coverage.Benchmark results below are from commit
47f66c442, including the ANSI-off guard narrowing and collect-limit cap reuse. Two fresh JVM runs on valid Parquet data (1,048,576 probe rows, 1,024 build rows),local[1], AQE off, one shuffle partition, whole-stage codegen on, ANSI off, 8 GiB heap. The Spark benchmark harness uses at least five iterations per case. Values are mean milliseconds (run 1 / run 2):| Query | Spark | Comet default | Operator fallback disabled |
| --- | ---: | ---: | ---: |
|
LIMIT 10| 45 / 47 | 29 / 31 | 25 / 22 || Broadcast join with probe-side date projection | 123 / 126 | 92 / 85 | 91 / 89 |
Captured LIMIT plans now use a native projection and an input cap in both Comet modes. The default still measures 4–9 ms above the opt-out in these end-to-end runs; this does not isolate the guard's planning cost. The join differences (-4 to +1 ms) are smaller than the observed standard deviations (10–16 ms across Comet modes), so these runs do not establish a precise join penalty. They are not release-build performance measurements.
The benchmark's unrestricted INT year column remains guarded by default because Spark's Date32 conversion can overflow even with ANSI disabled. The narrower ANSI-off exemption for bounded literal or small-integer years is verified by planner tests. The join uses a noop writer to consume the date output; its probe-side projection is asserted before timing.
Reproduce with
SPARK_GENERATE_BENCHMARK_FILES=1 make BENCH_HEAP=8g benchmark-org.apache.spark.sql.benchmark.CometDatetimeExpressionBenchmark -- --make-date-only, in two fresh JVMs. The measurements used the matching upstream native artifact built with Cargo'sciprofile.