ebyhr commented on code in PR #12511:
URL: https://github.com/apache/iceberg/pull/12511#discussion_r1994676612


##########
core/src/main/java/org/apache/iceberg/jdbc/JdbcCatalog.java:
##########
@@ -612,6 +613,14 @@ public boolean dropView(TableIdentifier identifier) {
       throw new UnsupportedOperationException(VIEW_WARNING_LOG_MESSAGE);
     }
 
+    JdbcViewOperations ops = (JdbcViewOperations) newViewOps(identifier);
+    ViewMetadata lastViewMetadata = null;
+    try {
+      lastViewMetadata = ops.current();
+    } catch (NotFoundException e) {

Review Comment:
   When does `ops.current()` method throw `NotFoundException`? I think it 
throws `NoSuchViewException`.



##########
core/src/test/java/org/apache/iceberg/jdbc/TestJdbcViewCatalog.java:
##########
@@ -138,4 +142,50 @@ public void testCommitExceptionWithMessage() {
           .hasMessageStartingWith("View already exists: " + identifier);
     }
   }
+
+  @Test
+  public void dropViewShouldNotDropMetadataFileIfGcNotEnabled() throws 
IOException {
+    TableIdentifier identifier = TableIdentifier.of("namespace1", "view");
+    BaseView view =
+        (BaseView)
+            catalog
+                .buildView(identifier)
+                .withQuery("spark", "select * from tbl")
+                .withSchema(SCHEMA)
+                .withDefaultNamespace(Namespace.of("namespace1"))
+                .withProperty(TableProperties.GC_ENABLED, "false")
+                .create();
+
+    assertThat(catalog.viewExists(identifier)).isTrue();
+    String metadataFileLocation = 
view.operations().current().metadataFileLocation();
+    assertThat(metadataFileLocation).isNotNull();
+    File currentMetadataLocation = new File(metadataFileLocation);
+
+    catalog.dropView(identifier);
+    assertThat(currentMetadataLocation.exists()).isTrue();

Review Comment:
   AssertJ has a method to verify a file existence:
   ```suggestion
       assertThat(currentMetadataLocation).exists();
   ```



##########
core/src/test/java/org/apache/iceberg/jdbc/TestJdbcViewCatalog.java:
##########
@@ -138,4 +142,50 @@ public void testCommitExceptionWithMessage() {
           .hasMessageStartingWith("View already exists: " + identifier);
     }
   }
+
+  @Test
+  public void dropViewShouldNotDropMetadataFileIfGcNotEnabled() throws 
IOException {

Review Comment:
   Why do we want to test only JDBC catalog? 
   
   Can we add `test` prefix for consistency with other test methods? Also, 
`throws IOException` is redundant. 
   
    Same for another test.



##########
core/src/test/java/org/apache/iceberg/jdbc/TestJdbcViewCatalog.java:
##########
@@ -138,4 +142,50 @@ public void testCommitExceptionWithMessage() {
           .hasMessageStartingWith("View already exists: " + identifier);
     }
   }
+
+  @Test
+  public void dropViewShouldNotDropMetadataFileIfGcNotEnabled() throws 
IOException {
+    TableIdentifier identifier = TableIdentifier.of("namespace1", "view");
+    BaseView view =
+        (BaseView)
+            catalog
+                .buildView(identifier)
+                .withQuery("spark", "select * from tbl")
+                .withSchema(SCHEMA)
+                .withDefaultNamespace(Namespace.of("namespace1"))
+                .withProperty(TableProperties.GC_ENABLED, "false")
+                .create();
+
+    assertThat(catalog.viewExists(identifier)).isTrue();
+    String metadataFileLocation = 
view.operations().current().metadataFileLocation();
+    assertThat(metadataFileLocation).isNotNull();
+    File currentMetadataLocation = new File(metadataFileLocation);
+
+    catalog.dropView(identifier);
+    assertThat(currentMetadataLocation.exists()).isTrue();
+    assertThat(catalog.viewExists(identifier)).isFalse();
+  }
+
+  @Test
+  public void dropViewShouldDropMetadataFileIfGcEnabled() throws IOException {
+    TableIdentifier identifier = TableIdentifier.of("namespace1", "view");
+    BaseView view =
+        (BaseView)
+            catalog
+                .buildView(identifier)
+                .withQuery("spark", "select * from tbl")
+                .withSchema(SCHEMA)
+                .withDefaultNamespace(Namespace.of("namespace1"))
+                .withProperty(TableProperties.GC_ENABLED, "true")
+                .create();
+
+    assertThat(catalog.viewExists(identifier)).isTrue();
+    String metadataFileLocation = 
view.operations().current().metadataFileLocation();
+    assertThat(metadataFileLocation).isNotNull();
+    File currentMetadataLocation = new File(metadataFileLocation);
+
+    catalog.dropView(identifier);
+    assertThat(currentMetadataLocation.exists()).isFalse();

Review Comment:
   ```suggestion
       assertThat(currentMetadataLocation).doesNotExist();
   ```



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