You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by "HaoXuAI (via GitHub)" <gi...@apache.org> on 2026/07/15 22:59:12 UTC
[PR] Core: Add streaming reader for snapshots in table metadata [iceberg]
HaoXuAI opened a new pull request, #17219:
URL: https://github.com/apache/iceberg/pull/17219
### What
Adds `SnapshotParser.fromJson(InputFile)`, which streams the `snapshots` array of a table metadata JSON document and yields one `Snapshot` at a time instead of materializing the whole list.
### Why
`TableMetadataParser` parses the entire document into memory and builds every `Snapshot` in the `snapshots` array. For tables with very large snapshot histories this dominates heap usage even when a consumer only needs to walk snapshots (e.g. by id, timestamp, or manifest-list location). The streaming reader keeps a single snapshot in memory at a time.
### Notes
- The returned `CloseableIterable` opens a fresh stream on each iteration and must be closed by the caller.
- Returns an empty iterable when the document has no `snapshots` array.
- No spec or public-type changes; reuses the existing snapshot parsing.
### Testing
- Adds `TestSnapshotStreamParser` covering ordering, snapshot-field fidelity, re-iteration, and the missing/empty `snapshots` array cases.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Add streaming reader for snapshots in table metadata [iceberg]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] closed pull request #17219: Core: Add streaming reader for snapshots in table metadata
URL: https://github.com/apache/iceberg/pull/17219
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Add streaming reader for snapshots in table metadata [iceberg]
Posted by "gaborkaszab (via GitHub)" <gi...@apache.org>.
gaborkaszab commented on PR #17219:
URL: https://github.com/apache/iceberg/pull/17219#issuecomment-5020603789
Thank you for getting back, @HaoXuAI !
The reason I asked about the usage is that I'd like to understand the following: When constructing a `TableMetadata` object we are expected to pass a list of `Snapshot`s to the constructor where we then create a snapshot ID to snapshot object mapping. So we are expected to hold a full list of snapshots, so I'm not entirely sure where the streaming approach helps us.
Exception from the above could be when using REST catalog with `snapshotMode=REFS` that loads only the referenced snapshots (including the current one). Also wanted to ask, if this solution is sufficient for you.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Add streaming reader for snapshots in table metadata [iceberg]
Posted by "HaoXuAI (via GitHub)" <gi...@apache.org>.
HaoXuAI commented on PR #17219:
URL: https://github.com/apache/iceberg/pull/17219#issuecomment-5026982832
You're right — a full `TableMetadata` always materializes the snapshot list and the id→snapshot index, so this doesn't help any path that builds one; `snapshot-loading-mode=refs` is the existing lever there.
What this targets is a library/tooling case: reading a table's **full** snapshot history *without* building a `TableMetadata`. The pattern is:
- load with `snapshot-loading-mode=refs`, so `TableMetadata` holds only referenced snapshots while `metadataLocation()` still points to the complete `metadata.json`;
- then stream that file with `SnapshotParser.fromJson(InputFile)` to walk the full history one snapshot at a time (filtering by id / timestamp / manifest-list), never calling `snapshots()` and never firing the supplier.
We use this in a metrics pipeline that scans snapshot histories across many tables — on deep-history tables the eager materialization was the dominant heap cost. Measured on a metadata document with 200k snapshots: **~49 MB retained (eager) vs ~1 MB (streaming)**; under `-Xmx128m` the eager read OOMs where streaming completes under `-Xmx64m`. Full-scan read time is comparable (streaming is slightly faster, skipping the intermediate JSON tree).
So it's meant as a companion to REFS mode for out-of-`TableMetadata` history reads, not a change to how `TableMetadata` loads. If you feel it fits better as a `Table`/`SnapshotUtil`-level accessor (using the table's `FileIO`) than a `SnapshotParser` method, I'm glad to reshape it — or close it if it's too niche for core. Wanted your read before going further.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Add streaming reader for snapshots in table metadata [iceberg]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #17219:
URL: https://github.com/apache/iceberg/pull/17219#issuecomment-5975251931
This pull request has been closed due to lack of activity. This is not a judgement on the merit of the PR in any way. It is just a way of keeping the PR queue manageable. If you think that is incorrect, or the pull request requires review, you can revive the PR at any time.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Add streaming reader for snapshots in table metadata [iceberg]
Posted by "gaborkaszab (via GitHub)" <gi...@apache.org>.
gaborkaszab commented on PR #17219:
URL: https://github.com/apache/iceberg/pull/17219#issuecomment-5031538042
Thanks you for the explanation, @HaoXuAI !
I personally feel, that we can't really find usage for such a functionality within the Iceberg library itself ATM. As you described you use this approach in one of your systems to get some snapshot metrics without forcing to load the full snapshot list into `TableMetadata`. However, that usage is not within the library but within some external metrics gathering system.
If we can't find any meaningful usage that is not external, I'm leaning towards not introducing further complexity and additional code to maintain TBH.
Let's wait if anyone else has a different opinion here.
Additional remark: you mentioned measurement with 200k snapshots. I think that's an extremely high number. In my experience, you probably want to expire snapshots when you have a couple of thousands not tens or hundreds of thousands.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Add streaming reader for snapshots in table metadata [iceberg]
Posted by "JasNeil (via GitHub)" <gi...@apache.org>.
JasNeil commented on PR #17219:
URL: https://github.com/apache/iceberg/pull/17219#issuecomment-5434132959
+1
Have a similar pain point with loading all snapshots at once. And as a downstream reader, I cannot ask the owner to simply expire snapshots.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Add streaming reader for snapshots in table metadata [iceberg]
Posted by "HaoXuAI (via GitHub)" <gi...@apache.org>.
HaoXuAI commented on PR #17219:
URL: https://github.com/apache/iceberg/pull/17219#issuecomment-5326396698
Sure.
But this is a chicken and eggs problem. I need to collect the metric to convince the team to do expiring the snapshots.
And hopefully this can resolve it and some other people run into similar situation.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Add streaming reader for snapshots in table metadata [iceberg]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #17219:
URL: https://github.com/apache/iceberg/pull/17219#issuecomment-5851282183
This pull request has been marked as stale due to 30 days of inactivity. It will be closed in 1 week if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the dev@iceberg.apache.org list. Thank you for your contributions.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Add streaming reader for snapshots in table metadata [iceberg]
Posted by "gaborkaszab (via GitHub)" <gi...@apache.org>.
gaborkaszab commented on PR #17219:
URL: https://github.com/apache/iceberg/pull/17219#issuecomment-4990682484
Hi @HaoXuAI ,
As I see the new functionality is not wired in to `TableMetada`/`TableMetadataParser`. It's not entirely clear how this is going to be used.
Random questions:
- I assume this new parser opens a file descriptor to the json input file, one per TableMetadata, and keeps them open until the TableMetadata object is destroyed. If we cache tables does this means we keep the file descriptors open for forever?
- For operations that need all the snapshots, like expire snapshots, does this design do 1000 IO to read 1000 snapshots?
- This is meant to be an enhancement for memory usage. Would be nice to see numbers what is the order of magnitude we gain here. Also this comes with a tradeoff, would be nice to see what is the read overhead based on the different use cases.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Add streaming reader for snapshots in table metadata [iceberg]
Posted by "HaoXuAI (via GitHub)" <gi...@apache.org>.
HaoXuAI commented on PR #17219:
URL: https://github.com/apache/iceberg/pull/17219#issuecomment-4997377772
Thanks for the review! Let me address each point.
**How it's used / not wired into `TableMetadataParser`.** Intentional for this PR — it's a standalone reader so it can be adopted incrementally. The intended integration is to let `TableMetadataParser.read` install a streaming-backed `snapshotsSupplier`, so `loadTable` paths that never call `snapshots()` skip materializing the array entirely. I kept that out of this PR to land the reader first; happy to follow up with the integration if you're open to the direction.
**File descriptors.** The returned `CloseableIterable` isn't attached to a `TableMetadata` and holds nothing for a table's lifetime. Each iteration opens a fresh stream and closes it on exhaustion or `close()`, so caching a table keeps no descriptor open.
**1 IO per snapshot?** No — it makes a single pass over the one `metadata.json` and yields every snapshot from it (1 read, not N). For operations that genuinely need all snapshots (e.g. expire), it does equivalent work to the eager path; the win is for consumers that need only a subset.
**Numbers.** Measured on a `metadata.json` with 200k snapshots (39 MB); read time from a JMH benchmark, heap from a fixed-`-Xmx` probe:
| Metric | Eager `TableMetadataParser.read` | Streaming `SnapshotParser.fromJson` |
| --- | --- | --- |
| Peak retained heap (200k) | 49 MB | 1 MB |
| Min heap to complete (200k) | OOM at `-Xmx128m` | completes at `-Xmx64m` |
| Full read, 100k snapshots | ~79 ms | ~53 ms |
| Subset lookup, 100k snapshots | loads all first | ~25 ms |
So there's no read-overhead tradeoff for the full-scan case (streaming is if anything slightly faster, since it skips the intermediate JSON tree and the snapshot list), and a large memory saving plus faster subset access.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org