Repository navigation
Cherry pick #112414 to 26.3: Write per-file statistics into Iceberg manifest entries on INSERT - #119455
Cherry pick #112414 to 26.3: Write per-file statistics into Iceberg manifest entries on INSERT#119455robot-ch-test-poll2 wants to merge 7 commits into
Conversation
An INSERT that produced more than one data file per partition wrote the manifest-wide aggregate column statistics into every `data_file` entry of that manifest, so `null_value_counts`, `column_sizes`, `lower_bounds` and `upper_bounds` described the union of all files instead of the file the entry points at. The values were not merely imprecise but impossible and non-conservative: with one row per data file, each one-row entry reported `null_value_counts = 2` for a table holding two NULLs in total, and `column_sizes` were inflated by the file count. The Iceberg pruning rule `null_count == record_count` implies the column is all-NULL in that file, so an external reader evaluating `score = 10` or `score IS NOT NULL` skipped every file and returned no rows for data that was present. ClickHouse's own reader never prunes on `null_value_counts`, which is why ClickHouse-only round trips stayed correct and this went unnoticed. `MultipleFileWriter` already computed the correct per-file statistics and kept them in lockstep with the per-file row and byte counts; the sink discarded them and passed only `getResultStatistics`, so `generateManifestFile` fell into its file-index-independent branch and stamped one set of values inside the per-file loop. The fix is applied at that discard point: a defaulted per-file parameter the sink populates, selected inside the existing type-aware branch. The same serialization path runs, on true values rather than impossible ones. A size mismatch between the per-file statistics and the data files throws `LOGICAL_ERROR` rather than falling back to the aggregate, so a release build cannot silently publish mis-paired metadata. A `chassert` would compile out. Bounds become tighter, which is strictly more accurate and allows more pruning. The Avro schema is unchanged, existing manifests are never rewritten, no setting is added, and all existing callers are byte-unchanged because the new parameter defaults to null. `value_counts` is still not emitted (#103168). Co-Authored-By: Claude Fable 5 <[email protected]>
The pairing of per-file statistics to data files is a bare index, so a permutation of the statistics relative to `data_file_names` would attach one file's `null_value_counts` to another file's entry. That is the same non-conservative metadata the fix removes: an entry can then report `null_count == record_count` for a file that holds a matching row, and a spec-conforming external reader prunes it. Every assertion the test had was invariant under such a permutation. They were sorted multisets over `(record_count, null_value_counts[k])`, a cross-table `max(column_sizes)` inequality, or a read of the table data that was never joined to any entry's `file_path`. Reversing the per-file vector left the reference byte-identical. Two scenarios now read the manifest at the Avro level and join each entry to the Parquet file its `file_path` names. The first compares the entry's `record_count` and `null_value_counts` against that file's real row and null counts and emits a per-entry verdict ordered by the file's own `id`, so a permutation moves the output. The second uses a table with no nullable column, where every entry carries bounds, and requires each entry's decoded `lower_bounds` and `upper_bounds` to equal the single row its own file holds. Reversing the per-file vector now reddens only these two scenarios while every pre-existing assertion stays byte-identical, which is what pins the pairing contract rather than a multiset. The scenarios also document the bounds behaviour in both directions. An entry whose nullable column is entirely NULL legitimately carries no bounds at all, because `canWriteStatistics` is all-or-nothing across an entry's columns and `ColumnNullable::getExtremes` yields NULL extremes that `canDumpIcebergStats` rejects. Writing per-file statistics therefore gains an upper bound on the bounded file and drops the union's lower bound on the all-NULL ones. Conservative in both directions, and now frozen in the reference rather than rediscoverable as a regression. Bounds are held as raw little-endian bytes, decoded here with `reinterpretAsInt32`. No metadata is fabricated, both new tables are scoped to the test database, and the test stays parallel-safe. Co-Authored-By: Claude Fable 5 <[email protected]>
The pairing of per-file statistics to data files is a bare index that governs all four statistics at once, and `column_sizes` is one of the values this change makes describe a single data file. It was the only one no assertion could catch a mis-pairing of. Its one assertion compared the largest per-file size against the largest whole-manifest size, which detects the aggregate fallback but constrains no individual entry. The per-entry cross-checks projected `record_count`, `null_value_counts` and the bounds, but not `column_sizes`. Both of their fixtures also give every data file the same per-file sizes, four bytes for a one-row `Int32` and five for a one-row `Nullable(Int32)`, so reversing the per-file vector could not move a size value there. A third scenario gives each data file a `String` of a different width, which makes each entry's size distinct, and joins every entry to the Parquet file its `file_path` names. Reversing the per-file vector now attaches the twelve-byte file's twenty-byte size to the four-byte file's entry, and dropping the fix restores the manifest-wide forty-eight bytes on all three entries, which is the sum of the three per-file values. The frozen counts are in-memory `IColumn::byteSize` sums rather than Parquet file sizes, so they do not depend on the encoding, the compression codec or the build flavour. For a one-row `String` the value is the character bytes plus one offset, because `insertData` appends exactly the given length with no terminator. Co-Authored-By: Claude Fable 5 <[email protected]>
…erg-compaction-per-file-stats
Master added `user_defined_snapshot_id` to `generateManifestFile` in the
middle of its parameter list (the compaction manifest-lineage work). The
INSERT sink passes the trailing optional arguments positionally, so after
merging master its `/*data_file_formats=*/{}` bound to the new parameter
and every later argument shifted by one, ending in a hard compile error:
error: no matching function for call to 'generateManifestFile'
note: no known conversion from 'std::nullptr_t' to
'const std::vector<DataFileEntryLineage>' for 21st argument
The merge itself was textually clean, so this only appears at build time.
Pass the new parameter explicitly, matching the argument spelling the
Compaction.cpp and Mutations.cpp callers already use.
Verified on the merged tree: 04652 passes with the fix, and the nullptr
mutation of the per-file statistics argument still reproduces the original
defect (impossible_entries: 3, null_count 2 inside one-row files), so the
regression oracle remains load-bearing. Siblings 04203, 04201 and 04614
are green.
…ile-stats Write per-file statistics into Iceberg manifest entries on INSERT
|
26.3 cannot take this cherry-pick without importing a feature it does not have. #112414 passes the writer's per-file statistics into Resolving the conflicts by taking the incoming side would import that plumbing into a supported release branch under a PR title that names a different fix, so I am not doing it, and hand-writing an equivalent would put Iceberg writer code on 26.3 that never went through master. Whether the plumbing should travel to 26.3 first is your call; without it there is nothing here for me to land. 26.6 has both pieces, so I am taking that one: #119456 gets a two-parent merge against |
Original pull-request #112414
Do not merge this PR manually
This pull-request is a first step of an automated backporting.
It contains changes similar to calling
git cherry-picklocally.If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.
The check results does not matter at this step - you can safely ignore them.
Before you resolve anything
Conflicts are often caused by a prerequisite change that has not been backported yet, rather than by a real divergence. The bot re-tries this cherry-pick against the release branch on every run, so if that is the case here it will merge itself as soon as the prerequisite lands, and you will see a comment saying so. Manual resolution is only needed while the conflict persists.
Troubleshooting
If the conflicts were resolved in a wrong way
If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:
pr-cherrypicklabel from the PRYou also need to check the Original pull-request for
pr-backports-createdlabel, and delete if it's presented thereThe PR source
The PR is created in the CI job