Skip to content

WIP: Iceberg bucket partitioning as the default for integer ID columns - #280

Open
bdpedigo wants to merge 4 commits into
masterfrom
bucket-partitioning
Open

bdpedigo wants to merge 4 commits into
masterfrom
bucket-partitioning

Conversation

@bdpedigo

@bdpedigo bdpedigo commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • New bucket partition strategy for the Delta Lake export. It uses the Iceberg bucket[N] transform from cavebear, and stores the spec in the table property cave.partition_spec.
  • Integer ID columns (the primary key, B-tree index columns, the view id) now default to bucket. non-integer columns keep percentile_range, and Morton keeps uniform_range (for now).
  • The old hash strategy is removed, because it was not portable or stable across polars versions.
  • A bucket count must be a power of two. auto rounds up, and the wizard shows an error for a bad count.
  • Bumps deltalake>=1.6 (needed by cavebear) and polars>=2.1. deltalake 1.6.4 truncates timestamp stats to milliseconds, and older polars then skips files with matching rows.
  • CI now uses PostGIS 18 instead of 13. The new runner's Postgres 18 pg_dump writes a setting that Postgres 13 rejects, so the pg_dump transfer test failed.

Closes #274

Evidence

  • A local export of a real table with an 8-bucket pt_root_id spec gave 8 partitions, and all sampled rows were in the right bucket.
  • Not tried on minnie, only LTV
  • Wizard changes worked locally

bdpedigo and others added 4 commits November 24, 2026 15:03
- Replace the "hash" strategy (polars hash, not portable) with "bucket",
  the Iceberg bucket[N] transform from cavebear. The export stores the
  spec in the Delta table configuration (cave.partition_spec).
- Discovery gives "bucket" to integer PK and B-tree index columns, and
  to the view id. Other columns keep percentile_range.
- A bucket count must be "auto" or a power of two in [1, 2**30]. Auto
  rounds up. The wizard shows the error and disables Next.
- Depend on cavebear (pinned commit) and deltalake>=1.6.
- deltalake 1.6 writes timestamp stats in milliseconds: update the root
  ID update log test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
deltalake 1.6.4 writes timestamp min/max stats truncated to
milliseconds (delta-rs #4690), so a file's max can be up to 999 us
before its real max. polars < 2.1 compared filters with that max and
skipped files with matching rows: scan_delta returned no rows for
end_time_stamp == run end (fixed in polars #30194).

- Require polars>=2.1. Pin cavebear d335ccb, which does the same.
- Test that a polars filter on a run end finds the run (it fails on
  polars 1.39.3), and explain the truncated max in the stats test.
- Tell readers of the root ID update log which readers widen the max.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The ubuntu-26.04 runner has the Postgres 18 client. Its pg_dump writes
SET transaction_timeout, which Postgres 13 rejects, so the pg_dump
transfer test restored 0 rows. The engine image also uses the
Postgres 18 client.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A plain write_deltalake cannot set the custom cave.partition_spec
property, so cavebear.create_delta makes the table. That was done in
each flush (and each view batch) after an is_deltatable check. Now the
export creates every bucket lake from the first streamed batch, before
any write, and each flush only appends. The create fails if a table
exists, so an export never appends to a table without the spec.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@bdpedigo
bdpedigo marked this pull request as ready for review November 25, 2026 23:38
@bdpedigo
bdpedigo requested review from fcollman and a balanced review from Copilot November 25, 2026 23:38

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Selecting flat partitioning leaves the bucket strategy set without a partition column, keeping Next enabled but causing export launch to fail with HTTP 400.

1 open issue
What changed in this PR

This PR integrates cavebear’s Iceberg bucket partitioning into Delta Lake exports, making it the default for integer ID columns and addressing #274.

Changes:

  • Replaces the old hash strategy with bucket partitioning and stores its specification in Delta table metadata.
  • Adds power-of-two bucket validation, automatic sizing, wizard feedback, and export tests.
  • Updates Delta Lake and Polars dependencies and moves CI to PostGIS 18.
File Description
uv.lock Locks cavebear and updated dependencies.
tests/​test_root_id_update_log.py Tests timestamp filtering with truncated statistics.
tests/​test_deltalake_export.py Covers bucket defaults, validation, metadata, and exports.
templates/​deltalake/​step2.html Adds bucket selection and validation feedback.
static/​js/​deltalakeStep2.js Validates and rounds bucket counts.
pyproject.toml Adds cavebear and raises dependency minimums.
materializationengine/​workflows/​root_id_update_log.py Documents timestamp-statistics truncation.
materializationengine/​workflows/​deltalake_export.py Implements bucket defaults, transforms, and table creation.
materializationengine/​blueprints/​deltalake/​api.py Applies strategy-aware partition sizing.
.github/​workflows/​materialization_ci.yml Updates the CI database to PostGIS 18.

Review effort: Balanced

Comment on lines +187 to +189
if (spec.partition_strategy !== "bucket") return null;
const n = spec.n_partitions;
if (n === null || n === undefined || n === "" || n === "auto") return null;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement hashing IDs via Iceberg's bucket scheme as default partitioning for ID columns

2 participants