liveBook · Manning

RewriteDataFiles

As explained in Architecting an Apache Iceberg Lakehouse

RewriteDataFiles is an Apache Iceberg maintenance procedure that rewrites table data files to consolidate or improve their physical layout.

RewriteDataFiles is an Apache Iceberg maintenance procedure that rewrites physical data files to improve layout, reduce metadata overhead, and accelerate reads. It can merge small or oversized files, apply compression, sort records, consolidate delete files, and refresh file statistics. section 10.2.1

Choose the rewrite strategy according to workload and operational constraints:

  • Bin-pack, the default, combines small files into target-sized outputs and reduces file-open and metadata costs. section 10.2.1
  • Sort rewrites records by selected columns to improve locality and predicate pruning; Z-order can help multidimensional access patterns but may increase compaction cost and is workload dependent. section 10.2.1
  • Merge-on-Read tables particularly benefit when delete files accumulate, because rewriting applies deletes to base files and restores read performance. section 10.1.4

Operational guardrails

Run compaction incrementally by partition, file size, or timestamp, and validate parameters before orchestration. Bound data volume and file counts, use planning or dry-run modes where available, and monitor query latency, planning time, delete-file growth, and table-size expansion. section 10.1.4 section 11.3.2

CALL catalog_name.system.rewrite_data_files(
    table =>'db.sales',
    strategy =>'sort',
    sort_order =>'zorder(customer_id, product_id)'
);

A Spark SQL example shows how to invoke RewriteDataFiles with sort and Z-order options. section 10.2.1

How Architecting an Apache Iceberg Lakehouse covers it

How deep it goes
Explains bin-pack, sort, delete-file application, targeting, and safeguards, but defers detailed procedure-option semantics.
Examples
Uses Spark SQL calls, sort and Z-order settings, targeted partition cleanup, and monitoring signals such as delete-file growth.
What it assumes
Assumes familiarity with Iceberg tables, data and delete files, table reads, and Merge-on-Read behavior.
What you can do after
Apply it via Spark SQL with bin-pack or sort settings, then operate it through bounded and monitored maintenance workflows.
How it connects
Connects compaction with Apache Iceberg, Merge-on-Read, Copy-on-Write, delete files, predicate pushdown, and manifest rewriting.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Architecting an Apache Iceberg Lakehouse. The section links point to the parts of the book it draws on.