pvary commented on code in PR #11813:
URL: https://github.com/apache/iceberg/pull/11813#discussion_r1903970848


##########
hive-metastore/src/test/java/org/apache/iceberg/hive/TestHiveViewCatalog.java:
##########
@@ -125,6 +125,51 @@ public void testHiveViewAndIcebergViewWithSameName() 
throws TException, IOExcept
         .hasMessageStartingWith("Not an iceberg view: 
hive.hivedb.test_hive_view");
   }
 
+  @Test
+  public void testHiveViewExists() throws IOException, TException {
+    String dbName = "hivedb";
+    Namespace ns = Namespace.of(dbName);
+    String viewName = "test_hive_view_exists";
+    TableIdentifier identifier = TableIdentifier.of(ns, viewName);
+    TableIdentifier invalidIdentifier = TableIdentifier.of(dbName, "invalid", 
viewName);
+    if (requiresNamespaceCreate()) {
+      catalog.createNamespace(identifier.namespace());
+    }
+
+    assertThat(catalog.viewExists(invalidIdentifier))
+        .as("Should return false on invalid view identifier")
+        .isFalse();
+    assertThat(catalog.viewExists(identifier)).as("View should not exist 
before create").isFalse();
+
+    catalog
+        .buildView(identifier)
+        .withSchema(SCHEMA)
+        .withDefaultNamespace(ns)
+        .withQuery("hive", "select * from hivedb.tbl")
+        .create();
+    assertThat(catalog.viewExists(identifier)).as("View should exist after 
create").isTrue();
+
+    catalog.dropView(identifier);
+    assertThat(catalog.viewExists(identifier)).as("View should not exist after 
drop").isFalse();
+
+    // create a hive table
+    Table hiveTable =
+        createHiveView(
+            viewName, dbName, 
Files.createTempDirectory("hive-view-tests-name").toString());
+    HIVE_METASTORE_EXTENSION.metastoreClient().createTable(hiveTable);
+    assertThat(catalog.viewExists(identifier))
+        .as("ViewExists should return false if identifier refers to a 
non-iceberg view")
+        .isFalse();
+    HIVE_METASTORE_EXTENSION.metastoreClient().dropTable(dbName, viewName);

Review Comment:
   Maybe I am too detail oriented, but would it worth to add?
   ```
       HIVE_METASTORE_EXTENSION
           .metastoreClient()
           .createTable(createHiveTable(testTableName, 
TableType.EXTERNAL_TABLE));
       assertThat(catalog.viewExists(identifier))
           .as("ViewExists should return false if identifier refers to a 
non-iceberg view")
           .isFalse();
       HIVE_METASTORE_EXTENSION.metastoreClient().dropTable(DB_NAME, 
testTableName);
   ```
   
   And similarly to HiveTableTest.testTableExists:
   ```
       Table hiveTable =
           createHiveView(
               viewName, dbName, 
Files.createTempDirectory("hive-view-tests-name").toString());
       HIVE_METASTORE_EXTENSION.metastoreClient().createTable(hiveTable);
       assertThat(catalog.tableExists(identifier))
           .as("Should return false when a hive table with the same name 
exists")
           .isFalse();
       assertThat(catalog.tableExists(metadataIdentifier))
           .as("Metadata table should not exist")
           .isFalse();
       HIVE_METASTORE_EXTENSION.metastoreClient().dropTable(dbName, viewName);
   ```



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