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


##########
nessie/src/main/java/org/apache/iceberg/nessie/NessieIcebergClient.java:
##########
@@ -378,27 +400,72 @@ 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 with same name already 
exists", from, to);
+      }
+    }
+  }
+
+  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 UnsupportedOperationException("Cannot perform rename for 
content type: " + type);
+      }
+    } else if (existingFromContent.getType() != type) {
+      throw new UnsupportedOperationException(
+          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 =
+        asContent(
+            identifier, type == Content.Type.ICEBERG_VIEW ? IcebergView.class 
: IcebergTable.class);

Review Comment:
   updated



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