singhpk234 commented on code in PR #14236:
URL: https://github.com/apache/iceberg/pull/14236#discussion_r2424615581


##########
hive-metastore/src/test/java/org/apache/iceberg/hive/TestHiveCommits.java:
##########
@@ -504,6 +505,60 @@ public void testChangeLockWithAlterTable() throws 
Exception {
         .hasSameClassAs(initialLock);
   }
 
+  @Test
+  public void testFirstHiveCommitNoLock() {
+    testFirstHivCommitWithLockSetting(false);
+  }
+
+  @Test
+  public void testFirstHivCommitWithLock() {

Review Comment:
   minor : copy to all places 
   ```suggestion
     public void testFirstHiveCommitWithLock() {
   ```



##########
hive-metastore/src/test/java/org/apache/iceberg/hive/TestHiveTable.java:
##########
@@ -119,6 +127,66 @@ public void testCreate() throws TException {
     assertThat(icebergTable.schema().asStruct()).isEqualTo(SCHEMA.asStruct());
   }
 
+  @Test
+  public void testCreateTableWithNoLock() {
+    testCreateTableEndToEnd(false);
+  }
+
+  @Test
+  public void testCreateTableWithLock() {
+    testCreateTableEndToEnd(true);
+  }
+
+  private void testCreateTableEndToEnd(boolean lockEnabled) {
+    String tableName = lockEnabled ? "new_table_lock_e2e" : 
"new_table_no_lock_e2e";
+    TableIdentifier newTableIdentifier = TableIdentifier.of(DB_NAME, 
tableName);
+
+    try {
+      // Create table with lock setting via catalog
+      // We will spy the call to create table operation and capture the lock 
object being returned
+      HiveCatalog spyCatalog = spy(catalog);
+      AtomicReference<HiveLock> lockRef = new AtomicReference<>();
+      doAnswer(
+              (args) -> {
+                TableOperations ops =
+                    catalog.newTableOps(args.getArgument(0, 
TableIdentifier.class));
+                HiveTableOperations spyOps = (HiveTableOperations) spy(ops);
+                doAnswer(
+                        (lockArgs) -> {
+                          lockRef.set(
+                              ((HiveTableOperations) ops)
+                                  .lockObject(lockArgs.getArgument(0, 
TableMetadata.class)));
+                          return lockRef.get();
+                        })
+                    .when(spyOps)
+                    .lockObject(any());
+                return spyOps;
+              })
+          .when(spyCatalog)
+          .newTableOps(newTableIdentifier);
+
+      spyCatalog.createTable(
+          newTableIdentifier,
+          SCHEMA,
+          PartitionSpec.unpartitioned(),
+          ImmutableMap.of(HIVE_LOCK_ENABLED, String.valueOf(lockEnabled)));
+
+      Class<? extends HiveLock> expectedLockClass =
+          lockEnabled ? MetastoreLock.class : NoLock.class;
+      assertThat(lockRef).as("Lock not captured by the 
stub").doesNotHaveNullValue();
+      assertThat(lockRef.get())
+          .as(
+              "Table created with HIVE_LOCK_ENABLED="

Review Comment:
   having the table name in this case too, will help debugging



##########
hive-metastore/src/test/java/org/apache/iceberg/hive/TestHiveCommits.java:
##########
@@ -504,6 +505,60 @@ public void testChangeLockWithAlterTable() throws 
Exception {
         .hasSameClassAs(initialLock);
   }
 
+  @Test
+  public void testFirstHiveCommitNoLock() {
+    testFirstHivCommitWithLockSetting(false);
+  }

Review Comment:
   can we make this parameterized instead ? 



##########
hive-metastore/src/main/java/org/apache/iceberg/hive/HiveTableOperations.java:
##########
@@ -143,7 +143,7 @@ protected void doCommit(TableMetadata base, TableMetadata 
metadata) {
         BaseMetastoreOperations.CommitStatus.FAILURE;
     boolean updateHiveTable = false;
 
-    HiveLock lock = lockObject(base);
+    HiveLock lock = lockObject(base != null ? base : metadata);

Review Comment:
   looks reasonable to me, we do similar thing in glue 
   
https://github.com/apache/iceberg/blob/main/aws/src/main/java/org/apache/iceberg/aws/glue/GlueTableOperations.java#L154-L156



##########
hive-metastore/src/test/java/org/apache/iceberg/hive/TestHiveTable.java:
##########
@@ -119,6 +127,66 @@ public void testCreate() throws TException {
     assertThat(icebergTable.schema().asStruct()).isEqualTo(SCHEMA.asStruct());
   }
 
+  @Test
+  public void testCreateTableWithNoLock() {
+    testCreateTableEndToEnd(false);
+  }
+
+  @Test
+  public void testCreateTableWithLock() {
+    testCreateTableEndToEnd(true);
+  }

Review Comment:
   same feedback as above can we make it parameterized ? 



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