difin commented on code in PR #6789:
URL: https://github.com/apache/hive/pull/6789#discussion_r4382258302


##########
iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/mapreduce/IcebergInputFormat.java:
##########
@@ -72,31 +72,36 @@
  */
 public class IcebergInputFormat<T> extends InputFormat<Void, T> {
 
-  private static TableScan createTableScan(Table table, Configuration conf) {
+  private static TableScan createTableScan(Table table, Configuration conf, 
Table serverSidePinTable) {
     TableScan scan = table.newScan();
 
-    long snapshotId = -1;
-    try {
-      snapshotId = conf.getLong(InputFormatConfig.SNAPSHOT_ID, -1);
-    } catch (NumberFormatException e) {
-      String version = conf.get(InputFormatConfig.SNAPSHOT_ID);
-      SnapshotRef ref = table.refs().get(version);
-      if (ref == null) {
-        throw new RuntimeException("Cannot find matching snapshot ID or 
reference name for version " + version);
+    if (HiveTableUtil.hasExplicitScanSnapshotBinding(conf)) {
+      long snapshotId = -1;
+      try {
+        snapshotId = conf.getLong(InputFormatConfig.SNAPSHOT_ID, -1);
+      } catch (NumberFormatException e) {
+        String version = conf.get(InputFormatConfig.SNAPSHOT_ID);
+        Table refsTable = serverSidePinTable != null ? serverSidePinTable : 
table;
+        SnapshotRef ref = refsTable.refs().get(version);
+        if (ref == null) {
+          throw new RuntimeException("Cannot find matching snapshot ID or 
reference name for version " + version);
+        }
+        snapshotId = ref.snapshotId();
+      }
+      String refName = conf.get(InputFormatConfig.OUTPUT_TABLE_SNAPSHOT_REF);
+      if (StringUtils.isNotEmpty(refName)) {

Review Comment:
   Done. A missing ref in the compile-time table now fails via 
`Preconditions.checkState` instead of falling back to a live `useRef`. For the 
older-schema branch case we still use `useRef` (there's no public API to pin a 
snapshot while keeping the table schema), but we fail fast with "Branch %s 
moved since query compilation" if the live head differs from the compile-time 
ref. Added tests for a missing ref, a moved branch, and tag pinning via 
`useSnapshot`.



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