Skip to content

[VL][Iceberg] Add global iceberg sorted write - #13199

Open
infvg wants to merge 1 commit into
apache:mainfrom
infvg:iceberg-sort-order
Open

infvg wants to merge 1 commit into
apache:mainfrom
infvg:iceberg-sort-order

Conversation

@infvg

@infvg infvg commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Support INSERT INTO and INSERT OVERWRITE on sorted Iceberg tables using the native Velox writer. Previously, tables with a defined sort order caused writes to fall back to Spark.
Users can now perform:

  • Global sorted writes (write.distribution-mode=range): range-distribute incoming rows and produce sorted files with non-overlapping sort-key ranges within each Iceberg partition for that write.
  • Local sorted writes (write.distribution-mode=none): sort rows within each write task without requiring redistribution for the write.

Supports ascending/descending order, null placement, transformed and nested sort keys, and preserves ordering across file rotation.

Does not reorganize existing files.

@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

@infvg
infvg marked this pull request as ready for review October 5, 2026 13:45
@zhouyuan
zhouyuan requested a balanced review from Copilot October 5, 2026 14:51

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.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

Review effort: Lite
Findings: 1 High severity · 1 Medium severity · 1 Low severity

Open (3)
What changed in this PR

Enable native Velox writes for Iceberg tables that define a sort order, supporting both global (range-distributed) and local (task-local) sorted writes without falling back to Spark.

Changes:

  • Adjust sort-order labeling so writes only advertise a sort order when Spark planned an ordering.
  • Gate validation of sorted-table writes behind a backend capability flag (supportsSortedWrite), enabling Velox sorted writes.
  • Add documentation and a dedicated test suite covering global/local/partitioned/transformed/nested sort keys and file rotation.
File Description
gluten-iceberg/​src/​main/​scala/​org/​apache/​iceberg/​spark/​source/​IcebergWriteUtil.scala Derives the sort order used for write metadata based on Spark’s required ordering.
gluten-iceberg/​src/​main/​scala/​org/​apache/​gluten/​execution/​IcebergWriteExec.scala Introduces a capability flag and relaxes sort-order validation for backends that support sorted writes.
backends-velox/​src-iceberg/​main/​scala/​org/​apache/​gluten/​execution/​AbstractIcebergWriteExec.scala Enables sorted writes for the Velox backend by overriding the capability flag.
docs/​get-started/​VeloxIceberg.md Documents how to use sorted native writes and relevant table properties.
backends-velox/​src-iceberg/​test/​scala/​org/​apache/​gluten/​execution/​enhanced/​VeloxIcebergSuite.scala Removes the old “sorted table must fallback” test that no longer applies for Velox.
backends-velox/​src-iceberg/​test/​scala/​org/​apache/​gluten/​execution/​enhanced/​VeloxIcebergSortOrderSuite.scala Adds comprehensive tests validating sorted file contents and non-overlapping ranges (global) across multiple scenarios.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +120 to +123
if (write.asInstanceOf[SparkWrite].requiredOrdering().nonEmpty) {
getTable(write).sortOrder()
} else {
SortOrder.unsorted()

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.

Validation checks supportsWrite before this helper is reached so this isn't an issue

}
}
if (IcebergWriteUtil.getTable(write).sortOrder().isSorted) {
if (!supportsSortedWrite && IcebergWriteUtil.getTable(write).sortOrder().isSorted) {

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.

fixed, Changed validation to use getSortOrder(write).isSorted

Comment on lines +33 to +35
Supported Parquet writes can offload when
`spark.gluten.sql.enable.enhancedFeatures` and
`spark.gluten.sql.columnar.iceberg.enableNativeWrite` are enabled.

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.

fixed

@infvg
infvg force-pushed the iceberg-sort-order branch from 1fab148 to 8400ec6 Compare October 5, 2026 15:43
@infvg
infvg force-pushed the iceberg-sort-order branch 2 times, most recently from 6946dbb to 151a6b2 Compare October 5, 2026 16:29
@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

@github-actions github-actions Bot added the CORE works for Gluten Core label Oct 5, 2026
@infvg
infvg force-pushed the iceberg-sort-order branch from 151a6b2 to 737be71 Compare October 5, 2026 16:53
@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

2 similar comments
@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

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

Which PR in Velox supports this feature?

def getSortOrder(write: Write): SortOrder = {
getTable(write).sortOrder()
if (write.asInstanceOf[SparkWrite].requiredOrdering().nonEmpty) {
getTable(write).sortOrder()

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.

What returns when write.asInstanceOf[SparkWrite].requiredOrdering() is empty?

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.

SortOrder.unsorted() will be returned and the output files will be recorded as unsorted

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.

What if we return getTable(write).sortOrder() in this case?

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.

The table’s sort order tells us how the data should be sorted, but this is for the individual write which can be unsorted. So if we return the table's sort order it will just label the files sorted even if they aren't

@jinchengchenghh jinchengchenghh 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!

@infvg
infvg force-pushed the iceberg-sort-order branch from 737be71 to 914c850 Compare October 15, 2026 14:05
@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

@infvg
infvg force-pushed the iceberg-sort-order branch from 914c850 to d73f971 Compare October 15, 2026 16:31
@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants