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/07/08 15:17:44 UTC

[GitHub] [iceberg] bryanck commented on a diff in pull request #5199: REST: Create commit catalog handler fix

bryanck commented on code in PR #5199:
URL: https://github.com/apache/iceberg/pull/5199#discussion_r916916654


##########
core/src/main/java/org/apache/iceberg/rest/CatalogHandlers.java:
##########
@@ -236,37 +252,22 @@ public static LoadTableResponse loadTable(Catalog catalog, TableIdentifier ident
     throw new IllegalStateException("Cannot wrap catalog that does not produce BaseTable");
   }
 
+  public static void renameTable(Catalog catalog, RenameTableRequest request) {
+    catalog.renameTable(request.source(), request.destination());
+  }
+
   public static LoadTableResponse updateTable(Catalog catalog, TableIdentifier ident, UpdateTableRequest request) {
     TableMetadata finalMetadata;
     if (isCreate(request)) {
-      // this is a hacky way to get TableOperations for an uncommitted table
-      Transaction transaction = catalog.buildTable(ident, EMPTY_SCHEMA).createOrReplaceTransaction();
-      if (transaction instanceof BaseTransaction) {
-        BaseTransaction baseTransaction = (BaseTransaction) transaction;
-        finalMetadata = create(baseTransaction.underlyingOps(), baseTransaction.startMetadata(), request);
-      } else {
-        throw new IllegalStateException("Cannot wrap catalog that does not produce BaseTransaction");
-      }
-
+      finalMetadata = commitCreate(catalog, ident, request);
     } else {
-      Table table = catalog.loadTable(ident);
-      if (table instanceof BaseTable) {
-        TableOperations ops = ((BaseTable) table).operations();
-        finalMetadata = commit(ops, request);
-      } else {
-        throw new IllegalStateException("Cannot wrap catalog that does not produce BaseTable");
-      }
+      finalMetadata = commitUpdate(catalog, ident, request);
     }
-

Review Comment:
   This is done.



##########
core/src/main/java/org/apache/iceberg/rest/CatalogHandlers.java:
##########
@@ -282,20 +283,77 @@ private static boolean isCreate(UpdateTableRequest request) {
     return isCreate;
   }
 
-  private static TableMetadata create(TableOperations ops, TableMetadata start, UpdateTableRequest request) {
+  private static TableMetadata commitUpdate(Catalog catalog, TableIdentifier ident, UpdateTableRequest request) {
+    Table table = catalog.loadTable(ident);
+    if (table instanceof BaseTable) {
+      TableOperations ops = ((BaseTable) table).operations();
+      return commit(ops, request.requirements(), request.updates());
+    } else {
+      throw new IllegalStateException("Cannot wrap catalog that does not produce BaseTable");
+    }
+  }
+
+  private static TableMetadata commitCreate(Catalog catalog, TableIdentifier ident, UpdateTableRequest request) {
+    // this is a hacky way to get TableOperations for an uncommitted table
+    Transaction transaction = catalog.buildTable(ident, EMPTY_SCHEMA).createOrReplaceTransaction();
+    if (!(transaction instanceof BaseTransaction)) {
+      throw new IllegalStateException("Cannot wrap catalog that does not produce BaseTransaction");

Review Comment:
   I made this change.



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