dbjnbnrj commented on code in PR #15993:
URL: https://github.com/apache/iceberg/pull/15993#discussion_r3096403653


##########
spark/v4.1/spark-extensions/src/test/java/org/apache/iceberg/spark/extensions/TestRegisterTableProcedure.java:
##########
@@ -82,4 +83,59 @@ public void testRegisterTable() throws NoSuchTableException, 
ParseException {
         .as("Should have the right datafile count in the procedure result")
         .contains(originalFileCount, atIndex(2));
   }
+
+  @TestTemplate
+  public void testRegisterTableAlreadyExistsFails() throws 
NoSuchTableException, ParseException {
+    long numRows = 1000;
+
+    sql("CREATE TABLE %s (id int, data string) using ICEBERG", tableName);
+    spark
+        .range(0, numRows)
+        .withColumn("data", functions.col("id").cast(DataTypes.StringType))
+        .writeTo(tableName)
+        .append();
+
+    Table table = Spark3Util.loadIcebergTable(spark, tableName);
+    String metadataJson = TableUtil.metadataFileLocation(table);
+
+    sql("CALL %s.system.register_table('%s', '%s')", catalogName, targetName, 
metadataJson);
+
+    assertThatThrownBy(
+            () ->
+                sql(
+                    "CALL %s.system.register_table('%s', '%s')",
+                    catalogName, targetName, metadataJson))
+        .isInstanceOf(Exception.class)
+        .hasMessageContaining("Table already exists");
+  }
+
+  @TestTemplate
+  public void testRegisterTableWithOverwriteNotSupported()
+      throws NoSuchTableException, ParseException {
+    long numRows = 1000;
+
+    sql("CREATE TABLE %s (id int, data string) using ICEBERG", tableName);
+    spark
+        .range(0, numRows)
+        .withColumn("data", functions.col("id").cast(DataTypes.StringType))
+        .writeTo(tableName)
+        .append();
+
+    Table table = Spark3Util.loadIcebergTable(spark, tableName);
+    String metadataJson = TableUtil.metadataFileLocation(table);
+
+    sql("CALL %s.system.register_table('%s', '%s')", catalogName, targetName, 
metadataJson);
+
+    // The test setup uses HiveCatalog which doesn't support overwrite, so it 
falls back to the
+    // default implementation in Catalog interface which throws 
UnsupportedOperationException.
+    // This verifies that the 'overwrite' parameter is correctly passed to the 
catalog.
+    // The third argument in register_table procedure is overwrite = true.
+    assertThatThrownBy(
+            () ->
+                sql(
+                    "CALL %s.system.register_table('%s', '%s', true)",
+                    catalogName, targetName, metadataJson))
+        .isInstanceOf(Exception.class)
+        .hasMessageContaining("Registering tables with overwrite is not 
supported");
+  }

Review Comment:
   Thanks - I moved the positive test case to a separate test class 
(TestRegisterTableProcedureWithOverwriteSupport) as the standard catalogs used 
in `CatalogTestBase` (like `HiveCatalog` and `HadoopCatalog`) do not currently 
override the registerTable(...,  overwrite) method. I tried to use the logic 
from 
/usr/local/google/home/bdebjani/iceberg/core/src/test/java/org/apache/iceberg/rest/TestRESTCatalog.java
 testRegisterTableOverwriteTrueSupported to test with overwrite=true.



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