From d7a37f73c97846caf6004f6598a3dd3d700a0bd4 Mon Sep 17 00:00:00 2001 From: Andrey Shitov Date: Tue, 14 Jan 2025 11:34:52 +0300 Subject: [PATCH] Build fix. --- .../iceberg/mr/hive/IcebergTableUtil.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/IcebergTableUtil.java b/iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/IcebergTableUtil.java index 1c0835e030ca..8c62bb6c52c2 100644 --- a/iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/IcebergTableUtil.java +++ b/iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/IcebergTableUtil.java @@ -344,4 +344,33 @@ public static PartitionData toPartitionData(StructLike key, Types.StructType key } return data; } + + public static Snapshot getTableSnapshot(org.apache.hadoop.hive.ql.metadata.Table hmsTable, Table table) { + String refName = HiveUtils.getTableSnapshotRef(hmsTable.getSnapshotRef()); + Snapshot snapshot; + if (refName != null) { + snapshot = table.snapshot(refName); + } else if (hmsTable.getAsOfTimestamp() != null) { + ZoneId timeZone = SessionState.get() == null ? new HiveConf().getLocalTimeZone() : + SessionState.get().getConf().getLocalTimeZone(); + TimestampTZ time = TimestampTZUtil.parse(hmsTable.getAsOfTimestamp(), timeZone); + long snapshotId = SnapshotUtil.snapshotIdAsOfTime(table, time.toEpochMilli()); + snapshot = table.snapshot(snapshotId); + } else if (hmsTable.getAsOfVersion() != null) { + try { + snapshot = table.snapshot(Long.parseLong(hmsTable.getAsOfVersion())); + } catch (NumberFormatException e) { + SnapshotRef ref = table.refs().get(hmsTable.getAsOfVersion()); + if (ref == null) { + throw new RuntimeException("Cannot find matching snapshot ID or reference name for version " + + hmsTable.getAsOfVersion()); + } + snapshot = table.snapshot(ref.snapshotId()); + } + } else { + snapshot = table.currentSnapshot(); + } + return snapshot; + } + }