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

##########
nessie/src/main/java/org/apache/iceberg/nessie/NessieIcebergClient.java:
##########
@@ -448,33 +480,85 @@ public void renameTable(TableIdentifier from, 
TableIdentifier to) {
     // behavior. So better be safe than sorry.
   }
 
+  private static void validateToContentForRename(
+      TableIdentifier from, TableIdentifier to, IcebergContent 
existingToContent) {
+    if (existingToContent != null) {
+      if (existingToContent.getType() == Content.Type.ICEBERG_VIEW) {
+        throw new AlreadyExistsException("Cannot rename %s to %s. View already 
exists", from, to);
+      } else if (existingToContent.getType() == Content.Type.ICEBERG_TABLE) {
+        throw new AlreadyExistsException("Cannot rename %s to %s. Table 
already exists", from, to);
+      } else {
+        throw new AlreadyExistsException(
+            "Cannot rename %s to %s. Another content of type %s with same name 
already exists",
+            from, to, existingToContent.getType());
+      }
+    }
+  }
+
+  private static void validateFromContentForRename(
+      TableIdentifier from, Content.Type type, IcebergContent 
existingFromContent) {
+    if (existingFromContent == null) {
+      if (type == Content.Type.ICEBERG_VIEW) {
+        throw new NoSuchViewException("View does not exist: %s", from);
+      } else if (type == Content.Type.ICEBERG_TABLE) {
+        throw new NoSuchTableException("Table does not exist: %s", from);
+      } else {
+        throw new RuntimeException("Cannot perform rename for content type: " 
+ type);
+      }
+    } else if (existingFromContent.getType() != type) {
+      throw new RuntimeException(
+          String.format("content type of from identifier %s should be of %s", 
from, type));
+    }
+  }
+
   public boolean dropTable(TableIdentifier identifier, boolean purge) {
+    return dropContent(identifier, purge, Content.Type.ICEBERG_TABLE);
+  }
+
+  public boolean dropView(TableIdentifier identifier, boolean purge) {
+    return dropContent(identifier, purge, Content.Type.ICEBERG_VIEW);
+  }
+
+  private boolean dropContent(TableIdentifier identifier, boolean purge, 
Content.Type type) {
     getRef().checkMutable();
 
-    IcebergTable existingTable = table(identifier);
-    if (existingTable == null) {
+    IcebergContent existingContent = fetchContent(identifier);
+    if (existingContent == null) {
       return false;
     }
 
+    if (existingContent.getType() != type) {
+      throw new RuntimeException(
+          String.format(
+              "Cannot drop %s: not matching with the type `%s`",
+              identifier, NessieUtil.contentTypeString(type)));
+    }
+
+    String contentType = 
NessieUtil.contentTypeString(type).toLowerCase(Locale.ENGLISH);
+
     if (purge) {
-      LOG.info("Purging data for table {} was set to true but is ignored", 
identifier.toString());
+      LOG.info(
+          "Purging data for {} {} was set to true but is ignored",
+          contentType,
+          identifier.toString());
     }
 
-    // We try to drop the table. Simple retry after ref update.
+    // We try to drop the content. Simple retry after ref update.
     try {
       commitRetry(
           String.format("Iceberg delete table %s", identifier),

Review Comment:
   good catch. Induced during rebase. 



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