You are viewing a plain text version of this content. The canonical link for it is here.
Posted to gitbox@hive.apache.org by "ayushtkn (via GitHub)" <gi...@apache.org> on 2023/09/22 17:06:07 UTC

[GitHub] [hive] ayushtkn commented on a diff in pull request #4735: HIVE-27711: Iceberg: Allow creating a branch from tag name

ayushtkn commented on code in PR #4735:
URL: https://github.com/apache/hive/pull/4735#discussion_r1334633511


##########
iceberg/iceberg-handler/src/test/java/org/apache/iceberg/mr/hive/TestHiveIcebergBranchOperation.java:
##########
@@ -197,4 +197,37 @@ public void testDropBranch() throws InterruptedException, IOException {
     table.refresh();
     Assert.assertNull(table.refs().get(branchName));
   }
+
+  @Test
+  public void testCreateBranchFromTag() throws IOException, InterruptedException {
+    Table table =
+        testTables.createTableWithVersions(shell, "customers", HiveIcebergStorageHandlerTestUtils.CUSTOMER_SCHEMA,
+            fileFormat, HiveIcebergStorageHandlerTestUtils.CUSTOMER_RECORDS, 2);
+    String branchName1 = "test_branch_1";
+    String tagName = "test_tag";
+    String branchName2 = "test_branch_2";
+    String nonExistTag = "test_non_exist_tag";
+    shell.executeStatement(String.format("ALTER TABLE customers CREATE TAG %s", tagName));
+
+    // Create a branch based on an existing tag.
+    shell.executeStatement(String.format("ALTER TABLE customers CREATE BRANCH %s FOR TAG AS OF %s",
+        branchName1, tagName));
+    table.refresh();
+    SnapshotRef ref = table.refs().get(branchName1);
+    Assert.assertEquals(table.currentSnapshot().snapshotId(), ref.snapshotId());
+    Assert.assertNull(ref.minSnapshotsToKeep());
+    Assert.assertNull(ref.maxSnapshotAgeMs());
+    Assert.assertNull(ref.maxRefAgeMs());
+
+    // Create a branch based on a tag which doesn't exist will fail.
+    try {
+      shell.executeStatement(String.format("ALTER TABLE customers CREATE BRANCH %s FOR TAG AS OF %s",
+          branchName2, nonExistTag));
+    } catch (Throwable e) {
+      while (e.getCause() != null) {
+        e = e.getCause();
+      }
+      Assert.assertTrue(e.getMessage().contains("does not exist"));
+    }

Review Comment:
   Can we use something like ```  Assertions.assertThatThrownBy```, this while loop thing doesn't look very cool



-- 
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: gitbox-unsubscribe@hive.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org