jackye1995 commented on code in PR #6717:
URL: https://github.com/apache/iceberg/pull/6717#discussion_r1103692411


##########
spark/v3.3/spark/src/main/java/org/apache/iceberg/spark/SparkCachedTableCatalog.java:
##########
@@ -144,23 +149,49 @@ private Pair<Table, Long> load(Identifier ident) throws 
NoSuchTableException {
       if (snapshotBasedMatcher.matches()) {
         snapshotId = Long.parseLong(snapshotBasedMatcher.group(1));
       }
+
+      Matcher branchBasedMatcher = BRANCH.matcher(meta);
+      if (branchBasedMatcher.matches()) {
+        branch = branchBasedMatcher.group(1);
+      }
+
+      Matcher tagBasedMatcher = BRANCH.matcher(meta);
+      if (tagBasedMatcher.matches()) {
+        tag = tagBasedMatcher.group(1);
+      }
     }
 
     Preconditions.checkArgument(
-        asOfTimestamp == null || snapshotId == null,
-        "Cannot specify both snapshot and timestamp for time travel: %s",
-        ident);
+        Stream.of(snapshotId, asOfTimestamp, branch, 
tag).filter(Objects::nonNull).count() <= 1,
+        "Can specify at most one of snapshot-id (%s), as-of-timestamp (%s), 
and snapshot-ref (%s)",
+        snapshotId,
+        asOfTimestamp,
+        branch);
 
     Table table = TABLE_CACHE.get(key);
 
     if (table == null) {
       throw new NoSuchTableException(ident);
     }
 
+    long snapshotIdFromTimeTravel = -1L;
+
     if (snapshotId != null) {
-      return Pair.of(table, snapshotId);
+      snapshotIdFromTimeTravel = snapshotId;
     } else if (asOfTimestamp != null) {
-      return Pair.of(table, SnapshotUtil.snapshotIdAsOfTime(table, 
asOfTimestamp));
+      snapshotIdFromTimeTravel = SnapshotUtil.snapshotIdAsOfTime(table, 
asOfTimestamp);
+    } else if (branch != null) {
+      Preconditions.checkArgument(
+          table.snapshot(branch) != null, "branch not associated with a 
snapshot");

Review Comment:
   nit: should capitalize first word, and also provide info in the error 
message, so something like `Cannot find snapshot associated with branch name: 
%s`. Similar comment for the error check.



##########
spark/v3.3/spark/src/main/java/org/apache/iceberg/spark/SparkCachedTableCatalog.java:
##########
@@ -144,23 +149,49 @@ private Pair<Table, Long> load(Identifier ident) throws 
NoSuchTableException {
       if (snapshotBasedMatcher.matches()) {
         snapshotId = Long.parseLong(snapshotBasedMatcher.group(1));
       }
+
+      Matcher branchBasedMatcher = BRANCH.matcher(meta);
+      if (branchBasedMatcher.matches()) {
+        branch = branchBasedMatcher.group(1);
+      }
+
+      Matcher tagBasedMatcher = BRANCH.matcher(meta);
+      if (tagBasedMatcher.matches()) {
+        tag = tagBasedMatcher.group(1);
+      }
     }
 
     Preconditions.checkArgument(
-        asOfTimestamp == null || snapshotId == null,
-        "Cannot specify both snapshot and timestamp for time travel: %s",
-        ident);
+        Stream.of(snapshotId, asOfTimestamp, branch, 
tag).filter(Objects::nonNull).count() <= 1,
+        "Can specify at most one of snapshot-id (%s), as-of-timestamp (%s), 
and snapshot-ref (%s)",
+        snapshotId,
+        asOfTimestamp,
+        branch);
 
     Table table = TABLE_CACHE.get(key);
 
     if (table == null) {
       throw new NoSuchTableException(ident);
     }
 
+    long snapshotIdFromTimeTravel = -1L;
+
     if (snapshotId != null) {
-      return Pair.of(table, snapshotId);
+      snapshotIdFromTimeTravel = snapshotId;
     } else if (asOfTimestamp != null) {
-      return Pair.of(table, SnapshotUtil.snapshotIdAsOfTime(table, 
asOfTimestamp));
+      snapshotIdFromTimeTravel = SnapshotUtil.snapshotIdAsOfTime(table, 
asOfTimestamp);
+    } else if (branch != null) {
+      Preconditions.checkArgument(
+          table.snapshot(branch) != null, "branch not associated with a 
snapshot");

Review Comment:
   nit: should capitalize first word, and also provide info in the error 
message, so something like `Cannot find snapshot associated with branch name: 
%s`. Similar comment for the tag error check.



-- 
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-unsubscr...@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org
For additional commands, e-mail: issues-h...@iceberg.apache.org

Reply via email to