You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by "amogh-jahagirdar (via GitHub)" <gi...@apache.org> on 2024/07/02 16:56:37 UTC

Re: [PR] Core: Fix create v1 table on REST Catalog [iceberg]

amogh-jahagirdar commented on code in PR #10369:
URL: https://github.com/apache/iceberg/pull/10369#discussion_r1653259556


##########
core/src/main/java/org/apache/iceberg/rest/CatalogHandlers.java:
##########
@@ -375,7 +376,16 @@ private static TableMetadata create(TableOperations ops, UpdateTableRequest requ
     request.requirements().forEach(requirement -> requirement.validate(ops.current()));
 
     TableMetadata.Builder builder = TableMetadata.buildFromEmpty();
-    request.updates().forEach(update -> update.applyTo(builder));
+    request
+        .updates()
+        .forEach(
+            update -> {
+              if (update instanceof UpgradeFormatVersion) {
+                builder.setInitialFormatVersion(((UpgradeFormatVersion) update).formatVersion());

Review Comment:
   I stepped through the code/debugger with the new tests, I think the right solution is to use the TableMetadata#newTableMetadata API in the `create` method rather than buildFromEmpty and apply the updates. That will build the initial metadata as V1 rather than trying to mutate it later after it's built, which is what I think @rdblue is saying to avoid. I'll let him confirm though.



##########
core/src/main/java/org/apache/iceberg/rest/CatalogHandlers.java:
##########
@@ -375,7 +376,16 @@ private static TableMetadata create(TableOperations ops, UpdateTableRequest requ
     request.requirements().forEach(requirement -> requirement.validate(ops.current()));
 
     TableMetadata.Builder builder = TableMetadata.buildFromEmpty();
-    request.updates().forEach(update -> update.applyTo(builder));
+    request
+        .updates()
+        .forEach(
+            update -> {
+              if (update instanceof UpgradeFormatVersion) {
+                builder.setInitialFormatVersion(((UpgradeFormatVersion) update).formatVersion());

Review Comment:
   Or an alternative is to add a `buildFromEmpty(int formatVersion)` API and apply the updates. Either way, agree with the idea that the format version should be defined once upfront when building a new table metadata instance rather than mutate it later.



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