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.

a table after one merge
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

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.

a new column arrives
$ 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
DuckDB: old rows read the new column as null
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.

two transforms
$ 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.

day1.jsonl, day2.jsonl
{"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}
two merges
$ 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)
DuckDB applies the 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

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.

What a merge costs

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.

compact
$ 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
Measured

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.

expire, dry run first
$ 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
Measured

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.

Guarded, not coordinated

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.

S3
$ 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
schemestorecredentials
s3://bucket/prefixAmazon S3 and S3-compatible storesAWS_* (AWS_ENDPOINT for a compatible store)
gs://, gcs://Google Cloud StorageGOOGLE_*
az://, azure://, abfs://, abfss://, adl://Azure Blob StorageAZURE_*
file:///abs/pathThe local filesystem, through the same code pathnone
Measured through a proxy adding 20 ms per request

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.

DuckDB: list snapshots, read one
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

local and S3
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