← Back to Pull requests

fix: preserve make_date evaluation across lazy operators #7283

Closed
unknown closed this pull request without merging on Oct 30, 2026 04:34 UTC
View on GitHub
unknown unknown commented on Oct 28, 2026 01:07 UTC
Author

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 1 stops 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?

  • Preserve Spark evaluation around affected make_date projections and consumers, including limits, filters, samples, joins, aggregates, ordered limits, window group limits, mapPartitions, and Dataset.rdd. Native scans and independent materialization boundaries remain available.

  • Track deferred date outputs, argument producers, and sibling computations across projections while retaining native execution for provably eager consumers. Preserve logical-plan tags and restore existing native broadcasts when a consuming join falls back.

  • Keep provably safe ANSI-off date projections native while preserving safeguards for unbounded years, deferred producers, and throwing siblings. Arithmetic consumers stay in Spark when a nullable date alias can hide a throwing operand; the safe date producer remains native. Reuse native collect-limit input caps when conversion succeeds; retain Spark fallback when a cap is unavailable or a lower producer needs guarding.

  • Add supported spark.comet.exec.makeDate.operatorFallback.enabled (default true) and document its tradeoff. Setting it to false allows these native operators to evaluate dates on rows Spark would skip; expression-level safeguards and invalid-date handling remain in effect.

  • Add focused regressions and two reproducible performance cases using 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?

  • Spark 4.1.3 / JDK 17: all 125 CometExecRuleSuite tests and both make_date tests in CometTemporalExpressionSuite pass, including skipped invalid-month errors, deferred sibling casts, arithmetic over nullable date aliases, AQE/reused broadcasts, native eager controls, and the opt-out.

  • Local runtime validation uses the unchanged native library from upstream commit 967d09b52694d64c423012ed7dcc8f7ec6e20413 (CI run). This PR changes no native source. Its build is Cargo ci (release-derived, LTO off, debug assertions on), targeting x86-64-v3.

  • Before merging, request run-spark-4.1-tests and run-all-spark-profiles for 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's ci profile.

    Diff: 632 lines (+474 / -158) across 7 files Reviewer: sunchao Review duration: 3086m
    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
    0.50
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 50.4% (MEDIUM) · Higher = larger blast radius
    50.4%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.8% · Lower = rushed or shallow review
    56.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 21.8% · Safe to merge
    21.8%