Support session context binding to catalogs at trait level - #2999
Draft
DerGut wants to merge 6 commits into
Draft
Conversation
Add RestSessionCatalog example Revised comments
DerGut
commented
Aug 14, 2026
| /// # let _ = catalog; | ||
| /// # } | ||
| /// ``` | ||
| pub fn into_catalog(self: Arc<Self>, session: SessionContext) -> Arc<dyn Catalog> { |
Contributor
Author
There was a problem hiding this comment.
into_catalog is close enough to Java's asCatalog while better fitting into Rust's conventional as_, into_, to_ naming where as_catalog would suggest a cheap borrowing conversion.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
This is another part in the chain towards resolving issue #2774 and is based on PR #2920
In a follow-up, I will introduce the
SessionCatalogto theintegrations/datafusioncrate. It will use adyn SessionCatalogsimilar to the existingdyn Catalog.Prevent Duplication of APIs
The purpose of this PR is to break the need to update all
Catalog-based APIs to get aSessionCatalogequivalent. It does so by introducing a conversion fromSessionCatalogtoCatalog.As an example, the
[Transaction::commit](https://github.com/apache/iceberg-rust/blob/a500a2e731ac0f1c9bf43d6613a8dbe08417465f/crates/iceberg/src/transaction/mod.rs#L175)function today takes a&dyn Catalog. To write any data with aSessionCatalog, we'd need to introduce new, duplicate APIs.What changes are included in this PR?
It adds this new implementation for all SessionCatalog's:
where a
SessionBoundCatalogis a private wrapper around an innerSessionCatalogthat adapts it to theCatalogtrait by always providing the same bound session context.RestCatalog
Note, this is basically mirroring what the
RestCatalogimplementation is now doing. It is also a wrapper with an innerSessionCatalogandSessionContext. The reason I'm introducing a separate type here (that is not used by theRestCatalogimplementation) are:SessionCatalogtrait be convertible toCatalog(the Datafusion integration uses traits for its providers, and not concrete catalog implementations)SessionBoundCatalogfor theRestCatalogwe'd need to make itpub. IMO the limited amount of duplication warrants the ability to keep it private for now. Users shouldn't really depend on theSessionBoundCatalog's direct API (beyond itsCatalogtrait implementation), and so the export would only serve to remove some duplication. We can also always change this later without breaking compatibility.Are these changes tested?
This is very similar to the
RestCatalogimplementation. TheSessionBoundCatalogis not adding behavior and the delegation is exercised by the compiler.AI Disclosure
Prototyped different approaches with Codex and Claude. Ended up typing the result by hand.