gaborkaszab commented on code in PR #11597:
URL: https://github.com/apache/iceberg/pull/11597#discussion_r1872741906


##########
hive-metastore/src/test/java/org/apache/iceberg/hive/HiveTableTest.java:
##########
@@ -388,6 +388,52 @@ public void 
testHiveTableAndIcebergTableWithSameName(TableType tableType)
     HIVE_METASTORE_EXTENSION.metastoreClient().dropTable(DB_NAME, 
hiveTableName);
   }
 
+  @Test
+  public void testTableExists() throws TException, IOException {
+    String testTableName = "test_table_exists";
+    TableIdentifier identifier = TableIdentifier.of(DB_NAME, testTableName);
+    TableIdentifier metadataIdentifier = TableIdentifier.of(DB_NAME, 
testTableName, "partitions");
+
+    assertThat(catalog.tableExists(identifier))
+        .as("Table should not exist before create")
+        .isFalse();
+    catalog.buildTable(identifier, SCHEMA).create();
+
+    assertThat(catalog.tableExists(identifier)).as("Table should exist after 
create").isTrue();
+    assertThat(catalog.tableExists(metadataIdentifier))
+        .as("Metadata table should also exist")
+        .isTrue();
+
+    assertThat(catalog.dropTable(identifier)).as("Should drop a table that 
does exist").isTrue();
+    assertThat(catalog.tableExists(identifier)).as("Table should not exist 
after drop").isFalse();
+    assertThat(catalog.tableExists(metadataIdentifier))
+        .as("Metadata table should not exist after drop")
+        .isFalse();
+
+    // recreate a hive table with the same name shall return false instead of 
throw exception
+    HIVE_METASTORE_EXTENSION
+        .metastoreClient()
+        .createTable(createHiveTable(testTableName, TableType.EXTERNAL_TABLE));
+    assertThat(catalog.tableExists(identifier))
+        .as("Catalog shall return false even if hive table with the same name 
exists")
+        .isFalse();
+    assertThat(catalog.tableExists(metadataIdentifier))
+        .as("Metadata table should not exist")
+        .isFalse();
+    HIVE_METASTORE_EXTENSION.metastoreClient().dropTable(DB_NAME, 
testTableName);
+    // tableExists shall return false for iceberg view

Review Comment:
   nit: new line before this to show that this is another section/step within 
this test?



##########
hive-metastore/src/main/java/org/apache/iceberg/hive/HiveCatalog.java:
##########
@@ -412,6 +412,40 @@ private void validateTableIsIcebergTableOrView(
     }
   }
 
+  /**
+   * Check whether table or metadata table exists.
+   *
+   * @param identifier a table identifier
+   * @return true if the table exists, false otherwise

Review Comment:
   I think for the HiveCatalog implementation that comment would in fact add 
some extra value for the users so +1



-- 
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: issues-unsubscr...@iceberg.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org
For additional commands, e-mail: issues-h...@iceberg.apache.org

Reply via email to