Skip to content

[spark] Support configurable dynamic partition column order - #9167

Draft
sablejade wants to merge 1 commit into
apache:masterfrom
sablejade:master-hive-dynamic
Draft

[spark] Support configurable dynamic partition column order#9167
sablejade wants to merge 1 commit into
apache:masterfrom
sablejade:master-hive-dynamic

Conversation

@sablejade

Copy link
Copy Markdown

Purpose

This PR fixes a Spark dynamic partition write issue where positional writes may be incorrectly interpreted as Hive-style dynamic partition writes.

When writing to a partitioned Paimon table with Spark SQL dynamic partition syntax, the query output may already follow the target table schema order. However, the current logic may still treat it as Hive-style order and move dynamic partition columns from the tail. This can misalign columns, especially for UNION queries whose output names are inherited from the first branch.

For example, a UNION query may output columns in the correct table schema order, but one expression name, such as detail_ratio, does not match the target column name value. The write is positional, so the value should still be written to the value column. Relying only on output names can misclassify the query order and cause silent column misalignment when column types are compatible.

This PR adds a configurable dynamic partition column order mode:

  • AUTO: preserve compatible behavior and automatically detect table-order or Hive-style-order writes.
  • TABLE: always interpret positional dynamic partition writes using the target table schema order.
  • HIVE: interpret dynamic partition writes using Hive-style order when applicable.

Changes

  • Add spark.paimon.sql.dynamic-partition-column-order.
  • Support AUTO, TABLE, and HIVE modes.
  • Avoid unnecessary Hive-style reordering when the query already follows table schema order.
  • Make dynamic overwrite without explicit PARTITION (...) respect the configured column order when Hive-style output is applicable.
  • Add Spark SQL tests for:
    • UNION output whose expression names differ from target column names.
    • AUTO table-order detection.
    • AUTO/HIVE Hive-style detection.
    • Explicit TABLE mode.
    • Explicit HIVE mode.
    • INSERT BY NAME behavior.
    • Invalid config handling.

Tests

  • PaimonDynamicPartitionColumnOrderTest

Closes #9156

@sablejade sablejade changed the title [SPARK] Support configurable dynamic partition column order [spark] Support configurable dynamic partition column order Aug 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug][Spark] Positional dynamic partition writes can silently misalign columns

1 participant