Skip to content

[GLUTEN-13500][VL] [Blocked on #13135] Support Delta partition column materialization - #13502

Draft
felipepessoto wants to merge 9 commits into
apache:mainfrom
felipepessoto:felipepessoto-delta-partition-materialization
Draft

felipepessoto wants to merge 9 commits into
apache:mainfrom
felipepessoto:felipepessoto-delta-partition-materialization

Conversation

@felipepessoto

@felipepessoto felipepessoto commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Agent assessment

Self-reported assessment, not an independent review.

Assessed revision: db5d7193f07a444957ba9b8716c68d2ea48d0291

Dimension Assessment Rationale
Change confidence 8/10 ↑ All nine commits replayed unchanged onto main b6fbc82; all 12 PR files retain their pre-rebase contents.
↑ Pre-rebase Delta CI passed all eight shards; matching integration builds passed 47 backend and 28 upstream OPTIMIZE cases.
↓ Eight known JNI exception-contract cases remain pending #13561.
↓ New-head CI is pending; no local native/Spark rebuild was run for this mechanical rebase. Prior CI exposed the streaming TTL race and a ClickHouse AQE build-side assertion, neither fixed here.

What changes are proposed in this pull request?

Fixes #13500.

Enable Velox native writes for Delta's Materialize Partition Columns feature on Spark 4.x.

This also enables native file writing for default Delta 4.4 partitioned tables. Delta defaults delta.writePartitionColumnsToParquet to true when unset, independently of the protocol feature. Previously, Gluten sent these writes to Delta's JVM writer even with native writes enabled. Reads could still run in Velox, so passing correctness tests or a GlutenDelta plan node did not prove native file-write coverage.

  • Forward partition-column retention through Scala/Java/JNI and emit columns in Delta's file-schema order.
  • Give statistics trackers a data-only batch, preserving batch ownership and excluding partition columns from Delta statistics.
  • Honor Delta's existing feature/property precedence: the writer feature requires materialization even when the property is false.

Column mapping, UniForm, and other existing unsupported combinations still fall back. FLOAT/DOUBLE partition columns fall back explicitly. TIMESTAMP partition columns fall back regardless of materialization or actual value precision because the splitter cannot represent sub-millisecond values; timestamp data columns retain their existing encoding checks. Delta 3.3 behavior is unchanged.

CDF UPDATE/DELETE can also execute natively on unpartitioned tables because Delta routes change rows through the virtual __is_cdc partition. Tests now inspect both data and change files and compare with vanilla Delta. Physical-file checks cover OPTIMIZE as well as UPDATE/DELETE, and Spark 4.0/4.1/4.2 CI explicitly selects DeltaNativeWriteSuite.

Filesystem prerequisite resolved: this branch is rebased onto main b6fbc82d, including merged #13386. On Spark 4.x, unsupported schemes and connectors unavailable in the native build use Delta's writer, including materialized writes and OPTIMIZE. New physical-file cases cover both default materialization and feature-forced materialization with the property set to false. Both original concurrent OPTIMIZE cases using block: now pass unchanged, so their two known-failure entries are removed. The filesystem fix is inherited from main, not duplicated here.

Remaining known failures: retain the eight replaceWhere exception-contract entries originally removed by e920e70e4 when partitioned writes began falling back. CHECK and replaceWhere failures can still lose their original exception across native iterators; constraints remain enforced and rejected writes commit nothing. Main already contains core JNI transport (#13560) and separate NOT NULL exception recovery, but iterator preservation in #13561 remains open. #13133 is the combined reference, not an additional PR to merge. Keep these eight entries until the remaining fix is integrated and the exact cases pass. Native/fallback coverage detection is tracked separately in #13504.

Historical combined validation of this PR at 45b16ab55 with #13133's JNI implementation at f88c2698 passed 12 strict constraint cases and all eight unchanged upstream replaceWhere cases, checking original Delta exception metadata and unchanged table version/files/rows after rejection. Default and feature-forced materialization were covered; the materialization-only control failed the partitioned exception-contract cases. Regression coverage was published separately in #13133, commit 00c478419. These are prior-combination results, not a claim that the pending iterator fix is present in this branch.

How was this patch tested?

Rebase db5d7193f onto main b6fbc82d: all nine commits have identical patches, and all 12 PR files retain their pre-rebase contents. License-header and whitespace checks passed. No local native/Spark rebuild was run for this mechanical rebase; new-head CI is pending.

Before the rebase, d28b3f310: Delta CI passed all eight shards and aggregation. The x86 rerun failed one Spark 4.2 GlutenTransformWithStateAvroSuite TTL-restart case: the first attempt failed with changelog checkpointing, while the retry passed that variant and failed without changelog checkpointing. The schema-error stack matches the previously observed streaming test race. All 62 Delta cases in that job passed; no streaming test was changed or excluded. The authenticated ClickHouse console log identifies its sole failure in Spark35 UT: ClickHouseAdaptiveQueryExecSuite, Gluten - metrics of the shuffle read, with BuildRight did not equal BuildLeft at line 767. The test expected the broadcast join to build on the left, but AQE selected the right. This suite is unchanged by the PR; the underlying cause of that plan choice has not been established. The earlier HTTP 403 was from an unauthenticated request, not an inability to access the documented read-only CI service. These are prior-head results, not current-head CI success.

Filesystem integration, ab1c25dda: 47 backend cases and 28 upstream OPTIMIZE cases passed, with no failures, skips, or aborted suites. The subsequent d28b3f310 follow-up changed only the two verified baseline entries.

  • Rebuilt the Spark 4.1 / Scala 2.13 / JDK 17 Maven reactor using the matching freshly built native libraries from run 45517616261. Its merge 5af65754046c5f4f9bd56ac5081570f9a7dd02e4 was verified to have base 04597a05 and PR head ab1c25dda.
  • GlutenDeltaNativeWriteGateSuite: 23 passed, including unsupported schemes, compiled-out connectors, and failed native-probe handling. VeloxDelta4WriteSuite: 24 passed, including the two new materialization/filesystem cases. Those cases verify JVM Parquet writer identity, physical partition values, successful OPTIMIZE file replacement, and all rows before/after compaction; existing supported-filesystem native checks remain enabled.
  • Ran the unchanged Delta v4.4.1 OptimizeCompactionSuite.scala with that run's matching bundle: 27 SQL cases plus the selected Scala concurrency case passed. Both exact optimize - multiple jobs start executing at once identities are present in successful JUnit reports. Replaying the normal enforcement script with the updated baseline passed. No assertions were weakened and no quarantine entries were added.
  • Scala formatting, license headers, whitespace checks, and conflict-resolution review passed. Rebase checks and CI outcomes are recorded above separately from this local validation.

Earlier review follow-up e57998b8c: 59 focused tests passed on Spark 4.1 / Scala 2.13 / JDK 17 in the preserved DevContainer: GlutenDeltaNativeWriteGateSuite (19), VeloxDelta4WriteSuite (20), DeltaNativeWriteSuite (12), and GlutenDeltaNativePartitionWriteSuite (8). JVM modules were rebuilt against the native libraries from the successful then-current-base CI build; that follow-up changed no JNI/C++ source.

Coverage verifies physical partition values after UPDATE/DELETE, data and change files for partitioned/unpartitioned CDF DML, rewritten native OPTIMIZE files, and sub-millisecond TIMESTAMP fallback with materialization both on and off. Existing precedence, null/reordered-key, file-limit, statistics, mixed-file, and fallback checks remain enabled.

Recorded Maven forks were passed through the actual parallel-UT discovery code: the new group-1 selector adds exactly DeltaNativeWriteSuite in backends-velox, preserves every prior suite, and adds nothing in the unrelated Spark UT module. Its 12 tests also executed successfully. YAML checks verify selection only in group 1 across Spark 4.0/4.1/4.2. These are historical selection checks, not a substitute for the current-head CI matrix.

Prior CI on 69706f449 passed all 83 executed GitHub checks (two skipped), all eight Delta shards and aggregation, and external ClickHouse CI. That historical result is not a claim that current-head CI is green. Delta CI enforces known failures; a green gate does not mean every upstream test passes.

Before/after execution

The write changes from row conversion for Delta's JVM writer to native batches for Velox's writer; the Parquet footer independently confirms the writer used.

Executed writer-input plans and Parquet footer evidence

Same input on Spark 4.1.1 / Delta 4.4.1, appended with data.write.format("delta").mode("append").save(path) to a table partitioned by part:

SELECT id, concat('row-', cast(id AS STRING)) AS value,
       CAST(id % 2 AS INT) AS part
FROM range(0, 6, 1, 1)

Both runs enabled native writes and the materializePartitionColumns writer feature, with delta.writePartitionColumnsToParquet=false to exercise feature precedence. AQE and optimized writes were disabled for a compact, deterministic example.

Before: DeltaFileFormatWriter (JVM fallback)

Sort [input[2, int, true] ASC NULLS FIRST], false, 0
+- DeltaInvariantChecker
   +- VeloxColumnarToRow
      +- ^(1) ProjectExecTransformer [id#433L, concat(row-, cast(id#433L as string)) AS value#431, cast((id#433L % 2) as int) AS part#432]
         +- ^(1) InputIteratorTransformer[id#433L]
            +- ArrowColumnarToVeloxColumnar
               +- OffloadArrowData
                  +- ColumnarRange 0, 6, 1, 1, 6, [id#433L]

After: GlutenDeltaFileFormatWriter (native)

VeloxColumnarToCarrierRow
+- ^(1) SortExecTransformer [input[2, int, true] ASC NULLS FIRST], false, 0
   +- ^(1) ProjectExecTransformer [id#433L, concat(row-, cast(id#433L as string)) AS value#431, cast((id#433L % 2) as int) AS part#432]
      +- ^(1) InputIteratorTransformer[id#433L]
         +- ArrowColumnarToVeloxColumnar
            +- OffloadArrowData
               +- ColumnarRange 0, 6, 1, 1, 6, [id#433L]

These are the plans actually consumed by the writers, captured through their existing executedPlan test hooks, not just the input DataFrame's explain() output. The outer command is Execute GlutenDelta SaveIntoDataSourceCommand in both runs. VeloxColumnarToCarrierRow carries native batches through the row-based writer interface rather than materializing every row.

The example has no row constraints. Omitting its no-op DeltaInvariantChecker is an existing native-path optimization, not a change introduced here; the checker is retained when constraints exist.

Physical file Parquet created_by Physical columns
Before parquet-mr version 1.16.0 id, value, part
After parquet-cpp-velox version 0.0.0 id, value, part

Both standalone part=1 files contain (1, row-1, 1), (3, row-3, 1), and (5, row-5, 1), with part physically stored as INT32. Spark and independent PyArrow reads agree. Delta's fallback already wrote correct materialized files; the improvement is native execution, not different data.

Capture provenance: matched pre-rebase CI bundles: main 1ac8f880 versus PR head 69706f449, tested as merge 8fff74dc onto that same main. The materialization implementation is unchanged in rebased head 45b16ab55; these captures are not represented as executions of that newer build.

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

Generated-by: GitHub Copilot 1.0.102-0.unstable.r40141230562.g130d689 (GPT-6 Astra / gpt-6-astra)

@github-actions github-actions Bot added CORE works for Gluten Core VELOX DOCS labels Oct 30, 2026
@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

@github-actions github-actions Bot added the INFRA label Oct 30, 2026
@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

1 similar comment
@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

@felipepessoto
felipepessoto marked this pull request as ready for review November 4, 2026 18:08
Copilot AI balanced review requested due to automatic review settings November 4, 2026 18:09
@felipepessoto
felipepessoto force-pushed the felipepessoto-delta-partition-materialization branch from 69706f4 to 45b16ab Compare November 4, 2026 18:20

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 partition-column materialization changes.

No open issues 🎉

What changed in this PR

Enables Velox native writes for Delta partition-column materialization on Spark 4.x, including Delta 4.4’s default partitioned writes, while retaining unsupported-case fallbacks.

Changes:

  • Passes partition-column retention through Scala, Java, and JNI, preserving Delta’s file-schema order and excluding partition columns from statistics.
  • Adds coverage for feature/property precedence, physical Parquet contents, writer identity, mixed-file reads, and UPDATE/DELETE behavior.
  • Updates support documentation and restores ten known failures exposed by native execution.
File Description
gluten-ut/​spark35/​src-delta/​test/​scala/​org/​apache/​spark/​sql/​execution/​datasources/​GlutenDeltaNativePartitionWriteSuite.scala Tests materialized columns, reordered keys, nulls, file limits, and statistics.
docs/​backends/​velox/​get-started/​VeloxDelta.md Documents materialization support and remaining type restrictions.
cpp/​velox/​jni/​VeloxJniWrapper.cc Retains partition columns after data columns when requested.
backends-velox/​src/​main/​scala/​org/​apache/​spark/​sql/​execution/​datasources/​velox/​VeloxFormatWriterInjects.scala Forwards the partition-retention flag to JNI.
backends-velox/​src/​main/​java/​org/​apache/​gluten/​datasource/​VeloxDataSourceJniWrapper.java Adds the partition-retention argument to the native interface.
backends-velox/​src-delta4/​test/​scala/​org/​apache/​spark/​sql/​delta/​DeltaNativeWriteSuite.scala Exercises Delta’s default partition-column behavior.
backends-velox/​src-delta4/​test/​scala/​org/​apache/​gluten/​execution/​VeloxDelta4WriteSuite.scala Tests precedence, interoperability, rewrite operations, and mapping fallbacks.
backends-velox/​src-delta4/​test/​scala/​org/​apache/​gluten/​delta/​GlutenDeltaNativeWriteGateSuite.scala Tests materialization eligibility and retained restrictions.
backends-velox/​src-delta4/​main/​scala/​org/​apache/​spark/​sql/​delta/​GlutenDeltaNativeWriteGate.scala Allows materialization while rejecting unsupported partition types.
backends-velox/​src-delta4/​main/​scala/​org/​apache/​spark/​sql/​delta/​files/​GlutenDeltaFileFormatWriter.scala Retains partition columns for writing and projects data-only statistics batches.
.github/​workflows/​util/​delta-spark-ut/​known-failures.txt Restores eight exception-contract and two concurrent OPTIMIZE failures.

Review effort: Balanced

@felipepessoto

Copy link
Copy Markdown
Contributor Author

Hi @malinjawi, @zhztheplayer, and @zhouyuan could you review this PR? It adds native partition-column materialization (enabled by default in 4.4), allowing supported Delta 4.4 partitioned writes to run natively instead of falling back.
Thanks!

@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

@malinjawi malinjawi 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.

Thanks @felipepessoto , looks good overall. The column order, stats exclusion and batch ownership all check out. A few points:

  1. CHECK and NOT NULL violations on default partitioned tables now lose Delta's exception type too, not just replaceWhere. Worth noting, and it overlaps with #13133.
  2. Writes to file systems the native writer can't handle (e.g. s3a without S3 support) now fail instead of falling back. My draft #13386 adds that check to the gate.
  3. CDF DML now runs native even on unpartitioned tables (__is_cdc). The output matches Delta, but it could use a mention and a small test.

Smaller gaps: no file-level test for OPTIMIZE on materialized tables, and no Spark 4.x CI job runs DeltaNativeWriteSuite.

Copilot AI balanced review requested due to automatic review settings November 5, 2026 19:41
@felipepessoto

Copy link
Copy Markdown
Contributor Author

@malinjawi Pushed e57998b with the review follow-ups. The inline replies cover the timestamp guard and direct UPDATE/DELETE file reads. I also added partitioned and unpartitioned CDF UPDATE/DELETE cases that inspect both data and change Parquet files and compare the rows with vanilla Delta, plus an OPTIMIZE case that requires real file replacement and checks the new files, partition values, and statistics. The docs now explain the virtual __is_cdc partition and the wider CHECK/NOT NULL exception impact.

DeltaNativeWriteSuite is now explicitly included in group 1 of the existing Spark 4.0/4.1/4.2 CI jobs. I checked the actual parallel-UT discovery output: only that suite is added, with no existing suites lost. All 59 focused tests passed locally on Spark 4.1, including its 12 tests; fresh CI is pending.

The generic JNI fix remains in #13133, where combined strict Delta constraint validation is being added separately. I also followed up on #13386 about checking connector build availability as well as URI schemes. Neither exception preservation nor filesystem fallback is claimed fixed by this PR.

@github-actions

github-actions Bot commented Nov 5, 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

Shared JNI splitting and asynchronous statistics-batch ownership now affect default partitioned Delta writes, warranting human review of persisted-file compatibility while full native/Spark 4.0–4.2 validation remains pending.

No open issues 🎉

Review effort: Balanced

@malinjawi malinjawi 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.

Thanks @felipepessoto, this covers everything I raised. Falling back on TIMESTAMP partitions in both modes is the safe call, and I like that the UPDATE/DELETE, CDF and OPTIMIZE tests now check the actual Parquet files. Nice to see DeltaNativeWriteSuite running on 4.0, 4.1 and 4.2 as well. Leaving the exception types to #13133 and the filesystem side to #13386 makes sense to me.

Small optional nit: in VeloxDelta.md, the sentence saying CI checks partitioned save(path) on 3.5 to 4.1 and OPTIMIZE on 3.5 is a bit out of date now that the next line adds the 4.0, 4.1 and 4.2 jobs.

LGTM!

Copilot AI balanced review requested due to automatic review settings November 6, 2026 17:42
@felipepessoto
felipepessoto force-pushed the felipepessoto-delta-partition-materialization branch from 1710bcf to ab1c25d Compare November 25, 2026 00:22
Copilot AI balanced review requested due to automatic review settings November 25, 2026 00:22
@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.

🟢 Approval recommended

No active review issues remain for the Delta partition-column materialization changes.

No open issues 🎉

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 25, 2026 00:44
@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.

🟢 Approval recommended

No active review issues remain for the Delta partitioned-table native-write changes.

No open issues 🎉

Review effort: Balanced

felipepessoto and others added 9 commits November 25, 2026 10:34
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Restore the ten failures removed by e920e70 when partitioned writes fell back to Delta. Materializing partition columns re-exposes existing JNI exception-loss and custom-filesystem limitations; record them without changing production behavior or test assertions.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Guard TIMESTAMP partition splitting independently of materialization; verify physical UPDATE, DELETE, CDF and OPTIMIZE outputs; and select DeltaNativeWriteSuite in Spark 4.x CI. Document the existing constraint exception and filesystem limitations without duplicating their separate fixes.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Keep the materialization caveats consistent with upstream's NOT NULL exception recovery; CHECK and replaceWhere still require generic JNI preservation.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Preserve the merged filesystem eligibility gate and exercise fallback for default and feature-forced materialization, including OPTIMIZE and physical partition values. Refresh the remaining JNI dependency caveat.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Both original upstream concurrent OPTIMIZE cases pass with the merged filesystem fallback and materialization. Keep the eight replaceWhere exception-contract cases until iterator preservation is integrated.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@felipepessoto
felipepessoto force-pushed the felipepessoto-delta-partition-materialization branch from d28b3f3 to db5d719 Compare November 25, 2026 18:35
Copilot AI balanced review requested due to automatic review settings November 25, 2026 18:35
@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.

🟢 Approval recommended

No active review issues block the expanded Velox native-write support for eligible Delta partitioned tables.

No open issues 🎉

Review effort: Balanced

@felipepessoto

Copy link
Copy Markdown
Contributor Author

@zhztheplayer FYI, we are waiting for #13133 first, and merge this after it: #13502 (comment)

@felipepessoto felipepessoto changed the title [GLUTEN-13500][VL] Support Delta partition column materialization [GLUTEN-13500][VL] [Blocked on #13133] Support Delta partition column materialization Nov 25, 2026
@felipepessoto
felipepessoto marked this pull request as draft November 26, 2026 18:08
@felipepessoto felipepessoto changed the title [GLUTEN-13500][VL] [Blocked on #13133] Support Delta partition column materialization [GLUTEN-13500][VL] [Blocked on #13561 and #13563] Support Delta partition column materialization Nov 26, 2026
@felipepessoto felipepessoto changed the title [GLUTEN-13500][VL] [Blocked on #13561 and #13563] Support Delta partition column materialization [GLUTEN-13500][VL] [Blocked on #13563 and #13135] Support Delta partition column materialization Nov 26, 2026
@felipepessoto felipepessoto changed the title [GLUTEN-13500][VL] [Blocked on #13563 and #13135] Support Delta partition column materialization [GLUTEN-13500][VL] [Blocked on #13135] Support Delta partition column materialization Nov 27, 2026

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 INFRA VELOX

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[VL][Delta] Support materializePartitionColumns in native writes

5 participants