-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-37031][SQL][TESTS] Unify v1 and v2 DESCRIBE NAMESPACE tests #34305
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
Closed
Closed
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
d44f56e
initial commit
imback82 ab5532c
Merge branch 'master' into migrate_desc_namespace
imback82 69ab022
address PR comments
imback82 002b4e7
minor fix
imback82 2640444
update variable name
imback82 174aedd
Update DescribeNamespaceParserSuite.scala
cloud-fan cecd0a6
Update sql/core/src/test/scala/org/apache/spark/sql/execution/command…
cloud-fan a5c1492
fix compilation error
imback82 a8820ab
add back with TODO
imback82 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
.../src/test/scala/org/apache/spark/sql/execution/command/DescribeNamespaceParserSuite.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| /* | ||
| * 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.DescribeNamespace | ||
|
|
||
| class DescribeNamespaceParserSuite extends AnalysisTest { | ||
| test("describe namespace") { | ||
| val sql1 = "DESCRIBE NAMESPACE EXTENDED a.b" | ||
| val sql2 = "DESCRIBE NAMESPACE a.b" | ||
| comparePlans(parsePlan(sql1), | ||
| DescribeNamespace(UnresolvedNamespace(Seq("a", "b")), extended = true)) | ||
| comparePlans(parsePlan(sql2), | ||
| DescribeNamespace(UnresolvedNamespace(Seq("a", "b")), extended = false)) | ||
| } | ||
| } |
51 changes: 51 additions & 0 deletions
51
...re/src/test/scala/org/apache/spark/sql/execution/command/DescribeNamespaceSuiteBase.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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.{AnalysisException, QueryTest} | ||
|
|
||
| /** | ||
| * This base suite contains unified tests for the `DESCRIBE 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.DescribeNamespaceSuite` | ||
| * - V1 table catalog tests: | ||
| * `org.apache.spark.sql.execution.command.v1.DescribeNamespaceSuiteBase` | ||
| * - V1 In-Memory catalog: `org.apache.spark.sql.execution.command.v1.DescribeNamespaceSuite` | ||
| * - V1 Hive External catalog: | ||
| * `org.apache.spark.sql.hive.execution.command.DescribeNamespaceSuite` | ||
| */ | ||
| trait DescribeNamespaceSuiteBase extends QueryTest with DDLCommandTestUtils with CommandTestUtils { | ||
| override val command = "DESCRIBE NAMESPACE" | ||
|
|
||
| test("namespace does not exists") { | ||
| val databaseNames = Seq("db1", "`database`") | ||
| databaseNames.foreach { dbName => | ||
| val dbNameWithoutBackTicks = cleanIdentifier(dbName) | ||
| val message = intercept[AnalysisException] { | ||
| sql(s"DESCRIBE NAMESPACE EXTENDED $catalog.$dbName") | ||
| }.getMessage | ||
|
|
||
| val prefix = if (catalogVersion == "V2") "Namespace" else "Database" | ||
imback82 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| assert(message.contains(s"$prefix '$dbNameWithoutBackTicks' not found")) | ||
|
|
||
| sql(s"DROP NAMESPACE IF EXISTS $catalog.$dbName") | ||
| } | ||
| } | ||
| } | ||
60 changes: 60 additions & 0 deletions
60
...ore/src/test/scala/org/apache/spark/sql/execution/command/v1/DescribeNamespaceSuite.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| /* | ||
| * 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.v1 | ||
|
|
||
| import org.apache.spark.sql.Row | ||
| import org.apache.spark.sql.catalyst.catalog.CatalogUtils | ||
| import org.apache.spark.sql.execution.command | ||
|
|
||
| /** | ||
| * This base suite contains unified tests for the `DESCRIBE NAMESPACE` command that checks V1 | ||
| * table catalogs. The tests that cannot run for all V1 catalogs are located in more | ||
| * specific test suites: | ||
| * | ||
| * - V1 In-Memory catalog: `org.apache.spark.sql.execution.command.v1.DescribeNamespaceSuite` | ||
| * - V1 Hive External catalog: | ||
| * `org.apache.spark.sql.hive.execution.command.DescribeNamespaceSuite` | ||
| */ | ||
| trait DescribeNamespaceSuiteBase extends command.DescribeNamespaceSuiteBase { | ||
| test("basic") { | ||
| val namespaceNames = Seq("db1", "`database`") | ||
| withNamespace(namespaceNames: _*) { | ||
| namespaceNames.foreach { ns => | ||
| val dbNameWithoutBackTicks = cleanIdentifier(ns) | ||
imback82 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| val location = getDBPath(dbNameWithoutBackTicks) | ||
|
|
||
| sql(s"CREATE NAMESPACE $ns") | ||
|
|
||
| checkAnswer( | ||
| sql(s"DESCRIBE NAMESPACE EXTENDED $ns") | ||
| .toDF("key", "value") | ||
| .where("key not like 'Owner%'"), // filter for consistency with in-memory catalog | ||
| Row("Database Name", dbNameWithoutBackTicks) :: | ||
| Row("Comment", "") :: | ||
| Row("Location", CatalogUtils.URIToString(location)) :: | ||
imback82 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Row("Properties", "") :: Nil) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * The class contains tests for the `DESCRIBE NAMESPACE` command to check V1 In-Memory | ||
| * table catalog. | ||
| */ | ||
| class DescribeNamespaceSuite extends DescribeNamespaceSuiteBase with CommandSuiteBase | ||
68 changes: 68 additions & 0 deletions
68
...ore/src/test/scala/org/apache/spark/sql/execution/command/v2/DescribeNamespaceSuite.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| /* | ||
| * 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.v2 | ||
|
|
||
| import org.apache.spark.sql.Row | ||
| import org.apache.spark.sql.connector.catalog.SupportsNamespaces | ||
| import org.apache.spark.sql.execution.command | ||
| import org.apache.spark.sql.types.{BooleanType, MetadataBuilder, StringType, StructType} | ||
| import org.apache.spark.util.Utils | ||
|
|
||
| /** | ||
| * The class contains tests for the `DESCRIBE NAMESPACE` command to check V2 table catalogs. | ||
| */ | ||
| class DescribeNamespaceSuite extends command.DescribeNamespaceSuiteBase with CommandSuiteBase { | ||
| test("DescribeNamespace using v2 catalog") { | ||
| withNamespace("test_catalog.ns1.ns2") { | ||
imback82 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| sql("CREATE NAMESPACE IF NOT EXISTS test_catalog.ns1.ns2 COMMENT " + | ||
| "'test namespace' LOCATION '/tmp/ns_test'") | ||
| val descriptionDf = sql("DESCRIBE NAMESPACE test_catalog.ns1.ns2") | ||
| assert(descriptionDf.schema.map(field => (field.name, field.dataType)) === | ||
| Seq( | ||
| ("info_name", StringType), | ||
| ("info_value", StringType) | ||
| )) | ||
| val description = descriptionDf.collect() | ||
| assert(description === Seq( | ||
| Row("Namespace Name", "ns2"), | ||
| Row(SupportsNamespaces.PROP_COMMENT.capitalize, "test namespace"), | ||
| Row(SupportsNamespaces.PROP_LOCATION.capitalize, "/tmp/ns_test"), | ||
| Row(SupportsNamespaces.PROP_OWNER.capitalize, Utils.getCurrentUserName())) | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| test("SPARK-34577: drop/add columns to a dataset of `DESCRIBE NAMESPACE`") { | ||
| withNamespace("ns") { | ||
| sql("CREATE NAMESPACE ns") | ||
| val description = sql(s"DESCRIBE NAMESPACE ns") | ||
| val noCommentDataset = description.drop("info_name") | ||
| val expectedSchema = new StructType() | ||
| .add( | ||
| name = "info_value", | ||
| dataType = StringType, | ||
| nullable = true, | ||
| metadata = new MetadataBuilder() | ||
| .putString("comment", "value of the namespace info").build()) | ||
| assert(noCommentDataset.schema === expectedSchema) | ||
| val isNullDataset = noCommentDataset | ||
| .withColumn("is_null", noCommentDataset("info_value").isNull) | ||
| assert(isNullDataset.schema === expectedSchema.add("is_null", BooleanType, false)) | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.