You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by GitBox <gi...@apache.org> on 2022/06/02 23:47:18 UTC

[GitHub] [iceberg] kbendick commented on a diff in pull request #4950: Core: Support metadata table loading in the REST catalog

kbendick commented on code in PR #4950:
URL: https://github.com/apache/iceberg/pull/4950#discussion_r888498511


##########
core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java:
##########
@@ -209,12 +211,40 @@ private LoadTableResponse loadInternal(SessionContext context, TableIdentifier i
 
   @Override
   public Table loadTable(SessionContext context, TableIdentifier identifier) {
-    LoadTableResponse response = loadInternal(context, identifier);
+    MetadataTableType metadataType;
+    LoadTableResponse response;
+    try {
+      response = loadInternal(context, identifier);
+      metadataType = null;
+
+    } catch (NoSuchTableException original) {
+      metadataType = MetadataTableType.from(identifier.name());
+      if (metadataType != null) {
+        // attempt to load a metadata table using the identifier's namespace as the base table
+        TableIdentifier baseIdent = TableIdentifier.of(identifier.namespace().levels());
+        try {
+          response = loadInternal(context, baseIdent);
+        } catch (NoSuchTableException ignored) {
+          // the base table does not exist
+          throw original;
+        }
+      } else {
+        // name is not a metadata table
+        throw original;
+      }
+    }
+
     Pair<RESTClient, FileIO> clients = tableClients(response.config());
     AuthSession session = tableSession(response.config(), session(context));
     RESTTableOperations ops = new RESTTableOperations(
         clients.first(), paths.table(identifier), session::headers, clients.second(), response.tableMetadata());
-    return new BaseTable(ops, fullTableName(identifier));
+
+    BaseTable table = new BaseTable(ops, fullTableName(identifier));
+    if (metadataType != null) {
+      return MetadataTableUtils.createMetadataTableInstance(table, metadataType);
+    }
+
+    return table;

Review Comment:
   The `table` is being used inside of `createMetadataTableInstance(table, metadataType)` regardless.
   
   But I do somewhat agree with your style point, that it might be more readable to duplicate the line of code.



-- 
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