ajantha-bhat commented on code in PR #14868:
URL: https://github.com/apache/iceberg/pull/14868#discussion_r2672997742


##########
core/src/test/java/org/apache/iceberg/view/ViewCatalogTests.java:
##########
@@ -1968,4 +1970,87 @@ public void dropNonEmptyNamespace() {
         .as("Namespace should not exist")
         .isFalse();
   }
+
+  @Test
+  public void registerView() {
+    C catalog = catalog();
+
+    // Register view is not yet supported for REST catalog
+    assumeThat(catalog instanceof RESTCatalog).isFalse();
+
+    TableIdentifier identifier = TableIdentifier.of("ns", "view");
+
+    if (requiresNamespaceCreate()) {
+      catalog.createNamespace(identifier.namespace());
+    }
+
+    View originalView =
+        catalog()
+            .buildView(identifier)
+            .withSchema(SCHEMA)
+            .withDefaultNamespace(identifier.namespace())
+            .withDefaultCatalog(catalog().name())
+            .withQuery("spark", "select * from ns.tbl")
+            .withProperty(GC_ENABLED, "false")
+            .create();
+
+    ViewOperations ops = ((BaseView) originalView).operations();
+    String metadataLocation = ops.current().metadataFileLocation();
+
+    assertThat(catalog.dropView(identifier)).isTrue();
+    assertThat(catalog.viewExists(identifier)).as("View must not 
exist").isFalse();
+
+    // view metadata should still exist after dropping the view as gc is 
disabled
+    assertThat(((BaseViewOperations) 
ops).io().newInputFile(metadataLocation).exists()).isTrue();
+
+    View registeredView = catalog.registerView(identifier, metadataLocation);
+
+    assertThat(registeredView).isNotNull();
+    assertThat(catalog.viewExists(identifier)).as("View must exist").isTrue();
+    assertThat(registeredView.schema().asStruct())
+        .as("Schema must match")
+        .isEqualTo(originalView.schema().asStruct());
+    assertThat(registeredView.currentVersion())
+        .as("Current version must match")
+        .isEqualTo(originalView.currentVersion());
+    assertThat(registeredView.versions())
+        .as("versions must match")
+        .isEqualTo(originalView.versions());
+    assertThat(registeredView.history()).as("History must 
match").isEqualTo(originalView.history());
+
+    assertThat(catalog.loadView(identifier)).isNotNull();
+    assertThat(catalog.dropView(identifier)).isTrue();
+    assertThat(catalog.viewExists(identifier)).isFalse();
+  }
+
+  @Test
+  public void registerExistingView() {

Review Comment:
   Nope. I added this for test in `CatalogTest` but each catalog had its own 
error message format. So, we couldn't have common clean test
   
   ```
   @Test
       public void testRegisterTableWithExistingView() {
           C catalog = catalog();
   
           assumeThat(catalog).isInstanceOf(ViewCatalog.class);
   
           TableIdentifier identifier = TableIdentifier.of("a", "t1");
   
           if (requiresNamespaceCreate()) {
               catalog.createNamespace(identifier.namespace());
           }
   
           ((ViewCatalog) catalog)
                   .buildView(identifier)
                   .withSchema(SCHEMA)
                   .withDefaultNamespace(identifier.namespace())
                   .withDefaultCatalog(catalog().name())
                   .withQuery("spark", "select * from ns.tbl")
                   .create();
           assertThat(((ViewCatalog)catalog).viewExists(identifier)).as("View 
should exist").isTrue();
   
           assertThatThrownBy(() -> catalog.createTable(identifier, SCHEMA))
                   .isInstanceOf(AlreadyExistsException.class)
                   .hasMessageStartingWith("View with same name already exists: 
a.t1");
   
           Table table = catalog.createTable(TableIdentifier.of("a", "temp"), 
SCHEMA);
           String metadataLocation = ((BaseTable) 
table).operations().current().metadataFileLocation();
   
           assertThatThrownBy(() -> catalog.registerTable(identifier, 
metadataLocation))
                   .isInstanceOf(AlreadyExistsException.class)
                   .hasMessageStartingWith("Table already exists: a.t1");
           assertThat(catalog.dropTable(identifier)).isTrue();
       }
   ```



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