kbendick commented on a change in pull request #3573:
URL: https://github.com/apache/iceberg/pull/3573#discussion_r752023139



##########
File path: 
spark/v3.2/spark/src/test/java/org/apache/iceberg/spark/sql/TestNamespaceSQL.java
##########
@@ -100,12 +97,94 @@ public void testDropNonEmptyNamespace() {
     Assert.assertTrue("Table should exist", 
validationCatalog.tableExists(TableIdentifier.of(NS, "table")));
 
     AssertHelpers.assertThrows("Should fail if trying to delete a non-empty 
namespace",
-        SparkException.class, "non-empty namespace",
+        Exception.class, "empty",
         () -> sql("DROP NAMESPACE %s", fullNamespace));
 
     sql("DROP TABLE %s.table", fullNamespace);
   }
 
+  @Test
+  public void testDropNonEmptyNamespaceOnCascade() {
+    Assert.assertFalse("Namespace should not already exist", 
validationNamespaceCatalog.namespaceExists(NS));
+
+    sql("CREATE NAMESPACE %s", fullNamespace);
+    sql("CREATE TABLE %s.table (id bigint) USING iceberg", fullNamespace);
+
+    Assert.assertTrue("Namespace should exist", 
validationNamespaceCatalog.namespaceExists(NS));
+    Assert.assertTrue("Table should exist", 
validationCatalog.tableExists(TableIdentifier.of(NS, "table")));
+
+    AssertHelpers.assertThrows("Should fail if trying to delete a non-empty 
namespace",
+        Exception.class, "empty",
+        () -> sql("DROP NAMESPACE %s", fullNamespace));
+
+    List<Object[]> namespaces = sql("SHOW NAMESPACES IN %s", catalogName);
+    if (isHadoopCatalog) {
+      Assert.assertEquals("Should have 1 namespace", 1, namespaces.size());
+      Set<String> namespaceNames = namespaces.stream().map(arr -> 
arr[0].toString()).collect(Collectors.toSet());
+      Assert.assertEquals("Should have only db namespace", 
ImmutableSet.of("db"), namespaceNames);
+    } else {
+      Assert.assertEquals("Should have 2 namespaces", 2, namespaces.size());
+      Set<String> namespaceNames = namespaces.stream().map(arr -> 
arr[0].toString()).collect(Collectors.toSet());
+      Assert.assertEquals("Should have default and db namespaces", 
ImmutableSet.of("default", "db"), namespaceNames);
+    }
+
+    sql("SHOW NAMESPACES in %s", catalogName).forEach(System.err::println);
+    // Assert.assertFalse("The namespace should still be present after 
attempting to delete without cascade",
+    //     sql("SHOW NAMESPACES in %s", catalogName).isEmpty());
+    sql("DROP NAMESPACE %s CASCADE", fullNamespace);
+    Assert.assertFalse(
+        "Namespace should not exist after deleting with CASCADE",
+        validationNamespaceCatalog.namespaceExists(NS));
+    Assert.assertFalse(
+        "Table should not exist after deleting its parent namespace with 
CASCADE",
+        validationCatalog.tableExists(TableIdentifier.of(NS, "table")));
+
+    // Clean up for other tests runs.
+    sql("DROP TABLE IF EXISTS %s.table", fullNamespace);
+  }
+
+  @Test
+  public void testDropNamespaceRespectsRestrictKeyword() {
+    Assert.assertFalse("Namespace should not already exist", 
validationNamespaceCatalog.namespaceExists(NS));
+
+    sql("CREATE NAMESPACE %s", fullNamespace);
+    sql("CREATE TABLE %s.table (id bigint) USING iceberg", fullNamespace);
+
+    Assert.assertTrue("Namespace should exist", 
validationNamespaceCatalog.namespaceExists(NS));
+    Assert.assertTrue("Table should exist", 
validationCatalog.tableExists(TableIdentifier.of(NS, "table")));
+
+    // TODO - Update this from Exception.class, but the excpetion changed now 
thaat we're following a new code path.
+    AssertHelpers.assertThrows("Should fail if trying to delete a non-empty 
namespace with RESTRICT",
+        Exception.class, "empty",
+        () -> sql("DROP NAMESPACE %s RESTRICT", fullNamespace));
+
+    // Check all expected namespaces are present
+    List<Object[]> namespaces = sql("SHOW NAMESPACES IN %s", catalogName);
+    if (isHadoopCatalog) {
+      Assert.assertEquals("Should have 1 namespace", 1, namespaces.size());
+      Set<String> namespaceNames = namespaces.stream().map(arr -> 
arr[0].toString()).collect(Collectors.toSet());
+      Assert.assertEquals("Should have only db namespace", 
ImmutableSet.of("db"), namespaceNames);
+    } else {
+      Assert.assertEquals("Should have 2 namespaces", 2, namespaces.size());
+      Set<String> namespaceNames = namespaces.stream().map(arr -> 
arr[0].toString()).collect(Collectors.toSet());
+      Assert.assertEquals("Should have default and db namespaces", 
ImmutableSet.of("default", "db"), namespaceNames);
+    }
+
+    // Might need to assert on contains (or just accept the above) because of 
default for non-hadoop.
+    Assert.assertFalse("The namespace should still be present after attempting 
to delete with restrict",
+        sql("SHOW NAMESPACES in %s", catalogName).isEmpty());

Review comment:
       TODO - Can just repeat the tests from 153 and 154 here (around the exact 
namespace and table existing).




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