Hourly partitions in table format Iceberg, yet queries on old hours still read whole days — why?
The Iceberg table lake.events was partitioned by day(event_ts). On 1 September 2026 the team ran ALTER TABLE lake.events REPLACE PARTITION FIELD day(event_ts) WITH hour(event_ts) and expected one-hour dashboard queries to read about an hour of data. October hours do; August hours still read a whole day.
Constraints: dashboards filter only on event_ts; the old daily files were written in arrival order, unsorted; storage budget allows rewriting about 90 days of data.
scan metrics per query (illustrative)
WHERE event_ts >= '2026-08-14 10:00' AND event_ts < '2026-08-14 11:00'
spec_id=0 [day(event_ts)] files scanned: 96 bytes: 48.1 GB rows read: 2.3 B rows returned: 97 M
WHERE event_ts >= '2026-10-14 10:00' AND event_ts < '2026-10-14 11:00'
spec_id=1 [hour(event_ts)] files scanned: 4 bytes: 2.0 GB rows read: 98 M rows returned: 98 MDiagnose the cause and say what you would do.
Partition evolution is metadata-only: old files keep the daily spec, and Iceberg plans each spec apart, so an hour filter on old data prunes only to the day and reads whole unsorted daily files. Rewrite under the new spec only the history queries hit.
- Expecting partition evolution to rewrite existing files into the new layout
- Rewriting the whole history instead of only the ranges that queries actually read
- Thinking queries must filter on a derived partition column rather than on
event_ts
- How would you rewrite only the last 90 days of data under the hourly spec?
- Why would sorting the old daily files by
event_tshelp without changing their partitioning?
Cause. Hidden partitioning stores the transform in the partition spec (day(event_ts), then hour(event_ts)), while the query filters on event_ts itself; Iceberg derives the partition predicate from the filter for each spec. Evolution is a metadata operation: it changes the spec for new writes and does not rewrite old files. So the table holds two sets of files — spec_id=0 with daily values and spec_id=1 with hourly ones — and the planner prunes each by its own spec. For August the best it can do is one day: 96 files, 48 GB. Min/max statistics on event_ts do not help either: the files were written in arrival order, so each one's range covers almost the whole day.
What to do. Rewrite under the new spec only what the dashboards read — the last 90 days, say. rewrite_data_files writes files in the table's current spec, and sorting by event_ts makes the statistics useful as well. The old ~500 MB files already sit inside the accepted size range (75–180% of the 512 MB target), so without rewrite-all the procedure would skip them:
CALL lake.system.rewrite_data_files(
table => 'lake.events',
strategy => 'sort',
sort_order => 'event_ts',
options => map('rewrite-all', 'true'),
where => 'event_ts >= TIMESTAMP ''2026-08-10 00:00:00'' AND event_ts < TIMESTAMP ''2026-09-01 00:00:00'''
);Older history that is rarely read stays daily: rewriting it is expensive and the gain is rare. In Hive the same change would mean a new table, a reload of all data, and rewriting the queries that filter on the partition column.