dchvn commented on a change in pull request #34819:
URL: https://github.com/apache/spark/pull/34819#discussion_r763683507



##########
File path: 
sql/core/src/test/scala/org/apache/spark/sql/execution/command/DropNamespaceSuiteBase.scala
##########
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark.sql.execution.command
+
+import org.apache.spark.sql.{AnalysisException, QueryTest, Row}
+import org.apache.spark.sql.internal.SQLConf
+import org.apache.spark.sql.types.{StringType, StructType}
+
+/**
+ * This base suite contains unified tests for the `DROP NAMESPACE` command 
that check V1 and V2
+ * table catalogs. The tests that cannot run for all supported catalogs are 
located in more
+ * specific test suites:
+ *
+ *   - V2 table catalog tests: 
`org.apache.spark.sql.execution.command.v2.DropNamespaceSuite`
+ *   - V1 table catalog tests: 
`org.apache.spark.sql.execution.command.v1.DropNamespaceSuiteBase`
+ *     - V1 In-Memory catalog: 
`org.apache.spark.sql.execution.command.v1.DropNamespaceSuite`
+ *     - V1 Hive External catalog: 
`org.apache.spark.sql.hive.execution.command.DropNamespaceSuite`
+ */
+trait DropNamespaceSuiteBase extends QueryTest with DDLCommandTestUtils {
+  override val command = "DROP NAMESPACE"
+
+  protected def builtinTopNamespaces: Seq[String] = Seq.empty
+  protected def isCasePreserving: Boolean = true
+  protected def assertDropFails
+
+  protected def checkNamespace(expected: Seq[String]) = {
+    val df = spark.sql(s"SHOW NAMESPACES IN $catalog")
+    assert(df.schema === new StructType().add("namespace", StringType, false))
+    checkAnswer(df, expected.map(Row(_)))
+  }
+
+  test("basic tests") {
+    sql(s"CREATE NAMESPACE $catalog.ns")
+    checkNamespace(Seq("ns") ++ builtinTopNamespaces)
+
+    sql(s"DROP NAMESPACE $catalog.ns")
+    checkNamespace(builtinTopNamespaces)
+  }
+
+  test("DropNamespace: test handling of 'IF EXISTS'") {
+    // It must not throw any exceptions
+    sql(s"DROP NAMESPACE IF EXISTS $catalog.unknown")
+    checkNamespace(builtinTopNamespaces)
+  }
+
+  test("DropNamespace: Namespace does not exist") {
+    // Namespace $catalog.unknown does not exist.
+    val message = intercept[AnalysisException] {
+      sql(s"DROP DATABASE $catalog.unknown")
+    }.getMessage
+    assert(message.contains(s"'unknown' not found"))
+  }
+
+  test("DropNamespace: drop non-empty namespace with a non-cascading mode") {
+    sql(s"CREATE NAMESPACE $catalog.ns")
+    sql(s"CREATE TABLE $catalog.ns.table (id bigint) $defaultUsing")
+    checkNamespace(Seq("ns") ++ builtinTopNamespaces)
+
+    // $catalog.ns.table is present, thus $catalog.ns cannot be dropped.
+    assertDropFails
+    sql(s"DROP TABLE $catalog.ns.table")
+
+    // Now that $catalog.ns is empty, it can be dropped.
+    sql(s"DROP NAMESPACE $catalog.ns")
+    checkNamespace(builtinTopNamespaces)
+  }
+
+  test("DropNamespace: drop non-empty namespace with a cascade mode") {
+    sql(s"CREATE NAMESPACE $catalog.ns")
+    sql(s"CREATE TABLE $catalog.ns.table (id bigint) $defaultUsing")
+    checkNamespace(Seq("ns") ++ builtinTopNamespaces)
+
+    sql(s"DROP NAMESPACE $catalog.ns CASCADE")
+    checkNamespace(builtinTopNamespaces)
+  }
+
+  test("DropNamespace: drop current namespace") {
+    sql(s"CREATE NAMESPACE $catalog.ns")
+    sql(s"USE $catalog.ns")
+    sql(s"DROP NAMESPACE $catalog.ns")
+    checkNamespace(builtinTopNamespaces)
+  }
+
+  test("DropNamespace: drop namespace with case sensitivity") {

Review comment:
       yeah, will remove it. Thanks!




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