← Back to Pull requests

feat: preserve columnar batches across observations #7325

Closed
unknown closed this pull request without merging on Nov 01, 2026 03:38 UTC
View on GitHub
unknown unknown commented on Oct 29, 2026 20:30 UTC
Author

Which issue does this PR close?

Closes #7324. Related to #5124; metric evaluation remains in Spark, so this does not implement the fully native collector proposed there.

Rationale for this change

A Parquet scan followed by observe(count(lit(1)).as("rows")) and a grouped aggregation currently introduces a row boundary at the observation. Preserve the observation results while passing Arrow batches between eligible native operators.

What changes are included in this PR?

  • Add CometCollectMetricsExec, enabled by spark.comet.exec.collectMetrics.enabled. Spark evaluates the metric expressions over batch row views and retains ownership of accumulator publication, observation discovery and resets. The original Arrow batch then feeds the downstream native block.

  • Require a materializing shuffle or broadcast exchange above the collector. Retain Spark collection below limits, joins, partial iterator consumers and nonpositive replacement sampling, and for direct actions or writes without such an exchange, so counts match Spark's row consumption.

  • Integrate native input boundaries, AQE revisits and stage reversion. Adopt the first completed accumulator state without copying large aggregate buffers, matching Spark.

  • Keep Arrow reader vectors independent from batches forwarded through observations, retaining buffers without copying data. Convert rows to UnsafeRows when metrics reference complex values, strings or calendar intervals, giving aggregate keys a consistent representation and keeping serialized expression caches independent of Arrow batches. Numeric-only metrics retain the direct row-view path. Preserve widened nested nullability in the observation scan schema during initial planning and AQE replanning, retaining existing accumulators.

  • Document the supported plan shapes and register CometCollectMetricsSuite in Linux and macOS CI, with Spark-version-specific aggregate test helpers.
  • How are these changes tested?

    The focused suite compares output rows and observations with Spark, covering AQE on/off, empty inputs, repeated execution, aggregate-state publication, limits, joins, iterator consumers, sampling, stage reversion and disabled configuration. It also covers mixed struct representations in mode, JSON expression caches at task serialization, multi-batch structs, direct column closure, collect_list/collect_set over structs containing calendar intervals, and null padding in array_insert across the observation boundary, with AQE off/on and explicit replanning that checks collector identity and native projection. The null-padding regression reproduced the Arrow failure before both the initial-conversion fix and the replanning fix. The partial iterator tests include a trailing shuffle to exercise the row-consumption guard.

  • Spark 4.1.3: CometCollectMetricsSuite passed all 23 tests, including the two new complex-value regressions.

  • Spark 3.5.9 with -Pstrict-warnings: CometCollectMetricsSuite passed all 23 tests; main and test sources compiled successfully.

  • Tests used a previously built Apache Comet 1.3 native library with unchanged execution JNI signatures. CI will build the native library from this PR.

  • Spotless, Scala style checks, the full-tree syntactic Scalafix 0.14.6 CI check, Prettier for the changed Markdown, CI configuration validation and git diff --check passed. Two independent reviews approved the fixes.
  • Spark 4.1's optional strict-warning profile reports four preexisting errors in CometShuffleExchangeExec and CometArrowPythonRunnerBase; its normal profile passes. A maintainer needs to apply run-all-spark-profiles and run-spark-4.1-tests for broader version and Spark SQL coverage; the author account cannot add these labels.

    Diff: 470 lines (+352 / -118) across 5 files Reviewer: sunchao Review duration: 3307m
    All Vouch review confidence checks passed
    Residual risk 0.18 = Change Risk (0.46) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.46 · 470 lines diff across 5 files
    0.46
    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%
    60%
    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.368
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #7325"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% 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: 45.7% (MEDIUM) · Higher = larger blast radius
    45.7%
    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: 60.5% · Lower = rushed or shallow review
    60.5%
    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: 18% · Safe to merge
    18%