Uh oh!
There was an error while loading. Please reload this page.
Core, Spark 4.1: Add K-way merge rewrite strategy for pre-sorted data files - #16305
Core, Spark 4.1: Add K-way merge rewrite strategy for pre-sorted data files#16305anuragmantri wants to merge 5 commits into
Conversation
| * A planner for K-way merge rewriting that selects files based on size thresholds and orders them | ||
| * by sort-key lower bounds before bin-packing into groups. | ||
| * | ||
| * <p>File selection uses the same size-based criteria as other strategies: files outside the |
There was a problem hiding this comment.
What makes this distinct from the planning processes in the other planners? I'm wondering if it's right to have a completely independent planner or or whether this shouldn't just be some special things or flags on the Sort planner? In general I'm not sure this need to be a completely separate hierarchy and maybe should be part of sort?
There was a problem hiding this comment.
You're right. The planning logic is structurally the same as BinPack/Sort. The key differences are that k-way merge needs includeColumnStats() on the scan and sorts files by lower bounds before bin-packing (so groups cover contiguous key ranges). I refactored to extend BinPackRewriteFilePlanner and made the scan overridable for k-way merge. Let me know what you think.
| } | ||
| @Override | ||
| protected Iterable<List<FileScanTask>> planFileGroups(Iterable<FileScanTask> tasks) { |
There was a problem hiding this comment.
This is basically the same as the parent code so i'm wondering if we have the inheritance off here
There was a problem hiding this comment.
I now inherited from the BinPackRewriteFilePlanner. That reduced a lot of duplication but I had to override planFileGroups() because we sort by lower bounds to reduce the overlap.
This pull request has been marked as stale due to 30 days of inactivity. It will be closed in 1 week if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the dev@iceberg.apache.org list. Thank you for your contributions. |
anuragmantri
commented
Jul 6, 2026
This is not stale. |
nssalian
commented
Aug 3, 2026
@anuragmantri this needs a rebase to pick up some of the changes that went in for CVEs |
4112b02 to
36b2b67Comparegimgit
commented
Aug 20, 2026
I've been working in the same area (#17504, overlap measurement/selection on the sort key), so I read this with interest. K-way merge for pre-sorted files fills a real gap — sort compaction re-shuffles data that is already 99% ordered, and that cost is what pushes people to skip maintenance. A few questions and one coordination note:
|
This PR adds a K-way merge compaction strategy to the RewriteDataFiles action. K-way merge rewrites pre-sorted data files by streaming-merging them in sort-key order without shuffle, preserving the table's sort order in output files.
K-way merge is intended for tables that are already sorted but have accumulated multiple overlapping files per partition (e.g., after daily ingestion into a previously sort-compacted table). It achieves the same output as SORT but eliminates shuffle and spill entirely.
Implementation summary:
Constraints:
Usage:
AI Usage: I used Claude Opus 4.7 for code generation, test writing, and review. I manually reviewed and validated all generated code.