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 2023/01/09 15:21:45 UTC

[GitHub] [iceberg] nastra commented on a diff in pull request #6512: Core: Support registerTable with REST session catalog

nastra commented on code in PR #6512:
URL: https://github.com/apache/iceberg/pull/6512#discussion_r1064754792


##########
core/src/main/java/org/apache/iceberg/jdbc/JdbcTableOperations.java:
##########
@@ -146,6 +149,21 @@ public void doCommit(TableMetadata base, TableMetadata metadata) {
     }
   }
 
+  private Optional<String> getExistingMetadataLocation(TableMetadata base, TableMetadata metadata) {

Review Comment:
   can you elaborate why these changes are needed in order to support registering a table in the REST catalog? I think stuff should work fine without these changes 



##########
core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java:
##########
@@ -351,7 +354,35 @@ public void invalidateTable(SessionContext context, TableIdentifier ident) {}
   @Override
   public Table registerTable(
       SessionContext context, TableIdentifier ident, String metadataFileLocation) {
-    throw new UnsupportedOperationException("Register table is not supported");
+    Preconditions.checkArgument(
+        ident != null && isValidIdentifier(ident), "Invalid identifier: %s", ident);
+    Preconditions.checkArgument(
+        metadataFileLocation != null && !metadataFileLocation.isEmpty(),
+        "Cannot register an empty metadata file location as a table");
+
+    // Throw an exception if this table already exists in the catalog.
+    if (tableExists(context, ident)) {
+      throw new AlreadyExistsException("Table already exists: %s", ident);
+    }
+
+    TableMetadata metadata = TableMetadataParser.read(io, metadataFileLocation);
+    Map<String, String> tableProperties =
+        ImmutableMap.<String, String>builder()
+            .putAll(metadata.properties())
+            .put(BaseMetastoreTableOperations.METADATA_LOCATION_PROP, metadataFileLocation)
+            .build();
+
+    return buildTable(context, ident, metadata.schema())
+        .withLocation(metadata.location())
+        .withProperties(tableProperties)
+        .withPartitionSpec(metadata.spec())
+        .withSortOrder(metadata.sortOrder())
+        .create();
+  }
+
+  private boolean isValidIdentifier(TableIdentifier tableIdentifier) {

Review Comment:
   do we need this, given that it always returns true? I know we do the same in `BaseMetastoreCatalog` where catalog implementations can override this behavior but I don't think we need this here in particular. 
   You might rather want to call `checkIdentifierIsValid(..)` in this case.



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