stevenzwu commented on code in PR #15831:
URL: https://github.com/apache/iceberg/pull/15831#discussion_r3031282933
##########
core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java:
##########
@@ -1471,6 +1478,113 @@ public View loadView(SessionContext context,
TableIdentifier identifier) {
return new BaseView(ops, ViewUtil.fullViewName(name(), identifier));
}
+ private LoadRelationResponse loadRelationInternal(
+ SessionContext context,
+ TableIdentifier identifier,
+ Map<String, String> headers,
+ Consumer<Map<String, String>> responseHeaders) {
+ Endpoint.check(endpoints, Endpoint.V1_LOAD_RELATION);
+ AuthSession contextualSession = authManager.contextualSession(context,
catalogAuth);
+ return client
+ .withAuthSession(contextualSession)
+ .get(
+ paths.relation(identifier),
+ ImmutableMap.of(),
+ LoadRelationResponse.class,
+ headers,
+ ErrorHandlers.relationErrorHandler(),
+ responseHeaders);
+ }
+
+ /**
+ * Load a relation (table or view) using the universal load endpoint and
construct the
+ * corresponding {@link Table} or {@link View} object.
+ */
+ public Relation loadRelation(SessionContext context, TableIdentifier
identifier) {
+ Map<String, String> responseHeaders = Maps.newHashMap();
+ TableWithETag cachedTable = tableCache.getIfPresent(context.sessionId(),
identifier);
+
+ LoadRelationResponse response =
+ loadRelationInternal(
+ context, identifier, headersForLoadTable(cachedTable),
responseHeaders::putAll);
+
+ if (response == null) {
+ Preconditions.checkNotNull(cachedTable, "Invalid load relation response:
null");
+ return Relation.forTable(identifier, cachedTable.supplier().get());
+ }
+
+ if (response.objectType() == CatalogObjectType.TABLE) {
+ return buildTableRelation(context, identifier, response.tableResponse(),
responseHeaders);
+ } else {
+ return buildViewRelation(context, identifier, response.viewResponse());
+ }
+ }
+
+ private BatchLoadRelationsResponse batchLoadRelationsInternal(
+ SessionContext context, BatchLoadRelationsRequest request) {
+ Endpoint.check(endpoints, Endpoint.V1_BATCH_LOAD_RELATIONS);
+ AuthSession contextualSession = authManager.contextualSession(context,
catalogAuth);
+ return client
+ .withAuthSession(contextualSession)
+ .post(
+ paths.batchLoadRelations(),
+ request,
+ BatchLoadRelationsResponse.class,
+ Map.of(),
+ ErrorHandlers.relationErrorHandler());
+ }
+
+ /**
+ * Batch load relations (tables and views) using the batch load endpoint.
Constructs {@link Table}
+ * and {@link View} objects for each result. Not-found identifiers (404) are
skipped.
+ */
+ public List<Relation> loadRelations(SessionContext context,
Set<TableIdentifier> identifiers) {
+ BatchLoadRelationsRequest.Builder requestBuilder =
BatchLoadRelationsRequest.builder();
+ for (TableIdentifier ident : identifiers) {
+ BatchLoadRelationRequestItem.Builder itemBuilder =
+ BatchLoadRelationRequestItem.builder().withIdentifier(ident);
+ TableWithETag cached = tableCache.getIfPresent(context.sessionId(),
ident);
+ if (cached != null) {
+ itemBuilder.withEtag(cached.eTag());
+ }
+
+ requestBuilder.addIdentifier(itemBuilder.build());
+ }
+
+ BatchLoadRelationsResponse response =
+ batchLoadRelationsInternal(context, requestBuilder.build());
+
+ List<Relation> relations = Lists.newArrayList();
+ for (BatchLoadRelationResultItem item : response.results()) {
+ TableIdentifier ident = item.identifier();
+ switch (item.status()) {
Review Comment:
done
##########
core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java:
##########
@@ -1471,6 +1478,113 @@ public View loadView(SessionContext context,
TableIdentifier identifier) {
return new BaseView(ops, ViewUtil.fullViewName(name(), identifier));
}
+ private LoadRelationResponse loadRelationInternal(
+ SessionContext context,
+ TableIdentifier identifier,
+ Map<String, String> headers,
+ Consumer<Map<String, String>> responseHeaders) {
+ Endpoint.check(endpoints, Endpoint.V1_LOAD_RELATION);
+ AuthSession contextualSession = authManager.contextualSession(context,
catalogAuth);
+ return client
+ .withAuthSession(contextualSession)
+ .get(
+ paths.relation(identifier),
+ ImmutableMap.of(),
+ LoadRelationResponse.class,
+ headers,
+ ErrorHandlers.relationErrorHandler(),
+ responseHeaders);
+ }
+
+ /**
+ * Load a relation (table or view) using the universal load endpoint and
construct the
+ * corresponding {@link Table} or {@link View} object.
+ */
+ public Relation loadRelation(SessionContext context, TableIdentifier
identifier) {
+ Map<String, String> responseHeaders = Maps.newHashMap();
+ TableWithETag cachedTable = tableCache.getIfPresent(context.sessionId(),
identifier);
+
+ LoadRelationResponse response =
+ loadRelationInternal(
+ context, identifier, headersForLoadTable(cachedTable),
responseHeaders::putAll);
+
+ if (response == null) {
+ Preconditions.checkNotNull(cachedTable, "Invalid load relation response:
null");
+ return Relation.forTable(identifier, cachedTable.supplier().get());
+ }
+
+ if (response.objectType() == CatalogObjectType.TABLE) {
+ return buildTableRelation(context, identifier, response.tableResponse(),
responseHeaders);
+ } else {
+ return buildViewRelation(context, identifier, response.viewResponse());
+ }
+ }
+
+ private BatchLoadRelationsResponse batchLoadRelationsInternal(
+ SessionContext context, BatchLoadRelationsRequest request) {
+ Endpoint.check(endpoints, Endpoint.V1_BATCH_LOAD_RELATIONS);
+ AuthSession contextualSession = authManager.contextualSession(context,
catalogAuth);
+ return client
+ .withAuthSession(contextualSession)
+ .post(
+ paths.batchLoadRelations(),
+ request,
+ BatchLoadRelationsResponse.class,
+ Map.of(),
+ ErrorHandlers.relationErrorHandler());
+ }
+
+ /**
+ * Batch load relations (tables and views) using the batch load endpoint.
Constructs {@link Table}
+ * and {@link View} objects for each result. Not-found identifiers (404) are
skipped.
+ */
+ public List<Relation> loadRelations(SessionContext context,
Set<TableIdentifier> identifiers) {
+ BatchLoadRelationsRequest.Builder requestBuilder =
BatchLoadRelationsRequest.builder();
+ for (TableIdentifier ident : identifiers) {
+ BatchLoadRelationRequestItem.Builder itemBuilder =
+ BatchLoadRelationRequestItem.builder().withIdentifier(ident);
+ TableWithETag cached = tableCache.getIfPresent(context.sessionId(),
ident);
+ if (cached != null) {
+ itemBuilder.withEtag(cached.eTag());
+ }
+
+ requestBuilder.addIdentifier(itemBuilder.build());
+ }
+
+ BatchLoadRelationsResponse response =
+ batchLoadRelationsInternal(context, requestBuilder.build());
+
+ List<Relation> relations = Lists.newArrayList();
+ for (BatchLoadRelationResultItem item : response.results()) {
+ TableIdentifier ident = item.identifier();
+ switch (item.status()) {
+ case 200:
Review Comment:
done
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]