rdblue commented on code in PR #5364:
URL: https://github.com/apache/iceberg/pull/5364#discussion_r954266899


##########
core/src/main/java/org/apache/iceberg/BaseTableScan.java:
##########
@@ -86,20 +90,56 @@ public TableScan appendsAfter(long fromSnapshotId) {
   public TableScan useSnapshot(long scanSnapshotId) {
     Preconditions.checkArgument(
         snapshotId() == null, "Cannot override snapshot, already set to 
id=%s", snapshotId());
+    Preconditions.checkArgument(
+        ref() == null, "Cannot override snapshot, already set to id=%s", 
ref());
     Preconditions.checkArgument(
         tableOps().current().snapshot(scanSnapshotId) != null,
         "Cannot find snapshot with ID %s",
         scanSnapshotId);
     return newRefinedScan(
-        tableOps(), table(), tableSchema(), 
context().useSnapshotId(scanSnapshotId));
+        tableOps(),
+        table(),
+        tableSchema(),
+        
context().useRef(SnapshotRef.MAIN_BRANCH).useSnapshotId(scanSnapshotId));
+  }
+
+  @Override
+  public TableScan useRef(String name) {
+    Preconditions.checkArgument(
+        snapshotId() == null, "Cannot override ref, already set to id=%s", 
snapshotId());
+    Preconditions.checkArgument(ref() == null, "Cannot override ref, already 
set to id=%s", ref());
+    SnapshotRef ref = tableOps().current().ref(name);
+    Preconditions.checkArgument(ref != null, "Cannot find ref %s", name);
+    long scanSnapshotId = ref.snapshotId();
+    return newRefinedScan(
+        tableOps(), table(), tableSchema(), 
context().useRef(name).useSnapshotId(scanSnapshotId));
   }
 
   @Override
   public TableScan asOfTime(long timestampMillis) {
     Preconditions.checkArgument(
-        snapshotId() == null, "Cannot override snapshot, already set to 
id=%s", snapshotId());
+        snapshotId() == null || ref() != null,
+        "Cannot override snapshot, already set to id=%s",
+        snapshotId());
+
+    if (ref() == null) {
+      Preconditions.checkArgument(
+          table().currentSnapshot() != null,
+          "Cannot find a snapshot older than %s in table",
+          DateTimeUtil.formatTimestampMillis(timestampMillis));
+    }
 
-    return useSnapshot(SnapshotUtil.snapshotIdAsOfTime(table(), 
timestampMillis));
+    String ref = ref() == null ? SnapshotRef.MAIN_BRANCH : ref();

Review Comment:
   I think there's a problem here: `asOfTime` selects a snapshot from table 
history, which we don't keep for refs other than `main`. That means we can't 
really have consistent behavior because the only way to implement this for 
branches would be to use ancestors and not the actual branch history. Because 
of that issue, I don't think that we should allow combining `useRef` and 
`asOfTime` after all.
   



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