aokolnychyi commented on code in PR #6965:
URL: https://github.com/apache/iceberg/pull/6965#discussion_r1129801228


##########
core/src/main/java/org/apache/iceberg/util/SnapshotUtil.java:
##########
@@ -397,6 +397,52 @@ public static Schema schemaFor(Table table, Long 
snapshotId, Long timestampMilli
     return table.schema();
   }
 
+  /**
+   * Return the schema of the snapshot at a given branch.
+   *
+   * <p>If branch does not exist, the table schema is returned because it will 
be the schema when
+   * the new branch is created.
+   *
+   * @param table a {@link Table}
+   * @param branch branch name of the table (nullable)
+   * @return schema of the specific snapshot at the given branch
+   */
+  public static Schema schemaFor(Table table, String branch) {
+    if (branch == null || branch.equals(SnapshotRef.MAIN_BRANCH)) {
+      return table.schema();
+    }
+
+    Snapshot ref = table.snapshot(branch);
+    if (ref == null) {
+      return table.schema();
+    }
+
+    return schemaFor(table, ref.snapshotId());
+  }
+
+  /**
+   * Return the schema of the snapshot at a given branch.
+   *
+   * <p>If branch does not exist, the table schema is returned because it will 
be the schema when
+   * the new branch is created.
+   *
+   * @param metadata a {@link TableMetadata}
+   * @param branch branch name of the table (nullable)
+   * @return schema of the specific snapshot at the given branch
+   */
+  public static Schema schemaFor(TableMetadata metadata, String branch) {
+    if (branch == null || branch.equals(SnapshotRef.MAIN_BRANCH)) {
+      return metadata.schema();
+    }
+
+    SnapshotRef ref = metadata.ref(branch);
+    if (ref == null) {
+      return metadata.schema();
+    }
+
+    return 
metadata.schemas().get(metadata.snapshot(ref.snapshotId()).schemaId());

Review Comment:
   nit: There are quite a few method calls in this line, what about an extra 
variable for the snapshot, for instance?



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