apache / apache/iceberg

Optimize re-partitioning for satisfiable schema evolution to minimize creation of too many small files.

Open
#16,514 1 comment 0 reactions 0 assignees View on GitHub
improvement
Dominant language
Java
Stars
9.2k
Forks
3.5k
Avg merge
2d 16h
Merged PRs (30d)
129

Description

On top of https://github.com/apache/iceberg/issues/16189

TL;DR : Current RewriteDataFiles algorithm leads to small fragmented files if partition spec has evolved over time. Proposing an optimized algorithm as described in attached images below.

### Feature Request / Improvement

**Problem**:
Let’s assume we have a large existing Iceberg table which is currently partitioned by month. After a few years, we would like to evolve the partition to have month and day as well. And now we want to rewrite all old data files using the current partition spec which is (month, day). As per the current algorithm, all the old partition spec data files are grouped in a single big group. If the data to be partitioned is large, a user will want to enable partial-progress. But then, the files are randomly split into multiple spark jobs. Thus, one partition gets processed in multiple spark jobs, which leads to small files in the resulting partition. These small files often require yet another round of compaction.

**Why it creates small files:**
Suppose there are 15TB of old spec data files. It will get broken into 150 spark shuffle jobs each processing 100GB of data. As the files are random in each group, every job can write files to all new partitions thus potentially leading to max of 150 files in each output spec partition.

**Current Solution:**
We have to run a separate compaction job to reduce the number of output files in each output partition.

**Proposed Solution:**
We can optimize the algorithm to create smaller groups of files per old partition even for older spec files if the current spec satisfies the older spec. By satisfies, we mean whether the new partition spec has the same ordering as the old partition spec. For example, the new partition by day on a timestamp field satisfies the old partition by month on the same timestamp field but vice-versa is not true.

### Query engine

None

### Willingness to contribute

- [ ] I can contribute this improvement/feature independently
- [x] I would be willing to contribute this improvement/feature with guidance from the Iceberg community
- [ ] I cannot contribute this improvement/feature at this time

Contributor guide

Open the contributing guide

Research direction

Start by reviewing the RewriteDataFiles algorithm and the related work in issue 16189. Determine how old partition-spec files are grouped when the current spec satisfies the old spec, then define tests showing that partial progress avoids scattering one old partition across many output groups. Done means the rewrite produces fewer fragmented files without changing partitioning behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
databases
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.