Skip to content

Rebuild entities in IcebergManifestFile - #98231

Merged
divanik merged 37 commits into
masterfrom
divanik/iceberg_good_abstractions_in_manifedt_file_reader_code
Mar 5, 2026
Merged

divanik merged 37 commits into
masterfrom
divanik/iceberg_good_abstractions_in_manifedt_file_reader_code

Conversation

@divanik

@divanik divanik commented Feb 27, 2026 •

Copy link
Copy Markdown
Contributor

Changelog category (leave one):

  • Improvement

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

Rebuild entities in IcebergManifestFile so code maintaining and enhancing will be less error-prone (also fixes some stuff with manifest file caching).

Preliminary PR before asyncronous Iceberg metadata iteration

Version info

  • Merged into: 26.3.1.419

@divanik
divanik marked this pull request as draft February 27, 2026 15:19
@clickhouse-gh

clickhouse-gh Bot commented Feb 27, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [059e95f]

Summary: ❌

job_name test_name status info comment
Upgrade check (amd_release) failure
Changed settings are not reflected in the settings changes history (see changed_settings.txt) FAIL cidb IGNORED
AST fuzzer (amd_debug) failure
Logical error: Bad cast from type A to B (STID: 3524-340b) FAIL cidb, issue ISSUE CREATED

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Feb 27, 2026
@divanik divanik changed the title Rebuild entities in IcebergManifestFile [[DRAFT]] Rebuild entities in IcebergManifestFile Feb 27, 2026
@divanik divanik added the no-fast-tests Drops preliminary CI jobs: Style, clang-tidy, Fast Test label Feb 27, 2026

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.

Pull request overview

This PR refactors Iceberg manifest handling by splitting “parsed” vs “processed” manifest entities and introducing ManifestFileIterator, with related updates to pruning, caching, and iterators consuming manifest entries (plus an integration-test update for pruning-status logging). The direction looks reasonable, but there are a few correctness/safety issues around metadata parsing and size handling that should be addressed before merge.

Changes:

  • Introduce ManifestFileIterator and new ParsedManifestFileEntry / ProcessedManifestFileEntry entities to rebuild manifest-file processing and enable streaming iteration.
  • Rework Iceberg metadata cache to store a cacheable manifest deserializer payload (ManifestFileCacheableInfo) keyed by manifest path + byte size.
  • Update Iceberg iterators/pruning/compaction paths and adjust integration test expectations for pruning-status logging.

Reviewed changes

Copilot reviewed 20 out of 20 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
tests/integration/test_storage_iceberg_with_spark/test_system_iceberg_metadata.py Updates integration assertions around manifest entry pruning status / row handling.
src/Storages/ObjectStorage/DataLakes/Iceberg/StatelessMetadataFileGetter.h Changes manifest getter API to return cacheable info and adds helper to build a fully-initialized iterator.
src/Storages/ObjectStorage/DataLakes/Iceberg/StatelessMetadataFileGetter.cpp Implements cacheable manifest loading, manifest-list parsing now records manifest byte size, and adds iterator builder that drains entries.
src/Storages/ObjectStorage/DataLakes/Iceberg/PersistentTableComponents.h Adds SchemaProcessor.h include (persistent components reference schema processor).
src/Storages/ObjectStorage/DataLakes/Iceberg/MetadataGenerator.cpp Adds ReadHelpers include (supporting changes elsewhere).
src/Storages/ObjectStorage/DataLakes/Iceberg/ManifestFilesPruning.h Switches pruning to work with ManifestFileIterator and ProcessedManifestFileEntryPtr.
src/Storages/ObjectStorage/DataLakes/Iceberg/ManifestFilesPruning.cpp Updates pruning logic to use entry->hyperrectangles and entry->parsed_entry fields.
src/Storages/ObjectStorage/DataLakes/Iceberg/ManifestFileIterator.h New iterator abstraction that incrementally processes manifest rows, caches results, and supports pruning.
src/Storages/ObjectStorage/DataLakes/Iceberg/ManifestFileIterator.cpp New iterator implementation: per-row processing, schema resolution, pruning, and logging.
src/Storages/ObjectStorage/DataLakes/Iceberg/ManifestFile.h Refactors manifest entities into ParsedManifestFileEntry + ProcessedManifestFileEntry, adds cacheable deserializer info.
src/Storages/ObjectStorage/DataLakes/Iceberg/ManifestFile.cpp Removes old eager ManifestFileContent logic; keeps comparisons and delete-matching diagnostics on processed entries.
src/Storages/ObjectStorage/DataLakes/Iceberg/IcebergMetadataFilesCache.h Changes cache payload to ManifestFileCacheableInfo and extends manifest cache key with byte size for accounting.
src/Storages/ObjectStorage/DataLakes/Iceberg/IcebergMetadata.cpp Switches manifest usage to the new iterator-based accessor for total rows/bytes and sort-order checks.
src/Storages/ObjectStorage/DataLakes/Iceberg/IcebergIterator.h Updates iterator types to use processed manifest entries and shares filter DAG via shared_ptr.
src/Storages/ObjectStorage/DataLakes/Iceberg/IcebergIterator.cpp Streams manifest entries via ManifestFileIterator::next(), sorts delete entries, and uses processed entry fields.
src/Storages/ObjectStorage/DataLakes/Iceberg/IcebergDataObjectInfo.h Updates APIs to accept processed manifest entries and delete objects.
src/Storages/ObjectStorage/DataLakes/Iceberg/IcebergDataObjectInfo.cpp Adapts object-info construction and delete attachment to the new processed entry layout.
src/Storages/ObjectStorage/DataLakes/Iceberg/Compaction.cpp Adapts compaction planning to use iterator handles and processed entry partition keys.
src/Storages/ObjectStorage/DataLakes/Common/AvroForIcebergDeserializer.h Adds caching for parsed manifest entries and declares methods to build them per row.
src/Storages/ObjectStorage/DataLakes/Common/AvroForIcebergDeserializer.cpp Implements parsed manifest entry creation + caching, reads manifest format version from Avro metadata.

#include <Interpreters/ActionsDAG.h>
#include <Storages/ObjectStorage/DataLakes/Iceberg/SchemaProcessor.h>
#include <Storages/ObjectStorage/DataLakes/Iceberg/ManifestFile.h>
#include <Storages/ObjectStorage/DataLakes/Iceberg/ManifestFileIterator.h>

Copilot AI Mar 2, 2026

Copy link

Choose a reason for hiding this comment

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

ManifestFilesPruning.h includes ManifestFileIterator.h, but the header only needs ProcessedManifestFileEntryPtr and a reference to ManifestFileIterator (which is already forward-declared). Including the full iterator header pulls in mutex/atomic/unordered_map and increases rebuild cost. Prefer including ManifestFile.h (for ProcessedManifestFileEntryPtr) and forward-declaring ManifestFileIterator, moving the iterator include to the .cpp if needed.

Suggested change
#include <Storages/ObjectStorage/DataLakes/Iceberg/ManifestFileIterator.h>
#include <Storages/ObjectStorage/DataLakes/Iceberg/ManifestFile.h>

Copilot uses AI. Check for mistakes.
@divanik divanik removed the no-fast-tests Drops preliminary CI jobs: Style, clang-tidy, Fast Test label Mar 2, 2026
Comment on lines +133 to +134
Int64 added_sequence_number;
Int64 snapshot_id;

@divanik divanik Mar 2, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Though these two fields should be the same during all snapshots, I think it is a good idea to logically isolate it from ParsedManifestFileEntry, because they can be inherited from manifest list entry, not parsed.

@divanik
divanik marked this pull request as ready for review March 2, 2026 12:31
@divanik divanik changed the title [[DRAFT]] Rebuild entities in IcebergManifestFile Rebuild entities in IcebergManifestFile Mar 2, 2026
@arsenmuk arsenmuk self-assigned this Mar 2, 2026
const String & common_path,
IcebergSchemaProcessor & schema_processor,
Int64 inherited_sequence_number,
Int64 inherited_snapshot_id,

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.

Sorry for nit picking and asking about the older code. Why are these sequence_num and snapshot_id explicitly named as inherited_? Perhaps to make them flat sequence_number/snapshot_id here, and at ManifestFile.h as well (instead of added_)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Because they were "inherited" from manifest list, not read from manifest file itself. I need to rename it, you are right

parsed_entry, common_partition_specification, file_path, resolved_sequence_number, resolved_snapshot_id, resolved_schema_id);


PruningReturnStatus pruning_status;

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.

are we ok with implicit initialization of this status in case when filter_dag==nullptr?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch, I think it is important


while (iterator->next())
{
}

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.

This is an illustration of abstraction mismatch, we've discussed earlier. We kinda return iterator object from a method called getManifestFileAsIterator. But this Iterator is already iterated until the end in order to have all the entries fetched. So in this context, and where it's been used, it is not actually the iterator, but the good old ManifestFile in a new shape, which has been processed using an iterator.

In my opinion, we mixed several separate abstractions together - ManifestFileIterator (which iterates over entries) and ManifestEntriesFetcher (or even -Prefetcher, as you aimed it for AsyncIterator).

Please take this comment as non-blocking thinking out loud. I wouldn't ask you to reconsider much now, when this PR is almost finished. Let's revise some of these overloaded abstractions at the next iteration of the refactoring.

@divanik
divanik added this pull request to the merge queue Mar 5, 2026
Merged via the queue into master with commit b0db88c Mar 5, 2026
143 of 145 checks passed
@divanik
divanik deleted the divanik/iceberg_good_abstractions_in_manifedt_file_reader_code branch March 5, 2026 10:16
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Mar 5, 2026
/// Compute inherited/resolved fields
const auto file_path = getProperFilePathFromMetadataInfo(parsed_entry->file_path_key, common_path, table_location);

Int64 resolved_snapshot_id;

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.

@divanik resolved_snapshot_id is declared as an uninitialized Int64. In the else if branch at lines 405–411 (reached when parsed_snapshot_id is null and status is EXISTING), it is read uninitialized in the fmt::format call at line 411 — this is undefined behavior.

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.

Fixed here #99038

{
throw Exception(
ErrorCodes::ICEBERG_SPECIFICATION_VIOLATION,
"Cannot read Iceberg table: manifest file '{}' has entry with snapshot_id '{}' for which write file schema is unknown",

@zlareb1 zlareb1 Mar 6, 2026 •

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.

the error message is incorrect — there is no snapshot_id.

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.

Fixed here #99038

zvonand added a commit to Altinity/ClickHouse that referenced this pull request Apr 24, 2026
Removes the `hyperrectangle` field from `DB::Iceberg::ColumnInfo` that
was re-added during the frontport. The field was removed upstream in
PR ClickHouse#98231, which relocated
raw min/max bounds to `ParsedManifestFileEntry::value_bounds`. The
`DataFileMetaInfo` Iceberg constructor now deserializes those bounds via
the shared `deserializeFieldFromBinaryRepr` helper (moved from
`ManifestFileIterator.cpp` to `IcebergFieldParseHelpers`).

Addresses @ianton-ru's comment at #1687 (comment).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-improvement Pull request with some product improvements 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.

5 participants