Operate
Iceberg tables
What shapeshift writes when the output is a table, and how to keep that table cheap to read and safe to write: appends and schema evolution, partitioning, upsert, compaction, expiry, concurrent writers, object stores and time travel. Outputs are from shapeshift 0.4.0; reads are from DuckDB 2.0.1.
What a table is
A self-contained Iceberg v2 table: a directory, or a bucket prefix, holding the data and every piece of metadata a reader needs. No catalog server writes it or reads it.
orders/ data/<uuid>.parquet # data files, PARQUET:field_id on every column data/delete-<uuid>.parquet # position deletes from a merge: (file_path, pos) metadata/<uuid>-m0.avro # manifests, with per-column statistics metadata/snap-<id>-1-<uuid>.avro # one manifest list per snapshot metadata/v1.metadata.json # one metadata file per commit: v1, v2, … metadata/v2.metadata.json metadata/version-hint.text # the newest version; only a hint
- Every commit is a new
v{N}.metadata.json. A commit succeeds only if it creates that file first (see the commit guard). - Paths are absolute, anchored where the table was written, so it reads back in place.
A copied or moved table is still readable with DuckDB's
allow_moved_paths = true; for every engine to read it with no flag the paths must be rewritten, whichshapeshift relocatedoes from 0.5. - Manifests are written by a small hand-rolled Avro encoder that keeps the
field-idattributes readers need; manifests are read back against the schema each one carries.
Append and schema evolution
Without --append, a write onto an existing table replaces it as the next version
(nothing is overwritten in place). With it, the write is a new snapshot on the existing table,
and it may add optional columns. Existing columns keep their field-ids, matched by name;
dropping, renaming or retyping a column, or adding a required one, is refused before any data
is written.
$ shapeshift shape -i day1.jsonl -o evo --to iceberg $ echo '{"id": 5, "name": "erin", "status": "new", "amount": 50.0, "region": "eu"}' > day3.jsonl $ shapeshift shape -i day3.jsonl -o evo --to iceberg --append shaped `day3` → evo (Iceberg) rows_in=1 rows_out=1 rejected=0 parse_errors=0 row_groups=1 bytes=1996 iceberg table metadata → evo/metadata/v2.metadata.json $ shapeshift inspect evo iceberg table: evo format-version: 2 table-uuid: 33c61602-e756-4ded-be04-c742026349e9 current-snapshot-id: 9217057256241778166 total-records: 4 columns (5): amount: double id: long name: string region: string status: string
SELECT id, name, region FROM iceberg_scan('evo') ORDER BY id;
-- 1 | alice | NULL
-- 2 | bob | NULL
-- 3 | carol | NULL
-- 5 | erin | eu
Partitioning
--partition-by (or output.partition_by) takes identity columns and
the hidden transforms bucket, truncate, year,
month, day and hour; the
spec page lists which types each accepts. The table's
partition spec records the real transform, so readers prune without knowing the layout.
$ shapeshift shape -i examples/events.jsonl -o ev_part --to iceberg \ --partition-by 'day(event_at), bucket(4, id)' shaped `events` → ev_part (Iceberg) rows_in=4 rows_out=4 rejected=0 parse_errors=1 row_groups=1 bytes=9189 malformed / rejected rows → ev_part.rejects.jsonl (1 parse, 0 shaped-out) iceberg table metadata → ev_part/metadata/v1.metadata.json $ find ev_part/data -type f ev_part/data/event_at_day=2026-07-11/id_bucket=2/<uuid>.parquet ev_part/data/event_at_day=2026-07-12/id_bucket=3/<uuid>.parquet ev_part/data/event_at_day=2026-07-13/id_bucket=0/<uuid>.parquet
Partition on low-cardinality transforms: every distinct value is at least one file per write. An append or merge must use the table's partition spec as it is.
Upsert: --merge-on
A source with updates carries the same key again and again. Appending it leaves one row per
version; --merge-on leaves one per key.
{"id": 1, "name": "alice", "status": "new", "amount": 10.0}
{"id": 2, "name": "bob", "status": "new", "amount": 20.0}
{"id": 3, "name": "carol", "status": "new", "amount": 30.0}
{"id": 2, "name": "bob", "status": "paid", "amount": 25.0}
{"id": 4, "name": "dave", "status": "new", "amount": 40.0}
{"id": 4, "name": "dave", "status": "paid", "amount": 45.0}
{"name": "ghost", "status": "new", "amount": 1.0}
$ shapeshift shape -i day1.jsonl -o orders --to iceberg --merge-on id shaped `day1` → orders (Iceberg) rows_in=3 rows_out=3 rejected=0 parse_errors=0 row_groups=1 bytes=1727 iceberg table metadata → orders/metadata/v1.metadata.json merged on (id): 3 key(s) — 0 updated, 3 inserted; 0 prior row(s) replaced scanned 0 data file(s), pruned 0 by key bounds; 0 position delete(s) in 0 delete file(s) $ shapeshift shape -i day2.jsonl -o orders --to iceberg --merge-on id shaped `day2` → orders (Iceberg) rows_in=4 rows_out=4 rejected=0 parse_errors=0 row_groups=1 bytes=1732 iceberg table metadata → orders/metadata/v2.metadata.json merged on (id): 2 key(s) — 1 updated, 1 inserted; 1 prior row(s) replaced 1 earlier occurrence(s) of a repeated key in the input were dropped (the last one wins) warning: 1 row(s) have a null key — appended, but they match nothing and can never be updated by a later merge scanned 1 data file(s), pruned 0 by key bounds; 2 position delete(s) in 1 delete file(s) $ shapeshift inspect orders | grep records live-records: 5 (7 written, 2 removed by position deletes)
SELECT * FROM iceberg_scan('orders') ORDER BY id NULLS LAST;
-- amount | id | name | status
-- 10.0 | 1 | alice | new
-- 25.0 | 2 | bob | paid
-- 30.0 | 3 | carol | new
-- 45.0 | 4 | dave | paid
-- 1.0 | NULL | ghost | new
- The last occurrence wins, against the table and within the input (dave →
paid). - A null key matches nothing, as in SQL
MERGE: appended, counted, warned about (ghost). - Composite keys:
--merge-on region,id. Keys may beint64,string,json,date,timestamporbool;float64is refused. - The first merge creates the table. A merge works across partitions (a key may move partition and its old row is still removed) and accepts additive schema changes.
How it works. Merge-on-read: the delta is appended as new data files, and every row it
supersedes is removed with an Iceberg v2 position delete, a small
(file_path, pos) Parquet file per partition that lost rows. No existing data file
is rewritten. To find the superseded rows the merge reads only the key columns of existing
files, and skips any file whose manifest key bounds rule out every incoming key.
On a 4 vCPU Intel Xeon @ 2.10 GHz (glibc release build, BENCHMARKS.md §7): merging 100,000 rows, 50,000 of them updates, into a 1M-row table took 0.37 s against 0.14 s to append them. When the updates touched only the newest keys of a 10-file table, 9 files were pruned (0.24 s).
Memory follows the delta, not the table: 33 MiB peak for 100,000 keys against 14 MiB for the append. A merge also loads the positions earlier merges deleted, which pile up until the table is compacted.
Compact
Each merge makes the table a little dearer to read: one more data file, one more delete file
every reader must apply, more manifests. compact pays that back in one snapshot.
$ shapeshift compact orders
compacted orders → snapshot 3251054351117798062 (replace)
rewrote 2 data file(s) (3.4 KiB) into 1 (1.7 KiB); kept 0 as they were
applied 2 position delete(s) from 1 delete file(s) — the table has none left
5 live row(s) rewritten across 1 partition(s); earlier snapshots still read their own files
- Every data file carrying a delete is rewritten without its deleted rows, so the table has no delete files afterwards.
- Small files are packed, per partition, into files of up to
--target-file-size(default512MiB, Iceberg's own).0only applies deletes. - The commit is one Iceberg
replacesnapshot whose manifest list names a single data manifest. The rows are unchanged; only the files holding them. - Time travel still works: earlier snapshots keep their files, so a compaction briefly adds storage.
expireis what reclaims it. - Nothing to do commits nothing. Columns a file predates are written as null.
Same machine as above. After 30 daily merges into a 1M-row table, a DuckDB
iceberg_scan took 71 ms (31 data files, 30 delete files, 61
manifests). After a 0.7 s compaction that peaked at 23 MiB: 9 ms,
against 7 ms before any merge. The next merge took 0.15 s instead of 0.28 s.
Expire
Every commit keeps the whole history, so any snapshot can be time-travelled to.
expire lets the old part go.
$ shapeshift expire orders --older-than 0s --dry-run would expire 2 snapshot(s) of orders; kept 1 (dry run: nothing changed) would delete 2 data file(s), 1 delete file(s), 3 manifest(s), 2 manifest list(s) — 12.9 KiB $ shapeshift expire orders --older-than 0s expired 2 snapshot(s) of orders; kept 1 deleted 2 data file(s), 1 delete file(s), 3 manifest(s), 2 manifest list(s) — 12.9 KiB
- What stays: the current snapshot, any snapshot a ref names, the newest
--retain-last(default 1) of the current history, and every snapshot newer than--older-than(default5d, Iceberg's own). - What goes: every manifest list, manifest, data and delete file only the expired snapshots reference.
- Never outside the table: a file whose path is not under the table's location is left and counted (a copied table can name the original's files).
- Commit first, delete after: an interrupted run leaves unreferenced files behind, never a table naming a missing one.
- A merge-only history frees little, because later snapshots still read every data file. After a
compact, it frees what the compaction replaced. Oldmetadata.jsonfiles are kept.
The same 30-merge table: 17.4 MiB in 185 files after the merges, 27.1 MiB once
compacted (the compaction keeps its inputs), 10.3 MiB in 38 files after
expire --older-than 0s, which took 0.01 s.
Concurrent writers: the commit guard
Several processes may write one table at once: a nightly merge, an hourly append, a
compact and an expire from an orchestrator. A commit is the creation
of metadata/v{N+1}.metadata.json, and it succeeds only if no other writer created it
first: locally a hard link that refuses to replace, on S3, GCS and Azure a conditional put. Of
two writers that built on the same version, the second is refused with
exit status 75.
- Nothing is lost, nothing is half-written. The refused writer removes every file it staged. Running it again builds on the winner.
- An unclear outcome is checked. A commit that errors on a store (a timeout can hide a put that landed) is checked against what the store holds; if it still cannot be told apart, its files stay rather than risk a committed snapshot's.
- A write that started before a compaction or expiry removed the files it was reading is refused the same way, not reported as a missing file.
version-hint.textis only a hint. It is replaced atomically after a commit and never moved backwards; readers and writers look past it for later versions, but only for a true successor, whosemetadata-lognames the version before it.- Append, merge,
compactandexpireare all guarded.
A writer that loses exits 75 and must run again: retry it from whatever schedules it.
Serialising writers instead of refusing them needs a catalog. The guard on S3 needs a store
that honours conditional writes (If-None-Match).
The repository's examples/merge/race_writers.py runs four writers merging into
one table while a janitor compacts and expires it, each retrying on 75; DuckDB reads exactly
what every writer's last round says, locally and over S3. The same race on a build without
the guard lost 400-odd of about 580 rows whose writers had been told they committed.
Object stores
In a build with --features object_store, an output or table can be a URL. Every
embedded path is anchored at it, so the table reads back from the bucket prefix like a
server-less Hadoop-style catalog.
$ export AWS_REGION=eu-west-1 AWS_ACCESS_KEY_ID=… AWS_SECRET_ACCESS_KEY=… $ shapeshift shape -i day2.jsonl -o s3://warehouse/db/orders --to iceberg --merge-on id $ shapeshift inspect s3://warehouse/db/orders $ shapeshift compact s3://warehouse/db/orders $ shapeshift expire s3://warehouse/db/orders --older-than 7d
| scheme | store | credentials |
|---|---|---|
s3://bucket/prefix | Amazon S3 and S3-compatible stores | AWS_* (AWS_ENDPOINT for a compatible store) |
gs://, gcs:// | Google Cloud Storage | GOOGLE_* |
az://, azure://, abfs://, abfss://, adl:// | Azure Blob Storage | AZURE_* |
file:///abs/path | The local filesystem, through the same code path | none |
- Writes: a file that fits in one 8 MiB part is one
PUT; larger ones are bounded-memory multipart uploads. A table's files go up 8 at a time, at most 16 MiB of file bytes in memory, then the guarded metadata file. A failed upload removes everything the write put. - Reads: a merge reads each data file's footer and then only its key columns' chunks, with ranged
GETs, 8 files at a time (SHAPESHIFT_READERSchanges it). A file's size comes from its manifest, so there is noHEAD. - Deletes: expiry hands every key to the store's bulk delete (on S3, one request per thousand keys).
inspectreads object-store tables; a Parquet file on a store is read with your query engine.
Against an S3-compatible server behind examples/merge/s3_proxy.py, on a 336-file
bucket(16, id) table, each 0.4 change measured against the build before it
(BENCHMARKS.md §7): reading 8 files at a time took a merge from 116.5 s to
18.0 s; one request per small file and 8 uploads in flight took an append from
3.12 s to 0.50 s and an expiry of 771 files from 58.5 s to 5.2 s;
planning the expiry in parallel took it to 1.02 s; reading ahead of the writer took a
compaction from 54.5 s to 6.8 s and a merge from 11.8 s to 6.4 s. A proxy
is not S3; the request counts are the durable part.
Time travel
Every snapshot stays readable until it is expired, including the ones before a compaction.
Below, the same two merges into a fresh orders, before any expiry.
SELECT * FROM iceberg_snapshots('orders');
-- 2 | 5535468230820774513 | 8220971173950475271 | 2026-11-24 17:21:18.249 | …/snap-5535468230820774513-1-….avro | overwrite | {…}
-- 1 | 8220971173950475271 | NULL | 2026-11-24 17:21:18.188 | …/snap-8220971173950475271-1-….avro | append | {…}
SELECT * FROM iceberg_scan('orders', snapshot_from_id = 8220971173950475271) ORDER BY id;
-- 10.0 | 1 | alice | new
-- 20.0 | 2 | bob | new
-- 30.0 | 3 | carol | new
Reading with DuckDB
INSTALL iceberg; LOAD iceberg;
SELECT count(*) FROM iceberg_scan('/warehouse/orders');
-- a moved or copied table: paths are anchored where it was written
SELECT count(*) FROM iceberg_scan('/elsewhere/orders', allow_moved_paths = true);
-- a bucket: httpfs and an S3 secret
INSTALL httpfs; LOAD httpfs;
CREATE SECRET (TYPE s3, KEY_ID '…', SECRET '…', REGION 'eu-west-1');
SELECT count(*) FROM iceberg_scan('s3://warehouse/db/orders');
The reads on this page were run with DuckDB 2.0.1 on tables written on another machine path,
so they passed allow_moved_paths = true; it is omitted above where it is not
needed. The repository checks merges, compaction, expiry and time travel against DuckDB with a
randomized model-check, examples/merge/verify_duckdb.py, locally, over
file:// and over S3.
Limits
- Every merge leaves a delete file that every reader applies until the table is compacted;
inspectshows how many rows they hide. - Concurrent writers are refused, not merged: the loser exits 75 and runs again.
- Rows are matched by key; deleting a row because a change feed says so (
op: d) is not supported. expirekeeps every oldmetadata.json, one small file per commit.timestampis zone-less (Icebergtimestamp, nottimestamptz).- No catalog: register a table with an external Iceberg REST catalog if engines should find it by name.