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/03/04 08:42:27 UTC

[GitHub] [iceberg] nastra commented on a change in pull request #4260: Core: Implement table refs in TableMetadataParser

nastra commented on a change in pull request #4260:
URL: https://github.com/apache/iceberg/pull/4260#discussion_r819366742



##########
File path: core/src/main/java/org/apache/iceberg/TableMetadata.java
##########
@@ -720,15 +728,24 @@ private static SortOrder freshSortOrder(int orderId, Schema schema, SortOrder so
     return builder.build();
   }
 
-  private Map<String, SnapshotRef> validateRefs(Map<String, SnapshotRef> inputRefs) {
-    for (Map.Entry<String, SnapshotRef> refEntry : inputRefs.entrySet()) {
-      String refName = refEntry.getKey();
-      SnapshotRef ref = refEntry.getValue();
-      if (!(ref.snapshotId() == -1 && refName.equals(SnapshotRef.MAIN_BRANCH))) {
-        Preconditions.checkArgument(snapshotsById.containsKey(ref.snapshotId()),
-            "Snapshot reference %s does not exist in the existing snapshots list", ref);
-      }
+  private static Map<String, SnapshotRef> validateRefs(Long currentSnapshotId,
+                                                       Map<String, SnapshotRef> inputRefs,
+                                                       Map<Long, Snapshot> snapshotsById) {
+    for (SnapshotRef ref : inputRefs.values()) {
+      Preconditions.checkArgument(snapshotsById.containsKey(ref.snapshotId()),
+          "Snapshot for reference %s does not exist in the existing snapshots list", ref);
     }
+
+    SnapshotRef main = inputRefs.get(SnapshotRef.MAIN_BRANCH);
+    if (currentSnapshotId != -1) {
+      Preconditions.checkArgument(main == null || currentSnapshotId == main.snapshotId(),
+          "Current snapshot ID does not match main branch (%s != %s)",
+          currentSnapshotId, main != null ? main.snapshotId() : null);
+    } else {
+      Preconditions.checkArgument(main == null,
+          "Current snapshot is not set, but main branch exists: %s", main);

Review comment:
       nit: should this mention `...snapshot ID is not set...` to be consistent with the error message above?

##########
File path: core/src/main/java/org/apache/iceberg/TableMetadata.java
##########
@@ -720,15 +728,24 @@ private static SortOrder freshSortOrder(int orderId, Schema schema, SortOrder so
     return builder.build();
   }
 
-  private Map<String, SnapshotRef> validateRefs(Map<String, SnapshotRef> inputRefs) {
-    for (Map.Entry<String, SnapshotRef> refEntry : inputRefs.entrySet()) {
-      String refName = refEntry.getKey();
-      SnapshotRef ref = refEntry.getValue();
-      if (!(ref.snapshotId() == -1 && refName.equals(SnapshotRef.MAIN_BRANCH))) {
-        Preconditions.checkArgument(snapshotsById.containsKey(ref.snapshotId()),
-            "Snapshot reference %s does not exist in the existing snapshots list", ref);
-      }
+  private static Map<String, SnapshotRef> validateRefs(Long currentSnapshotId,
+                                                       Map<String, SnapshotRef> inputRefs,
+                                                       Map<Long, Snapshot> snapshotsById) {
+    for (SnapshotRef ref : inputRefs.values()) {
+      Preconditions.checkArgument(snapshotsById.containsKey(ref.snapshotId()),
+          "Snapshot for reference %s does not exist in the existing snapshots list", ref);
     }
+
+    SnapshotRef main = inputRefs.get(SnapshotRef.MAIN_BRANCH);
+    if (currentSnapshotId != -1) {
+      Preconditions.checkArgument(main == null || currentSnapshotId == main.snapshotId(),
+          "Current snapshot ID does not match main branch (%s != %s)",

Review comment:
       nit: I wonder if the message would be slightly clearer like this: `Current snapshot ID '%s' does not match the snapshot ID 
    '%s' of the main branch`




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