Spark 4.1: Implement SupportsReportOrdering DSv2 API#16750
Draft
anuragmantri wants to merge 1 commit into
Draft
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR depends on #14948
This PR implements the Spark DSv2 SupportsReportOrdering API to report sort order to Spark, enabling sort elimination for partitioned tables when reading sorted Iceberg tables that have a defined sort order and files are written respecting that order.
Sort order reporting can be enabled with:
Implementation summary:
SortOrderAnalyzer validates two conditions before SparkPartitioningAwareScan.outputOrdering() reports ordering to Spark:
Merging Sorted Files: When ordering is reported, another PR (Spark 4.1: Add MergingSortedRowDataReader for k-way merge of sorted files #14948) adds MergingSortedRowDataReader to merge rows from multiple sorted files within a partition using k-way merge. The plumbing for the merging reader (SparkRowReaderFactory, SparkBatch) is included here.
Constraints:
preserve-data-orderingis enabled, bin-packing of large partitions is disabled. All files within a partition are placed into a single Spark task. This is a known limitation of the current KeyGroupedPartitioning approach and is expected to be addressed in SPARK-56241.Depends on #14948 for MergingSortedRowDataReader.
AI Usage: I used Claude Opus 4.6 for code generation and writing tests. I manually reviewed the generated code.