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


##########
core/src/main/java/org/apache/iceberg/rest/CatalogHandlers.java:
##########
@@ -361,4 +364,32 @@ private static TableMetadata commit(TableOperations ops, 
UpdateTableRequest requ
 
     return ops.current();
   }
+
+  public static void commitTransaction(Catalog catalog, 
CommitTransactionRequest request) {
+    List<Transaction> transactions = Lists.newArrayList();
+
+    for (CommitTransactionRequest.CommitTableRequest tableChange : 
request.tableChanges()) {
+      Table table = catalog.loadTable(tableChange.identifier());
+      if (table instanceof BaseTable) {
+        UpdateTableRequest updateTableRequest =
+            new UpdateTableRequest(tableChange.requirements(), 
tableChange.updates());
+
+        Transaction transaction =
+            Transactions.newTransaction(
+                tableChange.identifier().toString(), ((BaseTable) 
table).operations());
+        transactions.add(transaction);
+
+        BaseTransaction.TransactionTable txTable =
+            (BaseTransaction.TransactionTable) transaction.table();
+
+        // this performs validations and makes temporary commits that are 
in-memory
+        commit(txTable.operations(), updateTableRequest);
+      } else {
+        throw new IllegalStateException("Cannot wrap catalog that does not 
produce BaseTable");
+      }
+    }
+
+    // only commit if validations passed previously
+    transactions.forEach(Transaction::commitTransaction);

Review Comment:
   @singhpk234 the intention here was to have a very simple approach that does 
only validate the requirements and nothing else. Hence we don't have a way of 
providing true atomicity here, which is left to the implementation details of a 
server. I've also added a comment to make this clear.
   The main idea of this PR was to only include the REST-specific changes from 
https://github.com/apache/iceberg/pull/6948



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

Reply via email to