Repository navigation
Create system.iceberg_files table - #104415
Conversation
|
Workflow [PR], commit [cff2dd4] Summary: ❌
AI ReviewSummaryThis PR adds Findings❌ Blockers
💡 Nits
Tests
Final VerdictStatus: Minimum required actions: make |
Ergus
left a comment
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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()) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
I'll try to add a per-database and per-table cache, following the pattern in system.tables.
There was a problem hiding this comment.
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.
fa1317d to
9125635
Compare
|
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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
This is improved compared to buffering the whole table, but we still fully materialize one manifest before yielding:
getFilesForManifestreturns astd::vector<IcebergFileRecord>with all entries ofcur.next_manifest_index.process_one_manifestinserts the whole vector.- The
max_block_sizecheck happens only afterprocess_one_manifestreturns.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Rechecking the current code, this still looks live.
process_one_manifest currently does:
getFilesForManifest(...)-> builds a fullstd::vector<IcebergFileRecord>for the whole manifest.- Inserts every row from that vector.
- Only then checks
max_block_sizeingenerate.
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?
There was a problem hiding this comment.
I am aware it is still live. It is out of scope for this PR.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
|
Please support thanks |
Ergus
left a comment
There was a problem hiding this comment.
The getFilesForManifest concern is still valid, but I agree it is out of scope.
|
📊 Cloud Performance Report ✅ AI verdict: 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. clickbenchFlagged queries (9 of 43)
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
|
|
|
||
| try | ||
| { | ||
| auto * iceberg_metadata = dynamic_cast<IcebergMetadata *>(object_storage_table->getExternalMetadata(context_copy)); |
There was a problem hiding this comment.
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.
|
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. |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered by tests: 302/332 (90.96%) | Lost baseline coverage: none · Uncovered code |
|
We only need to backport to 26.4, closing backports to earlier versions. |
|
Why do we backport the feature? |
Backport #104415 to 26.5: Create system.iceberg_files table
|
@scanhex12, I'll send you the info offline. It's for an internal project. |
Changelog category (leave one):
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
Version info
26.6.1.614(included in26.6and later)26.5.8.4