Skip to content

Puffin output format - #121982

Merged
scanhex12 merged 28 commits into
masterfrom
puffin_output
Nov 17, 2026
Merged

scanhex12 merged 28 commits into
masterfrom
puffin_output

Conversation

@scanhex12

@scanhex12 scanhex12 commented Sep 24, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • New Feature

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Puffin output format (iceberg v3 related feature)


Workflow [PR]
Sync PR [sync-upstream/pr/121982]

Version info

  • Merged into: 26.11.1.2632-master (included in 26.11 and later)

@clickhouse-gh clickhouse-gh Bot added the comp-formats Input/output formats (CSV/JSON/Parquet/ORC/Arrow/Protobuf/etc.). label Sep 24, 2026
@alesapin alesapin self-assigned this Sep 24, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [0f6197b]

Summary: ✅


AI Review

Summary

Adds Puffin output for deletion vectors and Theta column statistics, separates container and blob handling, and lets the readers handle other blob types. Reviewed PR head 0f6197bc9f7456d67292ae38a1745c5169281abd, including all prior discussion. The recent optional-properties and independent-hash findings are addressed. Two previously dismissed writer/reader size-limit mismatches remain; request changes on those. No new blocking or major inline findings were identified.

Findings

⚠️ Majors

  • src/Processors/Formats/Impl/Puffin/PuffinWriter.cpp:71 [dismissed by author -- https://github.com/Puffin output format #121982#discussion_r4104296210]: The writer accepts footer payloads up to INT32_MAX, while readPuffinFooterFromSeekable rejects payloads above 16 MiB. With enough referenced files, a successful write therefore produces a file that neither Puffin nor PuffinMetadata can reopen. This remains real despite the dismissal because the reader's hard limit remains in place. Align the supported limits, preferably through a shared constant.
  • src/Processors/Formats/Impl/Puffin/PuffinDeletionVector.cpp:37 [dismissed by author -- https://github.com/Puffin output format #121982#discussion_r4104296202]: The writer caps combined_length at INT32_MAX, then adds eight envelope bytes. Near that boundary, the resulting blob exceeds the reader's 2 GiB limit and cannot round-trip. This remains real because readDeletionVectorBlobBytes still enforces that ceiling. Validate the complete envelope length against the shared reader limit.

💡 Nits

Final Verdict

⚠️ Request changes — reconcile the two writer/reader size limits. The dismissed findings remain in this summary only; no existing threads were reopened or replied to, and no new inline review was posted.

@clickhouse-gh clickhouse-gh Bot added the pr-feature Pull request with new product feature label Sep 25, 2026
# Conflicts:
#	src/Core/SettingsChangesHistory.cpp
Comment thread src/Core/FormatFactorySettings.h Resolved
@asya-ch asya-ch self-assigned this Oct 8, 2026
@clickhouse-gh

clickhouse-gh Bot commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

Dear @alesapin, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself.

@clickhouse-gh

clickhouse-gh Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Dear @asya-ch, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself.

scanhex12 and others added 5 commits November 13, 2026 11:45
# Conflicts:
#	src/Formats/FormatFactory.cpp
#	tests/queries/0_stateless/02187_async_inserts_all_formats.python
#	tests/queries/0_stateless/03251_insert_sparse_all_formats.sh
…s` in the `Puffin` output format

Apache Iceberg always writes `-1`, `-1` and `[2147483645]` (the `_pos` metadata column id) into the
blob metadata of deletion vectors, so the settings `output_format_puffin_snapshot_id`,
`output_format_puffin_sequence_number` and `output_format_puffin_field_ids` are removed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…d `fields` in the `Puffin` output format"

This reverts commit 0e10e18.
@scanhex12
scanhex12 requested a review from groeneai November 13, 2026 12:09
@murphy-4o murphy-4o self-assigned this Nov 13, 2026

@groeneai groeneai left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I checked the writer against the Puffin spec with this PR's CI amd_binary build of 84177c5: the file magic, the length/magic/CRC envelope, the portable roaring layout with unsigned key order and the footer trailer all match it, and the CI integration test shows Iceberg reads the result. 100M positions take about 1 s to write, so nothing on performance. Two design points inline, both about the threads @ asya-ch opened.

Comment thread src/Core/FormatFactorySettings.h Resolved
@clickhouse-gh

clickhouse-gh Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 0f6197bc9 with master 8a35900e2 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

⚠️ Significant changes: object file sizes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Object file sizes ⚠️

511 object files changed (+2.06 MiB total), 8 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Processors/Formats/Impl/Puffin/PuffinBlockInputFormat.cpp.o new 716.38 KiB +716.38 KiB
src/CMakeFiles/dbms.dir/Processors/Formats/Impl/Puffin/PuffinThetaSketch.cpp.o new 221.89 KiB +221.89 KiB
src/CMakeFiles/dbms.dir/Processors/Formats/Impl/Puffin/PuffinCommon.cpp.o new 178.15 KiB +178.15 KiB
src/CMakeFiles/dbms.dir/Processors/Formats/Impl/Puffin/PuffinWriter.cpp.o new 168.04 KiB +168.04 KiB
src/CMakeFiles/dbms.dir/Processors/Formats/Impl/Puffin/PuffinDeletionVector.cpp.o new 124.54 KiB +124.54 KiB
src/CMakeFiles/dbms.dir/Processors/Formats/Impl/Puffin/PuffinBlobBuilder.cpp.o new 123.54 KiB +123.54 KiB
src/CMakeFiles/dbms.dir/Processors/Formats/Impl/Puffin/PuffinBlockOutputFormat.cpp.o new 92.46 KiB +92.46 KiB
src/CMakeFiles/dbms.dir/Processors/Formats/Impl/Puffin/PuffinReader.cpp.o new 60.60 KiB +60.60 KiB
src/Functions/CMakeFiles/clickhouse_functions_obj.dir/FunctionsNumericIndexedVector.cpp.o 18.10 MiB 18.12 MiB +17.41 KiB (+0.09%)

712 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

813 translation units recompiled, 7836 s compile time in total, 805 of them have a recent master baseline.

Translation units without a recent master baseline:

  • src/Processors/Formats/Impl/Puffin/PuffinBlockInputFormat.cpp: 7.5 s

Job report

Comment thread src/Core/FormatFactorySettings.h Resolved
Comment thread src/Core/FormatFactorySettings.h Resolved
Address the review of the `Puffin` output format:
- `PuffinWriter` writes the Puffin container independently of the blob type, with a dynamic list of blobs; `PuffinBlob` moved to `PuffinCommon.h` together with the `apache-datasketches-theta-v1` blob type.
- `PuffinDeletionVector` serializes `deletion-vector-v1` blobs from `roaring::Roaring64Map` and fills their metadata the way Apache Iceberg does.
- The output format takes the same `(referenced_data_file, deleted_rows)` columns as the input format and writes one blob per referenced data file, so Puffin files with several deletion vectors can be copied.
- Remove the `output_format_puffin_referenced_data_file`, `output_format_puffin_snapshot_id`, `output_format_puffin_sequence_number` and `output_format_puffin_field_ids` settings: the data file is an input column and the rest are constants for deletion vectors.

Related: #121982

Co-Authored-By: Claude Opus 5.5 <[email protected]>
scanhex12 and others added 11 commits November 16, 2026 10:18
…ormat

With `output_format_puffin_blob_type = 'apache-datasketches-theta-v1'` every
input column becomes one Theta sketch blob with the `ndv` property, the way
Iceberg writes column statistics. Values are fed to the sketch in the Iceberg
single-value serialization, `NULL`s and empty values are skipped, and the result
goes through a `theta_union` like Iceberg's merge. Field ids, snapshot id and
sequence number come from `output_format_puffin_field_ids`,
`output_format_puffin_snapshot_id` and `output_format_puffin_sequence_number`.

`PuffinMetadata` now accepts Theta sketch blobs (the `ndv` property is
required), and `Puffin` skips them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
`PuffinBlockOutputFormat` now only forwards chunks to a builder chosen by
`createPuffinBlobBuilder` from `output_format_puffin_blob_type`.
`PuffinDeletionVectorBuilder` and `PuffinThetaSketchBuilder` own header
validation, accumulation, serialization and blob metadata of their blob type.
No change in behavior or in the written files.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Builder headers now only declare `createPuffinDeletionVectorBuilder` and
`createPuffinThetaSketchBuilder`; the classes live in the source files. This
keeps CRoaring and DataSketches headers apart: the `IS_BIG_ENDIAN` macro of
CRoaring broke an enum in `theta_sketch.hpp`. Also add the missing
`Columns/ColumnsDateTime.h` include.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Java DataSketches stores the sampling probability `p = 1.0` in bytes 12-15 of a
compact sketch, while the C++ library leaves them zero. Write it the Java way, so
that in exact mode the blobs are byte-identical to the ones written by Iceberg's
`compute_table_stats` in Spark. Checked locally against Iceberg 1.10 for
`boolean`, `int`, `long`, `float`, `double`, `date`, `timestamp`, `string`,
`decimal` and `binary` columns: all exact-mode sketches are byte-identical, and
estimation-mode `ndv` differs by at most 0.02% (Iceberg builds Alpha sketches,
the C++ library has only QuickSelect ones).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…tics writes

Prepares the ground for #131249,
which writes NDV statistics on Iceberg commits:

- `PuffinColumnThetaSketch` is the Theta sketch of one column, with the hashing
  of that PR: values are cast to a type whose `getDataAt` bytes are the Iceberg
  single-value serialization (decimals and `UUID` are encoded explicitly) and
  hashed with the new `IColumn::computeMurmurHash3Into` straight into the hash
  table of an `update_theta_sketch`. The result goes through a `theta_union` and
  gets `p = 1.0`, so it stays byte-identical to Iceberg's sketches. The
  `Puffin` output format and Iceberg statistics writes can both build on it.
- `PuffinBlob::toJSON` and `PuffinReader` (footer, blobs on demand, `zstd` and
  `lz4` blobs) from that PR.
- Blobs of unknown types are listed by `PuffinMetadata` and skipped by `Puffin`,
  as the Puffin specification requires, instead of failing the read.

Related: #131249

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…update_theta_sketch`

The batch hash only saved a virtual `getDataAt` call per row, at the cost of a
new `IColumn` method used in one place and a CMake workaround for the two
`MurmurHash3.h` headers. The values are still encoded as before (a cast to a
type whose `getDataAt` bytes are the Iceberg single-value serialization, and
explicit encoding of decimals and `UUID`), but each value now goes to
`update_theta_sketch::update`, which computes the same hash. This also removes
the direct use of DataSketches internals (`theta_update_sketch_base`). The
written sketches do not change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…dy and style

- Build `PuffinThetaSketchBuilder` and its helpers only with DataSketches: in the
  fast test build it was an unused class (`-Wunused-member-function`).
- Mark const getters `[[nodiscard]]` (`modernize-use-nodiscard`).
- Use `VectorWithMemoryTracking` and `UnorderedSetWithMemoryTracking` for the
  field ids.

https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=121982&sha=7ccc69308b7c7cf5b1aafd1b71b633d222439f1a&name_0=PR
PR: #121982

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…t independent references

The Puffin specification makes `properties` and the `ndv` property of `apache-datasketches-theta-v1`
blobs optional, so `ndv` is validated only when present. Before, such a blob also made `Puffin` fail
to read the deletion vectors of the same file.

`05813_puffin_theta_sketch_reference_hashes` compares the hashes stored in the written sketches with
the ones computed by `data_puffin/generate_theta_reference_hashes.py`, which encodes the values with the
Iceberg single-value serialization and hashes them as Apache DataSketches does, without ClickHouse.

Related: #121982

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@murphy-4o murphy-4o left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, please check these comments and fix ai review

scanhex12 and others added 3 commits November 17, 2026 12:49
…tor positions, fix clang-tidy

- Writing `apache-datasketches-theta-v1` blobs now requires `output_format_puffin_field_ids`,
  `output_format_puffin_snapshot_id` and `output_format_puffin_sequence_number`: default field ids
  1..n and snapshot id -1 produce statistics that readers accept but attach to wrong columns or skip.
- Deletion vector positions are added per run of rows with the same data file through
  `Roaring64Map::addMany` from the typed column, instead of `getUInt`/`add` per position.
- Rename `IPuffinBlobBuilder::reset` to `clear` (`readability-ambiguous-smartptr-reset-call`).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Remove `output_format_puffin_blob_type`, `output_format_puffin_field_ids`,
`output_format_puffin_snapshot_id` and `output_format_puffin_sequence_number`.
The `Puffin` output format writes deletion vectors only; the Theta sketch builder
takes the field ids, the snapshot id and the sequence number in
`PuffinThetaSketchBlobOptions` from its caller, the Iceberg statistics writer.
The tests that wrote Theta sketches through the format settings are removed.

Write single deleted positions with `Roaring64Map::add`, `addMany` is slower for one value.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…uilder as a struct

Bring back `output_format_puffin_blob_type`, `output_format_puffin_field_ids`,
`output_format_puffin_snapshot_id`, `output_format_puffin_sequence_number`, the format
docs and the Theta tests removed in the previous commit. The settings are parsed once
in `createPuffinBlobBuilder` into `PuffinThetaSketchBlobOptions`, which the Theta sketch
builder takes instead of `FormatSettings`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@scanhex12
scanhex12 enabled auto-merge November 17, 2026 14:26
@scanhex12
scanhex12 disabled auto-merge November 17, 2026 17:54
@scanhex12
scanhex12 added this pull request to the merge queue Nov 17, 2026
Merged via the queue into master with commit d283713 Nov 17, 2026
193 checks passed
@scanhex12
scanhex12 deleted the puffin_output branch November 17, 2026 20:28
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 17, 2026
murphy-4o added a commit to murphy-4o/ClickHouse that referenced this pull request Nov 18, 2026
Use master's Puffin layer (ClickHouse#121982) instead of PuffinFile.{h,cpp}.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-formats Input/output formats (CSV/JSON/Parquet/ORC/Arrow/Protobuf/etc.). pr-feature Pull request with new product feature pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants