-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[SPARK-37478][SQL][TESTS] Unify v1 and v2 DROP NAMESPACE tests #34819
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| /* | ||
| * 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.catalyst.analysis.{AnalysisTest, UnresolvedNamespace} | ||
| import org.apache.spark.sql.catalyst.parser.CatalystSqlParser.parsePlan | ||
| import org.apache.spark.sql.catalyst.plans.logical.DropNamespace | ||
|
|
||
| class DropNamespaceParserSuite extends AnalysisTest { | ||
| test("drop namespace") { | ||
| comparePlans( | ||
| parsePlan("DROP NAMESPACE a.b.c"), | ||
| DropNamespace( | ||
| UnresolvedNamespace(Seq("a", "b", "c")), ifExists = false, cascade = false)) | ||
|
|
||
| comparePlans( | ||
| parsePlan("DROP NAMESPACE IF EXISTS a.b.c"), | ||
| DropNamespace( | ||
| UnresolvedNamespace(Seq("a", "b", "c")), ifExists = true, cascade = false)) | ||
|
|
||
| comparePlans( | ||
| parsePlan("DROP NAMESPACE IF EXISTS a.b.c RESTRICT"), | ||
| DropNamespace( | ||
| UnresolvedNamespace(Seq("a", "b", "c")), ifExists = true, cascade = false)) | ||
|
|
||
| comparePlans( | ||
| parsePlan("DROP NAMESPACE IF EXISTS a.b.c CASCADE"), | ||
| DropNamespace( | ||
| UnresolvedNamespace(Seq("a", "b", "c")), ifExists = true, cascade = true)) | ||
|
|
||
| comparePlans( | ||
| parsePlan("DROP NAMESPACE a.b.c CASCADE"), | ||
| DropNamespace( | ||
| UnresolvedNamespace(Seq("a", "b", "c")), ifExists = false, cascade = true)) | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -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") | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we consistently use |
||||||
| }.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 | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| 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") { | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: this is the drop namespace test suite, do we really need to put the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, will remove it. Thanks! |
||||||
| Seq(true, false).foreach { caseSensitive => | ||||||
| withSQLConf(SQLConf.CASE_SENSITIVE.key -> caseSensitive.toString) { | ||||||
| sql(s"CREATE NAMESPACE $catalog.AAA") | ||||||
| sql(s"CREATE NAMESPACE $catalog.bbb") | ||||||
| // TODO: The v1 in-memory catalog should be case preserving as well. | ||||||
| val casePreserving = isCasePreserving && (catalogVersion == "V2" || caseSensitive) | ||||||
| val expected = if (casePreserving) "AAA" else "aaa" | ||||||
|
|
||||||
| sql(s"DROP NAMESPACE $catalog.$expected") | ||||||
| sql(s"DROP NAMESPACE $catalog.bbb") | ||||||
| checkNamespace(builtinTopNamespaces) | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.