Skip to content

[GLUTEN-12538][VL] Fall back for unsupported Delta statistics plans - #13510

Open
felipepessoto wants to merge 2 commits into
apache:mainfrom
felipepessoto:felipepessoto-delta-writer-statistics
Open

felipepessoto wants to merge 2 commits into
apache:mainfrom
felipepessoto:felipepessoto-delta-writer-statistics

Conversation

@felipepessoto

@felipepessoto felipepessoto commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

What changes are proposed in this pull request?

Fixes #12538.

Prevent Delta 3.3/4 native writes from failing when their statistics plan cannot fully offload. Validate the entire statistics stage before constructing native tasks; otherwise log the rejection and reuse Delta's row-based statistics tracker through the existing columnar-to-row adapter.

Preserve native file writing and supported native statistics. The regression suite is shared with Delta 4 through the src-delta4/test symlink, and the statistics suites are selected in CI group 3 for Spark 3.5 (both Scala variants) and Spark 4.x. No native NTZ file-writing support, dependency changes beyond main, or known-failure changes are included.

How was this patch tested?

  • Before/after: On the original base (cce7716), the regression suite reproduced ClassCastException for projection/NTZ rejection and a column-count mismatch for partial aggregation offload. All four cases, including the native control, passed with the fix.
  • Historical runtime validation: 20/20 local tests passed at 8863b207 across Spark 4.1.1 / Delta 4.4.1 and Spark 3.5.5 / Delta 3.3.2. Actual CI reports at 8d14b6e6d then confirmed all four fallback-suite tests passed on Spark 3.5 and 4.1, plus the existing native NTZ test on Spark 3.5, with zero skips.
  • November 17 rebase: 7f8189cda is based on main 2011f60b9, including [GLUTEN-12743][VL] Align Delta test parallelism and clean up aborted statistics #13578's native statistics cleanup. Resolved import conflicts in both trackers while preserving the upstream cleanup and this PR's eligibility/fallback logic. The separate CI-selector commit was dropped because those exact selectors are now in main.
  • Rebase validation: Scala formatting and license checks passed on the resolved source snapshot. Shared-source links and CI selection were checked; the existing regression tests and main's lifecycle tests are unchanged. No new local native runtime results are claimed.
  • Current-head CI (7f8189cda): fresh Velox x86, ARM, and Kafka workflows are queued in the fork. Earlier runtime/CI results above are historical, not validation of this composed head.

The historical DATE-to-NTZ ALTER setup was not rerun. The NTZ rejection regression exercises statistics directly, without bypassing the Delta 4 file-writer gate.

Was this patch authored or co-authored using generative AI tooling?

Generated-by: GitHub Copilot (GPT-6 Astra, model ID: gpt-6-astra)

Copilot AI balanced review requested due to automatic review settings October 31, 2026 23:08
@github-actions github-actions Bot added CORE works for Gluten Core VELOX DOCS labels Oct 31, 2026
@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

@felipepessoto
felipepessoto marked this pull request as draft October 31, 2026 23:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues remain for the statistics-fallback change.

No open issues 🎉

What changed in this PR

Addresses #12538 by falling back to Delta’s row-based statistics tracker when the complete statistics plan cannot run natively. This preserves native file writing and supported native statistics without changing Delta 4’s TIMESTAMP_NTZ writer restriction.

Changes:

  • Validate the full statistics stage before constructing native tasks in both Delta variants, and log fallback reasons.
  • Add regression coverage for supported and rejected statistics plans, plus fallback during partitioned file rotation and batch splitting.
  • Update the writer documentation to describe statistics fallback.
File Description
gluten-ut/​spark35/​src-delta/​test/​scala/​org/​apache/​spark/​sql/​execution/​datasources/​GlutenDeltaNativePartitionWriteSuite.scala Adds partitioned-write cases with statistics offload disabled.
docs/​backends/​velox/​get-started/​VeloxDelta.md Documents statistics fallback and removes the resolved crash limitation.
backends-velox/​src-delta4/​main/​scala/​org/​apache/​spark/​sql/​delta/​stats/​GlutenDeltaJobStatsTracker.scala Selects native or fallback statistics after full-stage validation for Delta 4.
backends-velox/​src-delta33/​test/​scala/​org/​apache/​spark/​sql/​delta/​GlutenDeltaStatsFallbackSuite.scala Checks native writer provenance, statistics values, and rejected-plan fallback.
backends-velox/​src-delta33/​main/​scala/​org/​apache/​spark/​sql/​delta/​stats/​GlutenDeltaJobStatsTracker.scala Applies the same statistics-stage validation and fallback for Delta 3.3.

Review effort: Balanced

@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

@felipepessoto
felipepessoto marked this pull request as ready for review November 6, 2026 23:35
@felipepessoto

Copy link
Copy Markdown
Contributor Author

@zhztheplayer, @rui-mo, could you review #13510? It fixes the unchecked cast when Delta’s statistics plan cannot fully offload, including partially native plans. Supported statistics and file writing remain native, rejected statistics plans use the existing fallback tracker.
The regression tests fail before the fix and pass afterward.

Copilot AI balanced review requested due to automatic review settings November 7, 2026 00:39
@github-actions github-actions Bot added the INFRA label Nov 7, 2026
@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The regression suite is compiled only for Delta 3.3, leaving the separately changed Delta 4 tracker and original Spark 4.x failure uncovered by the new CI selectors.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Medium severity Delta 4 CI skips these regression tests

backends-velox/​src-delta33/​test/​scala/​org/​apache/​spark/​sql/​delta/​GlutenDeltaStatsFallbackSuite.scala:44

This suite is compiled only for Delta 3.3: Spark 4.x sets delta.binary.version=4, which selects src-delta4/test rather than this directory (pom.xml:1300,1857). The new Spark 4.x CI selectors therefore do not run these projection-rejection, partial-offload, or TIMESTAMP_NTZ regressions against the separately changed Delta 4 tracker. Add a Delta 4 variant or share the compatible tests across both source sets so CI covers the original Spark 4.x failure.

Review effort: Balanced

@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

@felipepessoto

Copy link
Copy Markdown
Contributor Author

The Delta 4 coverage finding is a false positive. backends-velox/src-delta4/test/scala/org/apache/spark/sql/delta/GlutenDeltaStatsFallbackSuite.scala is already a tracked Git symlink (mode 120000) to the Delta 3.3 suite; it was included in the original patch.

The spark-test-spark41-group3-report artifact from CI run 42319505960 contains TEST-org.apache.spark.sql.delta.GlutenDeltaStatsFallbackSuite.xml with all four tests executed, zero failures/errors, and zero skips. That includes projection rejection, partial aggregation offload, NTZ rejection, and the supported-native control. No duplicate suite is needed.

Rebased onto main 3342737a4 at head aebaef0f7 to pick up the latest CI changes. Both patches are unchanged by range-diff, and the production/test files are byte-identical. Fresh CI is pending on the rebased head; the execution evidence above belongs to the previous head.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues remain for the Delta statistics fallback change.

No open issues 🎉

Review effort: Balanced

Comment on lines +161 to +163
val transformRule =
HeuristicTransform.WithRewrites(validatorBuilder(config), Seq(PullOutPreProject), offloads)
ColumnarCollapseTransformStages(config)(transformRule(projOp))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the main reason of the fallbacks? The statistics plan should be in a few fixed patterns - can we just support them or have more focused checks?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You’re right to question whether we still need this. The original motivation was the NTZ statistics-support gap, which #12967 addressed. I haven’t identified another unsupported statistics pattern under default settings, so I’m not sure we should proceed with this PR in its current form.

The remaining reproductions are configuration-driven. For example, disabling native aggregation while keeping native writing enabled makes the statistics planner leave a Spark aggregate, but the tracker still assumes a fully native plan. That causes a column-count mismatch; disabling projection instead causes the unchecked ProjectExec cast to fail. Explicitly enabling NTZ validation also reproduces rejection in the direct statistics test.

This PR checks the complete stage—not just its root—and uses Spark statistics when it cannot fully offload, while retaining native file writing. It therefore handles those rejected plans safely rather than adding missing native support.

Before proceeding, could we clarify whether ordinary-query offload switches should also govern the writer’s internal statistics? If yes, this fixes crashes for that configuration. If not, statistics-specific planning rules would address those cases more directly, and we could defer the general fallback change. I’ve updated #12538 to distinguish the historical motivation from this remaining question.

Validate the entire local statistics plan before creating the native task. Reuse Delta statistics through the existing columnar-to-row fallback when any required operator remains in Spark, preserving native file writing and file statistics.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@felipepessoto
felipepessoto force-pushed the felipepessoto-delta-writer-statistics branch from aebaef0 to 7f8189c Compare November 17, 2026 22:05
Copilot AI balanced review requested due to automatic review settings November 17, 2026 22:05
@github-actions github-actions Bot removed the INFRA label Nov 17, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Maintainer confirmation is needed on whether general query-offload switches should govern internal Delta statistics, and queued current-head CI has not yet validated the native-task lifecycle integration.

No open issues 🎉

Review effort: Balanced

@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

@zhztheplayer zhztheplayer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

Use GlutenExplainUtils.visitFallbackNodes for the existing warning in both tracker variants. Keep statistics offload eligibility and the fallback task selection unchanged.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 21, 2026 16:50
@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Maintainer input is needed to resolve whether Delta’s internal statistics should follow ordinary-query offload switches or use statistics-specific planning rules.

No open issues 🎉

Review effort: Balanced

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CORE works for Gluten Core DOCS VELOX

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[VL][Delta] Gluten Delta stats tracker should fall back when the stats plan can't be offloaded (ClassCastException on TIMESTAMP_NTZ)

3 participants