Skip to content

Spark: [3/N] Support sending referenced-by to all endpoints - #13979

Open
singhpk234 wants to merge 3 commits into
apache:mainfrom
singhpk234:feature/ref-imp-referenced-by
Open

Spark: [3/N] Support sending referenced-by to all endpoints#13979
singhpk234 wants to merge 3 commits into
apache:mainfrom
singhpk234:feature/ref-imp-referenced-by

Conversation

@singhpk234

@singhpk234 singhpk234 commented Sep 3, 2025

Copy link
Copy Markdown
Contributor

About the change

This provides a reference implementation for passing the view name that table is referenced in as part of which the loadTable call is being made.

Details on the spec change proposal and motivation here

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

Thanks for the PR @singhpk234 !
I took a look for my own benefit, and left some observations and questions meanwhile. Let me know what you think!

Comment thread api/src/main/java/org/apache/iceberg/catalog/ContextAwareTableCatalog.java Outdated
Comment thread api/src/main/java/org/apache/iceberg/catalog/ContextAwareCatalog.java Outdated
Comment thread api/src/main/java/org/apache/iceberg/catalog/ContextAwareTableCatalog.java Outdated

@Override
public Table loadTableViaView(TableIdentifier identifier, Map<String, Object> viewContext) {
if (delegate instanceof ContextAwareTableCatalog) {

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.

delegate is a BaseSessionCatalog.AsCatalog that now implements ContextAwareTableCatalog. Is there a use-case or configuration where delegate doesn't implement the new interface?

I see the concept in this class is rather to have a new member of type ContextAwareTableCatalog that is converted from delegate and this new function could directly call that. Similarly as nsCatalog.

Would this also work here? Do I miss something?

Comment thread core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java Outdated
Comment thread core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java Outdated
Comment thread api/src/main/java/org/apache/iceberg/catalog/ContextAwareTableCatalog.java Outdated
Comment thread spark/v4.0/spark/src/main/java/org/apache/iceberg/spark/SparkCatalog.java Outdated
Comment thread api/src/main/java/org/apache/iceberg/catalog/ContextAwareTableCatalog.java Outdated
Comment thread core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java Outdated
Comment thread core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java Outdated
@singhpk234
singhpk234 force-pushed the feature/ref-imp-referenced-by branch 2 times, most recently from 97296ab to bcec3f2 Compare September 8, 2025 00:22
Comment thread api/src/main/java/org/apache/iceberg/catalog/ContextAwareTableCatalog.java Outdated
Comment thread core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java Outdated
@sfc-gh-prsingh
sfc-gh-prsingh force-pushed the feature/ref-imp-referenced-by branch from a34c0f2 to fb6e824 Compare November 3, 2025 12:12
@singhpk234 singhpk234 changed the title Spark, Rest: Reference implementation of referenced-by in the loadTable call [REST | SPARK]: Reference implementation of referenced-by in the loadTable call Nov 3, 2025
@sfc-gh-prsingh
sfc-gh-prsingh force-pushed the feature/ref-imp-referenced-by branch from 20d30b3 to 737fc50 Compare November 3, 2025 12:31
@github-actions

github-actions Bot commented Dec 4, 2025

Copy link
Copy Markdown

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.

@github-actions github-actions Bot added the stale label Dec 4, 2025
@singhpk234 singhpk234 added not-stale and removed stale labels Dec 4, 2025
@sfc-gh-prsingh
sfc-gh-prsingh force-pushed the feature/ref-imp-referenced-by branch 3 times, most recently from f368355 to 57e3e30 Compare January 11, 2026 05:39

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

I went through the api/ and core/ part for now (haven't checked Spark). Left some questions and nits. I also found some of my previous comments so I'm not sure this was ready for review.
Anyway, some test coverage in TestRESTCatalog would be great!

Comment thread api/src/main/java/org/apache/iceberg/catalog/ContextAwareTableCatalog.java Outdated
Comment thread api/src/main/java/org/apache/iceberg/catalog/SessionCatalog.java Outdated
Comment thread core/src/main/java/org/apache/iceberg/catalog/BaseSessionCatalog.java Outdated
Comment thread core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java Outdated
Comment thread core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java Outdated
Comment thread core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java Outdated
Comment thread core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java Outdated
Comment thread core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java Outdated
Comment thread core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java Outdated
@chris922

Copy link
Copy Markdown

Hi all - the Iceberg REST spec was merged 😃 This PR is now the next step in getting this referenced-by feature into the different Iceberg clients, right? Looking forward to get it merged & released

@sfc-gh-prsingh
sfc-gh-prsingh force-pushed the feature/ref-imp-referenced-by branch from 57e3e30 to a300631 Compare February 21, 2026 19:05
@singhpk234 singhpk234 changed the title [REST | SPARK]: Reference implementation of referenced-by in the loadTable call [REST | SPARK]: Reference implementation of referenced-by to all endpoints for DEFINER views Feb 21, 2026
@singhpk234
singhpk234 requested a review from rdblue April 3, 2026 18:51
@sfc-gh-prsingh
sfc-gh-prsingh force-pushed the feature/ref-imp-referenced-by branch 2 times, most recently from 64d8981 to 59258c3 Compare April 7, 2026 17:17
isStreaming,
timeTravelVersion,
timeTravelTimestamp) =>
val referencedBy = ViewUtil.buildReferencedByChain(viewChain, catalog.name())

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'm wondering if it's feasible to use the view UUID as the referenced by instead of the view name identifier? That might address issues around cross catalog access and having the catalog name in the identifier.

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.

I gave it more thought, the thing is catalog don't index things from uuid, all our specification is based on identifiers / name, hence this would be a tricky, do you have any thoughts on server side implementation pov ?

Comment thread core/src/main/java/org/apache/iceberg/rest/RESTUtil.java Outdated
@singhpk234
singhpk234 marked this pull request as draft May 29, 2026 19:46
@singhpk234
singhpk234 marked this pull request as ready for review May 29, 2026 19:47
@sfc-gh-prsingh
sfc-gh-prsingh force-pushed the feature/ref-imp-referenced-by branch from 59258c3 to 32e0455 Compare May 30, 2026 17:17
sfc-gh-prsingh added a commit to singhpk234/iceberg that referenced this pull request Aug 24, 2026
…tualLoad

Addresses review feedback from danielcweeks:
- PR apache#15895: "generalize this to something more like SupportsContextualLoad
  and not make it so narrowly specific to this particular field"
- PR apache#15895: "we should probably be adding some sort of LoadContext as opposed
  to specific parameters that are targeted to this one behavior"
- PR apache#13979: "much prefer specific context objects" over Map<String, Object>

Introduces a typed LoadContext with a builder pattern that can evolve with
new fields (e.g., planId, credentials scope) without requiring new interfaces
or method overloads for each addition.
@sfc-gh-prsingh
sfc-gh-prsingh force-pushed the feature/ref-imp-referenced-by branch from a4de8ca to dfcd362 Compare August 24, 2026 17:13
@singhpk234 singhpk234 changed the title [REST | SPARK]: Send referenced-by to all endpoints Core,Spark: Send referenced-by to all endpoints Aug 24, 2026
sfc-gh-prsingh added a commit to singhpk234/iceberg that referenced this pull request Sep 2, 2026
…tualLoad

Addresses review feedback from danielcweeks:
- PR apache#15895: "generalize this to something more like SupportsContextualLoad
  and not make it so narrowly specific to this particular field"
- PR apache#15895: "we should probably be adding some sort of LoadContext as opposed
  to specific parameters that are targeted to this one behavior"
- PR apache#13979: "much prefer specific context objects" over Map<String, Object>

Introduces a typed LoadContext with a builder pattern that can evolve with
new fields (e.g., planId, credentials scope) without requiring new interfaces
or method overloads for each addition.
@sfc-gh-prsingh
sfc-gh-prsingh force-pushed the feature/ref-imp-referenced-by branch 2 times, most recently from 3472ae0 to 9053739 Compare September 4, 2026 19:07
@github-actions github-actions Bot removed the API label Sep 4, 2026
* the loading contract to accept a {@link LoadContext} that carries the view reference chain and
* other contextual information.
*/
public interface SparkSupportsContextualLoad {

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.

will this be renamed to SparkSupportsLoadContext instead?

Append the pre-encoded referenced-by value verbatim in HTTPRequest.requestUri
rather than handing it to URIBuilder.addParameter. The spec's wire form mixes
encoding levels, a literal comma delimiter over percent-encoded entries, and
nothing on the classpath produces it: addParameter double-encodes % under both
encoding policies (%1F becomes %251F) and encodes the delimiter under
ALL_RESERVED, setCustomQuery re-encodes % the same way, and URIBuilder's own
formatQuery, which takes a BitSet of characters to leave alone, is
package-private. Passing raw separators instead does not help, because then a
%2C standing for a comma inside a view name is double-encoded while a raw one
is indistinguishable from the delimiter. However many views the chain holds,
they travel as one parameter.

Encode namespace levels and the view name with PercentCodec, which produces
the same bytes as the parent query parameter as the spec requires, and join
them with the configured namespace separator as-is. URLEncoder renders a space
as +, which RFC 3986 percent-decoding reads as a literal plus.

Leave the ETag table cache untouched for view-mediated loads. Servers are
already required to produce distinct ETags for responses that differ by query
parameter, with the snapshots parameter given as the example, so a server
whose response varies on referenced-by owes a distinct ETag and answers 200
rather than 304.

Carry the chain to credential providers as the internal rest-referenced-by
property, mirroring rest-scan-plan-id, rather than putting a wire parameter
name into the config map, where it shared a namespace with server-returned
keys and would override them. Add it inside tableFileIO instead of merging it
into the server's response config, so that config alone still decides whether
the catalog FileIO can be reused; merging it in made every view-mediated load
build a FileIO by reflection. Views build no FileIO and tableSession filters
config through an allow list, so loadView does not inject it at all.

Pass the whole LoadContext down to loadInternal and tableFileIO rather than
one field of it, so later context fields need no signature change and a caller
with no context says so with LoadContext.empty().

Forward the contextual loads through the same delegate the rest of RESTCatalog
uses, and override loadTable/loadView on the AsCatalog and AsViewCatalog
bridges so the context is not dropped there.

Test the encoder in TestRESTUtil next to the namespace encoders it follows,
across the same separator forms, and add its separator validation to the test
that already covers that message. Cover request building in TestHTTPRequest,
and the chain through the catalog: that it reaches the table FileIO
properties, that it leaves the catalog FileIO reusable when the server returns
no table config, that the metadata-table retry against the base table still
carries it, and that the credentials endpoint receives it single-encoded
alongside planId. Fold the duplicated view-load tests into
TestReferencedByQueryParam and reuse RESTUtil.merge rather than reimplementing
it.
Resolve the chain of views a relation was reached through and pass it to the
catalog as a LoadContext, so a REST catalog can forward it to the server.

SparkSupportsLoadContext extends the loading contract with context-carrying
overloads of loadTable and loadView, including the time-travel forms, and
SparkCatalog and SparkSessionCatalog implement it. ResolveViews records the
chain while resolving nested views, with UnResolvedRelationFromView carrying it
through analysis. Cross-catalog view references fail rather than silently
dropping the chain.

Gated behind spark.sql.iceberg.referenced-by-enabled, off by default.
@sfc-gh-prsingh
sfc-gh-prsingh force-pushed the feature/ref-imp-referenced-by branch from 9053739 to 373d92e Compare September 8, 2026 21:42
@singhpk234
singhpk234 requested review from RussellSpitzer and removed request for ldsantos0911 September 8, 2026 22:21
@singhpk234 singhpk234 changed the title Core,Spark: Send referenced-by to all endpoints Spark: [3/N] Support sending referenced-by to all endpoints Sep 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants