Skip to content

[VL] Fall back to vanilla Delta write for VariantType columns#12444

Merged
zml1206 merged 1 commit into
apache:mainfrom
felipepessoto:vl-variant-write-fallback
Jul 13, 2026
Merged

[VL] Fall back to vanilla Delta write for VariantType columns#12444
zml1206 merged 1 commit into
apache:mainfrom
felipepessoto:vl-variant-write-fallback

Conversation

@felipepessoto

@felipepessoto felipepessoto commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

What changes are proposed in this pull request?

Velox cannot write every Spark type. When native Delta write is enabled, Gluten offloads certain
Delta write commands to the native columnar writer (OffloadDeltaCommand) --
DataFrameWriter.save (append/overwrite), CREATE/REPLACE TABLE AS SELECT, UPDATE, DELETE
and OPTIMIZE. The native write path inserts a RowToVeloxColumnarExec transition that converts
the schema via SparkArrowUtil.toArrowSchema, which throws
UnsupportedOperationException: Unsupported data type: <type> at runtime for any type it has no
Arrow mapping for (VariantType is the motivating example). (Plain SQL INSERT INTO and MERGE
are not offloaded and were unaffected.)

This PR guards GlutenOptimisticTransaction.writeFiles with the backend's existing schema
validator: if VeloxValidatorApi.validateSchema(inputData.schema) reports the schema is not
supported, it delegates to super.writeFiles (the vanilla Delta write path) instead of offloading
to Velox, and logs an info message when it falls back. This reuses the same validator Velox already
applies to scan schemas (VeloxBackend.validateDataSchema), so unsupported types fall back
consistently before the Arrow schema conversion -- rather than adding a one-off VariantType guard
(per review feedback). Supported writes are unaffected.

How was this patch tested?

Adds DeltaVariantWriteSuite (backends-velox, delta-4.0). It exercises offloaded writes --
top-level and struct-nested variant columns via DataFrameWriter.save, plus an UPDATE -- and
asserts the data is written and read back correctly. The suite runs with the Gluten plugin and
spark.gluten.sql.columnar.backend.velox.delta.enableNativeWrite=true, so these writes go through
the native path that previously failed.

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

Generated-by: GitHub Copilot CLI (Claude Opus 4.8)

Copilot AI review requested due to automatic review settings July 4, 2026 00:56
@github-actions github-actions Bot added the VELOX label Jul 4, 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.

Pull request overview

This PR prevents Delta Lake writes from failing when the table schema contains Spark VARIANT columns by bypassing the Velox native columnar write path (which cannot represent VariantType in Arrow) and delegating those writes to the vanilla Delta writer instead.

Changes:

  • Add a recursive schema check (schemaContainsVariant) and guard GlutenOptimisticTransaction.writeFiles to fall back to super.writeFiles when any VARIANT is present (including nested).
  • Add a Delta 4.0 Velox-backend test suite validating top-level, struct-nested, and UPDATE writes involving VARIANT.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
backends-velox/src-delta40/main/scala/org/apache/spark/sql/delta/GlutenOptimisticTransaction.scala Adds a schema-based guard to route VARIANT-containing writes through vanilla Delta instead of the native Velox writer.
backends-velox/src-delta40/test/scala/org/apache/spark/sql/delta/GlutenDeltaVariantWriteSuite.scala Adds coverage ensuring VARIANT writes and updates succeed and round-trip correctly.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@felipepessoto felipepessoto force-pushed the vl-variant-write-fallback branch from b7c684f to d97a33e Compare July 4, 2026 04:09
Copilot AI review requested due to automatic review settings July 4, 2026 04:17
@felipepessoto felipepessoto force-pushed the vl-variant-write-fallback branch from d97a33e to bff7ffa Compare July 4, 2026 04:17

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.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

@felipepessoto felipepessoto force-pushed the vl-variant-write-fallback branch from bff7ffa to c40c3c7 Compare July 4, 2026 05:02
@felipepessoto felipepessoto marked this pull request as draft July 4, 2026 20:00
@felipepessoto felipepessoto force-pushed the vl-variant-write-fallback branch from c40c3c7 to 84e9591 Compare July 4, 2026 21:03
felipepessoto added a commit to felipepessoto/gluten that referenced this pull request Jul 4, 2026
…thout the fix)

Adds only GlutenDeltaVariantWriteSuite, WITHOUT the GlutenOptimisticTransaction
guard from apache#12444, to demonstrate that the suite fails on an
unpatched main: with native Delta write enabled, the Velox write path throws
`UnsupportedOperationException: Unsupported data type: variant` at runtime.

Do not merge -- this PR exists only to validate that the test is an effective
regression test for apache#12444.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@felipepessoto

Copy link
Copy Markdown
Contributor Author

Validation that it fails without the fix is here: #12445 (comment)

@felipepessoto felipepessoto marked this pull request as ready for review July 6, 2026 16:49
Copilot AI review requested due to automatic review settings July 6, 2026 16:49
@felipepessoto

Copy link
Copy Markdown
Contributor Author

@baibaichen could you please review?

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.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

// RowToVeloxColumnarExec transition whose SparkArrowUtil.toArrowSchema call throws
// `Unsupported data type: variant` at runtime. Delegate writes whose schema contains a
// variant column to the vanilla Delta write path instead of offloading them.
if (inputData.schema.existsRecursively(_.isInstanceOf[VariantType])) {

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, could we reuse the existing VeloxValidatorApi.validateSchema / doSchemaValidate for Delta/native write schema validation instead of adding another one-off VariantType guard? That would make unsupported Spark types fail consistently before RowToVeloxColumnarExec / Arrow schema conversion.

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.

Done. Thanks for the suggestion

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.

@zml1206 I also addressed some Copilot comments. Could you review again please?

Copilot AI review requested due to automatic review settings July 9, 2026 07:45
@felipepessoto felipepessoto force-pushed the vl-variant-write-fallback branch from 84e9591 to f113e26 Compare July 9, 2026 07:45
felipepessoto added a commit to felipepessoto/gluten that referenced this pull request Jul 9, 2026
…thout the fix)

Adds only GlutenDeltaVariantWriteSuite, WITHOUT the GlutenOptimisticTransaction
guard from apache#12444, to demonstrate that the suite fails on an
unpatched main: with native Delta write enabled, the Velox write path throws
`UnsupportedOperationException: Unsupported data type: variant` at runtime.

Do not merge -- this PR exists only to validate that the test is an effective
regression test for apache#12444.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

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.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

Copilot AI review requested due to automatic review settings July 9, 2026 07:53

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.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

Copilot AI review requested due to automatic review settings July 9, 2026 08:00
@felipepessoto felipepessoto force-pushed the vl-variant-write-fallback branch from 5db07eb to c143d1d Compare July 9, 2026 08:04

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.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Copilot AI review requested due to automatic review settings July 9, 2026 08:05

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.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Copilot AI review requested due to automatic review settings July 9, 2026 08:11
@felipepessoto felipepessoto force-pushed the vl-variant-write-fallback branch from c143d1d to 95d8dcf Compare July 9, 2026 08:11

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.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

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

Nit: Could we rename this suite to DeltaVariantWriteSuite? Other Delta suites in this source set do not use the Gluten prefix, and the file already lives under Gluten's Velox Delta tests, so DeltaVariantWriteSuite would be more consistent. cc @zhztheplayer

Copilot AI review requested due to automatic review settings July 10, 2026 01:38
@felipepessoto felipepessoto force-pushed the vl-variant-write-fallback branch from 95d8dcf to e7b4d4c Compare July 10, 2026 01:38

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.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

@felipepessoto felipepessoto force-pushed the vl-variant-write-fallback branch from e7b4d4c to 6d77625 Compare July 10, 2026 01:46
Velox cannot write every Spark type. When native Delta write is enabled, Gluten
offloads certain Delta write commands to the native writer via OffloadDeltaCommand
-- DataFrameWriter.save (append/overwrite), CREATE/REPLACE TABLE AS SELECT,
UPDATE, DELETE and OPTIMIZE. The native write path inserts a RowToVeloxColumnarExec
transition whose SparkArrowUtil.toArrowSchema call throws
`UnsupportedOperationException: Unsupported data type: <type>` at runtime for any
type it has no Arrow mapping for (VariantType is the motivating example). (Plain
SQL INSERT INTO and MERGE are not offloaded and were unaffected.)

Guard GlutenOptimisticTransaction.writeFiles with the backend's existing schema
validator: if VeloxValidatorApi.validateSchema reports the input schema is not
supported, delegate to super.writeFiles (the vanilla Delta write path) instead of
offloading. This reuses the same check Velox already applies to scan schemas, so
unsupported types fall back consistently before Arrow schema conversion rather
than adding a one-off VariantType guard. Supported writes are unaffected, and the
validator's reason is logged when it falls back.

Adds DeltaVariantWriteSuite, which exercises offloaded writes: top-level
and struct-nested variant columns via DataFrameWriter.save, plus an UPDATE.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 10, 2026 19:13
@felipepessoto felipepessoto force-pushed the vl-variant-write-fallback branch from 6d77625 to decb51c Compare July 10, 2026 19:13

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.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

@zml1206 zml1206 merged commit cd37d7a into apache:main Jul 13, 2026
53 of 54 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants