[WIP] Spark 4.1: Implement SupportsReportOrdering DSv2 API#14948
[WIP] Spark 4.1: Implement SupportsReportOrdering DSv2 API#14948anuragmantri wants to merge 2 commits intoapache:mainfrom
Conversation
cc08ff2 to
b4fde94
Compare
|
Moved the changes to Spark 4.1 since it is now the latest version. Marked this PR as WIP as there is a prerequisite PR #14683 that is also in review. |
|
My concern from Spark PoV is that unnecessary partition grouping can cause performance degradations. SPARK-55092 is a ticket about the problem and apache/spark#53859 / apache/spark#54330 PRs try to fix the problem. If this PR disables bin packing then the above PRs won't be able to fix the issue.
So I would suggest keeping bin packing and reporting sort order for those packed partitions (i.e. the partitions might not be unique by key, but they are locally sorted), and when partition grouping is actually needed then Spark should merge the sorted partitions with the same key using k-way merge. |
|
As we discussed offline, a long term (after apache/spark#54330) solution could be to improve the new |
Note: This PR builds on top of #14683 which is still in review. Reviewers can look at the changes in this commit b4fde94
This PR implements the Spark DSv2 SupportsReportOrdering API to enable Spark's sort elimination optimization for partitioned tables when reading sorted Iceberg tables that have a defined sort order and files are written respecting that order.
Implementation summary:
Ordering Validation:
SparkPartitioningAwareScan.outputOrdering()validates all files have the current table's sort order ID before reporting ordering to Spark. If validation fails, no ordering is reported.Merging Sorted Files: Since sorted files within a partition may have overlapping ranges, this PR introduces MergingSortedRowDataReader that merges rows from multiple sorted files using k-way merge with a min-heap.
Row Comparison:
InternalRowComparatorcompares Spark InternalRows based on Iceberg sort order.Constraints
Sort elimination examples
Without reporting sort order
With sort order reporting:
Without reporting sort order
With sort order reporting: