Skip to content

Create system.iceberg_files table - #104415

Merged
asya-ch merged 24 commits into
masterfrom
asya/iceberg_files
Jun 10, 2026
Merged

asya-ch merged 24 commits into
masterfrom
asya/iceberg_files

Conversation

@asya-ch

@asya-ch asya-ch commented May 8, 2026 •

Copy link
Copy Markdown
Collaborator

Changelog category (leave one):

  • New Feature

Changelog entry (a [user-readable short description] :

Added a new system table system.iceberg_files exposing per-file metadata for Iceberg tables, with one row per data or delete file in each table's current snapshot. This closes #98777.

Also, serialize format_version in Iceberg writer.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Version info

  • Merged into: 26.6.1.614 (included in 26.6 and later)
  • Backported to: 26.5.8.4

@asya-ch asya-ch added the comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. label May 8, 2026
@CLAassistant

CLAassistant commented May 8, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@clickhouse-gh

clickhouse-gh Bot commented May 8, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [cff2dd4]

Summary: ❌

job_name test_name status info comment
Stateless tests (arm_asan_ubsan, azure, parallel) FAIL
00376_shard_group_uniq_array_of_int_array FAIL cidb IGNORED
01753_mutate_table_predicated_with_table FAIL cidb IGNORED
02346_text_index_partially_materialized FAIL cidb IGNORED
02187_async_inserts_all_formats FAIL cidb IGNORED
02122_parallel_formatting_PrettySpaceNoEscapes FAIL cidb IGNORED
00169_contingency FAIL cidb IGNORED
04033_tpc_ds_q95 FAIL cidb IGNORED
04061_text_index_json_all_values FAIL cidb IGNORED
04229_numeric_indexed_vector_scalar_uint64_overflow FAIL cidb IGNORED
04070_dedup_token_insert_select_mv FAIL cidb IGNORED
13 more test cases not shown
Integration tests (amd_tsan, 1/6) ERROR IGNORED

AI Review

Summary

This PR adds system.iceberg_files to expose data and delete-file metadata for Iceberg tables, plus tests and docs. The feature shape is useful, but the current implementation can still return stale or silently partial results and has unresolved resource-scaling issues, so I would not merge it yet.

Findings

❌ Blockers

  • [src/Storages/System/StorageSystemIcebergFiles.cpp:229] system.iceberg_files promises rows for the current snapshot and explicitly disables use_iceberg_metadata_files_cache, but getExternalMetadata can reuse an existing IcebergMetadata whose persistent_components.metadata_cache was captured by an earlier cached read. With non-zero iceberg_metadata_staleness_ms, getRelevantState can still use the stale latest-metadata cache and return old file rows. Existing inline thread: Create system.iceberg_files table #104415 (comment)
    Suggested fix: force a fresh cache-free IcebergMetadata for this system table, or add/use an API that reads the relevant state and files while bypassing the existing object's cache.
  • [src/Storages/System/StorageSystemIcebergFiles.cpp:197] and [src/Storages/System/StorageSystemIcebergFiles.cpp:248] Query-control and resource-limit exceptions must abort the query, but both catch (...) blocks catch QUERY_WAS_CANCELLED, TIMEOUT_EXCEEDED, MEMORY_LIMIT_EXCEEDED, and similar exceptions, log them as broken metadata, and continue. That can return partial system.iceberg_files data after cancellation or limits. Existing inline threads: Create system.iceberg_files table #104415 (comment) and Create system.iceberg_files table #104415 (comment)
    Suggested fix: catch const Exception & e, rethrow query-control/resource-limit codes, and only downgrade actual per-table metadata or manifest parsing failures.

⚠️ Majors

  • [src/Storages/System/StorageSystemIcebergFiles.cpp:153] and [src/Storages/ObjectStorage/DataLakes/Iceberg/IcebergMetadata.cpp:989] [dismissed by author -- https://github.com/Create system.iceberg_files table #104415#discussion_r3230359910] process_one_manifest still materializes one full std::vector<IcebergFileRecord> per manifest and checks the chunk boundary only after the whole manifest is inserted. A single large manifest can still force high peak memory and emit an oversized chunk; the implementation reduced the failure mode from table-size to manifest-size, but did not remove it.
    Suggested fix: stream entries within a manifest via an iterator/callback API or keep per-manifest cursor progress so row production can stop near the block boundary.
  • [src/Storages/System/StorageSystemIcebergFiles.cpp:316] When USE_AVRO=0, generate still walks every selected database/table before returning an empty result. Since that build cannot read Iceberg metadata anyway, system.iceberg_files is guaranteed empty and the query cost should not scale with catalog size. Existing inline thread: Create system.iceberg_files table #104415 (comment)
    Suggested fix: short-circuit before constructing or advancing table iterators in non-USE_AVRO builds.

💡 Nits

  • [docs/en/operations/system-tables/iceberg_files.md:2] [dismissed by author -- https://github.com/Create system.iceberg_files table #104415#discussion_r3314137071] The new docs file is still missing the required sidebar_label and sidebar_position frontmatter fields.
    Suggested fix: add those fields, for example sidebar_label: 'system.iceberg_files' and an appropriate sidebar_position.
Tests
  • ⚠️ Add focused coverage for the stale-cache path: read an Iceberg table with metadata cache/staleness enabled, advance the table metadata, then query system.iceberg_files and verify it reports the latest snapshot's files.
  • ⚠️ Add a cancellation/limit regression for system.iceberg_files if practical, or factor the exception filtering into a helper with direct coverage.
Final Verdict

Status: ⚠️ Request changes

Minimum required actions: make system.iceberg_files reliably bypass stale Iceberg metadata cache state, and rethrow query-control/resource-limit exceptions instead of returning partial results. The non-USE_AVRO catalog scan should also be addressed; the manifest-buffering and docs-frontmatter points remain live even though the author dismissed them.

@clickhouse-gh clickhouse-gh Bot added the pr-feature Pull request with new product feature label May 8, 2026
@Ergus Ergus self-assigned this May 9, 2026

@Ergus Ergus 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.

Please fix the per-row partial-insertion on exception (or explicitly accept it as a known issue carried over from iceberg_history).

Mention the fix in IcebergWrites.cpp as part of the PR description (for changelog) or add it in a different PR with it's tests.

The comment avout the poredicate pushdown would be very nice to have in order to prevent future issues.

{
IcebergMetadata::IcebergFiles files = iceberg_metadata->getFiles(context_copy);

for (auto & file : files)

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 for is inside a try-catch inside a lambda. If any of the per-column insertions call throws after column_index has been advanced the next iteration on a different table will then missalign rows for the rest of the query.

(I know a pattern like this already exists in code like StorageSystemIcebergHistory.cpp, but better if we can avoid that)

Just copy column_index of every column before the row, and on exception roll back any columns whose size grew.

auto databases = DatabaseCatalog::instance().getDatabases(GetDatabasesOptions{.with_datalake_catalogs = true});
for (const auto & db : databases)
{
for (auto iterator = db.second->getTablesIterator(context_copy, {}, true); iterator->isValid(); 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.

IIUC the predicate arguments in fillColumn above are ignored. For simpler system tables that's fine, however, in this case that means that we are not filtering table names at all at this point in getTablesIterator.

So if a user makes a SELECT ... WHERE database = 'foo' AND table = 'bar'... is only applied later by the SQL engine, after fillData has already produced rows for every Iceberg table in every database.

This means that add_file_records will be called for every single table and that is in general expensive because it implies a metadata reflesh (configuration->update(object_storage, query_context)) for each of them even if they will be filtered out latter.

system.iceberg_history has the same gap, but the per-table cost is just metadata.json annd no manifest traversal.

For example:
Imagine a deployment with 200 Iceberg tables (each ~50 manifest files) plus 50 Delta tables. A user runs:

SELECT * FROM system.iceberg_files
WHERE database = 'analytics' AND table = 'events'

The user asked for one table; the server did the work for 200. And because the cache is disabled, repeating the query does not amortize.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I'll try to add a per-database and per-table cache, following the pattern in system.tables.

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.

I could be wrong, but I think that using the ignored predicates arguments it will be simpler and enough for this use case. Just skipping the non-matching tables is simple and typical pattern.

@scanhex12 scanhex12 self-assigned this May 10, 2026
@asya-ch
asya-ch force-pushed the asya/iceberg_files branch from fa1317d to 9125635 Compare May 12, 2026 22:12
@Ergus

Ergus commented May 12, 2026 •

Copy link
Copy Markdown
Member

Hi @asya-ch

Please avoid rebassing after a review started ;). It is simpler to see what changed since the last review. To get master changes just merge master. I know history looks ugly then... but we learn to live with it ;p

{
if (IcebergMetadata * iceberg_metadata = dynamic_cast<IcebergMetadata *>(object_storage->getExternalMetadata(context_copy)); iceberg_metadata)
{
IcebergMetadata::IcebergFiles files = iceberg_metadata->getFiles(context_copy);

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.

getFiles materializes all file records of a table into a std::vector before SystemIcebergFilesSource::generate can stop by max_block_size.

For large Iceberg tables this can allocate very large memory and still produce an oversized chunk in one go, which defeats the streaming design.

Can we stream manifest entries directly to output columns (or via a callback/iterator API) so row production can stop near max_block_size without buffering the entire table?

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.

This is improved compared to buffering the whole table, but we still fully materialize one manifest before yielding:

  • getFilesForManifest returns a std::vector<IcebergFileRecord> with all entries of cur.next_manifest_index.
  • process_one_manifest inserts the whole vector.
  • The max_block_size check happens only after process_one_manifest returns.

So if a single manifest is large, we can still allocate a large temporary vector and emit an oversized chunk in one generate call. That keeps the same failure mode (OOM / very large chunks), just at manifest granularity instead of table granularity.

Can we stream within a manifest too (e.g., iterator/callback API from metadata layer, or keep per-manifest progress in TableCursor) so we can stop near max_block_size without full-manifest buffering?

@asya-ch asya-ch May 14, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I think this is OK for now. We already have several calls to getManifestFileEntriesHandle() which parse and keep in-memory data for entire manifest files.

If someone has particularly huge manifest files, and this causes issues for them, we can consider implementing buffered reading from manifest files.

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.

I still think this is live in the current code path.

process_one_manifest calls getFilesForManifest, which materializes a full std::vector<IcebergFileRecord> for cur.next_manifest_index, and only after that returns do we check max_block_size.

So for a large manifest we can still accumulate very large memory in one generate call (parsed manifest entries + full IcebergFileRecord vector + output columns) and emit an oversized chunk.

Could we avoid the extra full-manifest vector and insert incrementally (iterator/callback), so we can stop near the block limit within a manifest?

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.

Rechecking the current code, this still looks live.

process_one_manifest currently does:

  1. getFilesForManifest(...) -> builds a full std::vector<IcebergFileRecord> for the whole manifest.
  2. Inserts every row from that vector.
  3. Only then checks max_block_size in generate.

So for a large manifest we still need memory for all converted rows at once and can emit an oversized chunk in one call. The earlier table-level buffering issue is reduced to manifest-level buffering, but the same failure mode remains.

Could we avoid full-manifest materialization by keeping per-manifest progress in TableCursor (or by exposing an entry iterator/callback from metadata) so generate can stop close to the configured chunk boundary without building an entire manifest result vector?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I am aware it is still live. It is out of scope for this PR.

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.

Rechecking the current implementation, this is still live.

SystemIcebergFilesSource::process_one_manifest still calls getFilesForManifest(...), which builds a full std::vector<IcebergFileRecord> for the entire manifest in IcebergMetadata::getFilesForManifest, and only after that does generate evaluate the max_block_size break condition.

So one large manifest can still force high peak memory (parsed manifest entries + full converted vector + output columns) and can emit an oversized chunk in a single generate call.

Can we stream entries within a manifest (iterator/callback or cursor state that tracks per-manifest progress) so row production can stop near the chunk boundary without full-manifest materialization?

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.

Rechecking the current head (2a6e60fa), this is still live.

SystemIcebergFilesSource::process_one_manifest calls IcebergMetadata::getFilesForManifest, which still builds a full std::vector<IcebergFileRecord> for the whole manifest before row insertion starts. The chunk boundary check (get_total_size() >= max_block_size) runs only after process_one_manifest returns.

So a single large manifest can still force high peak memory (parsed manifest entries + full converted vector + output columns) and can still emit an oversized chunk in one generate iteration.

Could we stream rows within a manifest (iterator/callback or cursor state with per-manifest offset) so generate can stop near chunk boundaries without full-manifest materialization?

@fikadufikaduteasfaye-stack

Copy link
Copy Markdown

Please support thanks

@asya-ch
asya-ch enabled auto-merge May 19, 2026 15:30

@Ergus Ergus 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.

The getFilesForManifest concern is still valid, but I agree it is out of scope.

@clickhouse-gh

clickhouse-gh Bot commented Jun 4, 2026 •

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

✅ AI verdict: no_change — no significant changes across 38 queries analysed

This PR adds the system.iceberg_files table plus a refactor of Iceberg data-lake metadata defaults and a docs fix; it does not change any general query-execution code. The nine flagged ClickBench queries are SELECTs over the standard hits dataset and run none of the modified paths, so the ~6-19% deltas cannot be caused by this change. The slowdowns are uniform across unrelated queries, several have noisy or already-drifting history, and none reach the large-and-clear threshold that would force the call. We've downgraded all nine to not-sure as environment/baseline variance.

clickbench

⚠️ 9 inconclusive

Flagged queries (9 of 43)
Query Verdict Baseline med (ms) PR med (ms) Change q-value Hint
⚠️ 12 not_sure 331 365 +10.3% <0.0001 PR only adds system.iceberg_files + Iceberg metadata refactor; cannot touch this query's path. Trending master drift.
⚠️ 13 not_sure 508 578 +13.8% <0.0001 Iceberg-only change; nothing in this query's execution path is modified. Off-path delta, trending baseline.
⚠️ 14 not_sure 390 430 +10.3% <0.0001 PR adds Iceberg system table only; no general query-path code changed. Off-path delta on a trending query.
⚠️ 16 not_sure 817 924 +13.1% <0.0001 Iceberg metadata/system-table PR; unrelated to this query. History is noisy, so treat as variance.
⚠️ 17 not_sure 570 641 +12.5% <0.0001 No execution-path code touched by this Iceberg-only PR; noisy history. Off-path, downgrade.
⚠️ 18 not_sure 1422 1654 +16.2% <0.0001 Iceberg system-table addition cannot affect this query; noisy history and high run-to-run spread.
⚠️ 32 not_sure 1384 1641 +18.6% <0.0001 PR is Iceberg-only; this query's path is untouched. 18.6% under override threshold, trending baseline.
⚠️ 33 not_sure 1510 1629 +7.9% <0.0001 Iceberg metadata/system-table PR does not touch this query. Off-path delta, no history to trust.
⚠️ 34 not_sure 1513 1602 +5.9% <0.0001 Off-path for an Iceberg-only PR; high source spread. Treat 5.9% as environment variance.

q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on.

tpch_adapted_1_official

🟢 No significant changes

Debug info
  • StressHouse run: c6317769-78e5-48ca-85c6-0da0a09a309e
  • MIRAI run: 0b38c4a4-06ad-482b-8898-92dfdcfc70fd
  • PR check IDs:
    • clickbench_200896_1781121592
    • clickbench_201031_1781121759
    • clickbench_201051_1781121759
    • tpch_adapted_1_official_201071_1781121759
    • tpch_adapted_1_official_201296_1781121792
    • tpch_adapted_1_official_201317_1781121793


try
{
auto * iceberg_metadata = dynamic_cast<IcebergMetadata *>(object_storage_table->getExternalMetadata(context_copy));

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.

This does not reliably disable the Iceberg metadata-files cache. getExternalMetadata calls configuration->update, and DataLakeConfiguration::update reuses an already-initialized IcebergMetadata object when supportsUpdate is true; the cache pointer captured in that object is not rebuilt from this copied context. So after the table has been read once with the default cache settings, system.iceberg_files can still read through the cache here despite line 56 explicitly disabling it for correctness, and with a non-zero iceberg_metadata_staleness_ms it can return stale rows for the promised current snapshot. Please either force a fresh IcebergMetadata without a cache for this system table, or add an API that reads the relevant state/files while bypassing the existing object's cache.

@clickhouse-gh

clickhouse-gh Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Dear @scanhex12, 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 Jun 10, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.70% 84.60% -0.10%
Functions 92.30% 92.30% +0.00%
Branches 77.30% 77.20% -0.10%

Changed lines: Changed C/C++ lines covered by tests: 302/332 (90.96%) | Lost baseline coverage: none · Uncovered code

Full report · Diff report

@asya-ch
asya-ch added this pull request to the merge queue Jun 10, 2026
Merged via the queue into master with commit 38c0979 Jun 10, 2026
323 of 328 checks passed
@asya-ch
asya-ch deleted the asya/iceberg_files branch June 10, 2026 22:14
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Jun 10, 2026
This was referenced Jun 30, 2026
@alesapin alesapin added the pr-must-backport Pull request should be backported intentionally. Use this label with great care! label Aug 19, 2026
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Aug 19, 2026
@asya-ch

asya-ch commented Aug 19, 2026

Copy link
Copy Markdown
Collaborator Author

We only need to backport to 26.4, closing backports to earlier versions.

@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Aug 19, 2026
@scanhex12

Copy link
Copy Markdown
Member

Why do we backport the feature?

asya-ch added a commit that referenced this pull request Aug 19, 2026
Backport #104415 to 26.5: Create system.iceberg_files table
@asya-ch

asya-ch commented Aug 19, 2026 •

Copy link
Copy Markdown
Collaborator Author

@scanhex12, I'll send you the info offline. It's for an internal project.

kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Aug 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-feature Pull request with new product feature pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR 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.

Introduce system.iceberg_files table

9 participants