-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-37888][SQL][TESTS] Unify v1 and v2 DESCRIBE TABLE tests
#36912
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 all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
28b0e56
Unify v1 and v2 DESCRIBE TABLE tests
MaxGekk 6866b76
Add the test Table Ownership
MaxGekk bf9926e
Check Hive calls
MaxGekk c7cfc0f
Move the test "DESCRIBE TABLE with non-'partitioned-by' clause"
MaxGekk 644cc9a
Add v2 DescribeTableSuite
MaxGekk c5deb5a
Add v1 specific test
MaxGekk 8c6caed
Add the test "Describing a partition is not supported"
MaxGekk 974f370
Move the test "DESCRIBE TABLE in a catalog when table does not exist"
MaxGekk 3bcde64
Move the test DESCRIBE TABLE EXTENDED of a partitioned table
MaxGekk 5e792ec
A test for DESCRIBE TABLE EXTENDED
MaxGekk b20993e
Move tests from DataSourceV2SQLSuite
MaxGekk 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
39 changes: 39 additions & 0 deletions
39
...core/src/test/scala/org/apache/spark/sql/execution/command/DescribeTableParserSuite.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,39 @@ | ||
| /* | ||
| * 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, UnresolvedTableOrView} | ||
| import org.apache.spark.sql.catalyst.parser.CatalystSqlParser.parsePlan | ||
| import org.apache.spark.sql.catalyst.plans.logical.DescribeRelation | ||
|
|
||
| class DescribeTableParserSuite extends AnalysisTest { | ||
| test("SPARK-17328: Fix NPE with EXPLAIN DESCRIBE TABLE") { | ||
| comparePlans(parsePlan("describe t"), | ||
| DescribeRelation( | ||
| UnresolvedTableOrView(Seq("t"), "DESCRIBE TABLE", true), Map.empty, isExtended = false)) | ||
| comparePlans(parsePlan("describe table t"), | ||
| DescribeRelation( | ||
| UnresolvedTableOrView(Seq("t"), "DESCRIBE TABLE", true), Map.empty, isExtended = false)) | ||
| comparePlans(parsePlan("describe table extended t"), | ||
| DescribeRelation( | ||
| UnresolvedTableOrView(Seq("t"), "DESCRIBE TABLE", true), Map.empty, isExtended = true)) | ||
| comparePlans(parsePlan("describe table formatted t"), | ||
| DescribeRelation( | ||
| UnresolvedTableOrView(Seq("t"), "DESCRIBE TABLE", true), Map.empty, isExtended = true)) | ||
| } | ||
| } |
87 changes: 87 additions & 0 deletions
87
sql/core/src/test/scala/org/apache/spark/sql/execution/command/DescribeTableSuiteBase.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,87 @@ | ||
| /* | ||
| * 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} | ||
| import org.apache.spark.sql.types.{BooleanType, MetadataBuilder, StringType, StructType} | ||
|
|
||
| /** | ||
| * This base suite contains unified tests for the `DESCRIBE TABLE` 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.DescribeTableSuite` | ||
| * - V1 table catalog tests: | ||
| * `org.apache.spark.sql.execution.command.v1.DescribeTableSuiteBase` | ||
| * - V1 In-Memory catalog: `org.apache.spark.sql.execution.command.v1.DescribeTableSuite` | ||
| * - V1 Hive External catalog: | ||
| * `org.apache.spark.sql.hive.execution.command.DescribeTableSuite` | ||
| */ | ||
| trait DescribeTableSuiteBase extends QueryTest with DDLCommandTestUtils { | ||
| override val command = "DESCRIBE TABLE" | ||
|
|
||
| test("DESCRIBE TABLE in a catalog when table does not exist") { | ||
| withNamespaceAndTable("ns", "table") { tbl => | ||
| val e = intercept[AnalysisException] { | ||
| sql(s"DESCRIBE TABLE ${tbl}_non_existence") | ||
| } | ||
| assert(e.getMessage.contains(s"Table or view not found: ${tbl}_non_existence")) | ||
| } | ||
| } | ||
|
|
||
| test("SPARK-34561: drop/add columns to a dataset of `DESCRIBE TABLE`") { | ||
| withNamespaceAndTable("ns", "table") { tbl => | ||
| sql(s"CREATE TABLE $tbl (c0 INT) $defaultUsing") | ||
| val description = sql(s"DESCRIBE TABLE $tbl") | ||
| val noCommentDataset = description.drop("comment") | ||
| val expectedSchema = new StructType() | ||
| .add( | ||
| name = "col_name", | ||
| dataType = StringType, | ||
| nullable = false, | ||
| metadata = new MetadataBuilder().putString("comment", "name of the column").build()) | ||
| .add( | ||
| name = "data_type", | ||
| dataType = StringType, | ||
| nullable = false, | ||
| metadata = new MetadataBuilder().putString("comment", "data type of the column").build()) | ||
| assert(noCommentDataset.schema === expectedSchema) | ||
| val isNullDataset = noCommentDataset | ||
| .withColumn("is_null", noCommentDataset("col_name").isNull) | ||
| assert(isNullDataset.schema === expectedSchema.add("is_null", BooleanType, false)) | ||
| } | ||
| } | ||
|
|
||
| test("SPARK-34576: drop/add columns to a dataset of `DESCRIBE COLUMN`") { | ||
| withNamespaceAndTable("ns", "table") { tbl => | ||
| sql(s"CREATE TABLE $tbl (c0 INT) $defaultUsing") | ||
| val description = sql(s"DESCRIBE TABLE $tbl c0") | ||
| val noCommentDataset = description.drop("info_value") | ||
| val expectedSchema = new StructType() | ||
| .add( | ||
| name = "info_name", | ||
| dataType = StringType, | ||
| nullable = false, | ||
| metadata = new MetadataBuilder().putString("comment", "name of the column info").build()) | ||
| assert(noCommentDataset.schema === expectedSchema) | ||
| val isNullDataset = noCommentDataset | ||
| .withColumn("is_null", noCommentDataset("info_name").isNull) | ||
| assert(isNullDataset.schema === expectedSchema.add("is_null", BooleanType, false)) | ||
| } | ||
| } | ||
| } |
106 changes: 106 additions & 0 deletions
106
sql/core/src/test/scala/org/apache/spark/sql/execution/command/v1/DescribeTableSuite.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,106 @@ | ||
| /* | ||
| * 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.{AnalysisException, QueryTest, Row} | ||
| import org.apache.spark.sql.execution.command | ||
| import org.apache.spark.sql.types.StringType | ||
|
|
||
| /** | ||
| * This base suite contains unified tests for the `DESCRIBE TABLE` 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.DescribeTableSuite` | ||
| * - V1 Hive External catalog: | ||
| * `org.apache.spark.sql.hive.execution.command.DescribeTableSuite` | ||
| */ | ||
| trait DescribeTableSuiteBase extends command.DescribeTableSuiteBase | ||
| with command.TestsV1AndV2Commands { | ||
|
|
||
| test("DESCRIBE TABLE with non-'partitioned-by' clause") { | ||
| withNamespaceAndTable("ns", "table") { tbl => | ||
| spark.sql(s"CREATE TABLE $tbl (id bigint, data string) $defaultUsing") | ||
| val descriptionDf = spark.sql(s"DESCRIBE TABLE $tbl") | ||
| assert(descriptionDf.schema.map(field => (field.name, field.dataType)) === | ||
| Seq( | ||
| ("col_name", StringType), | ||
| ("data_type", StringType), | ||
| ("comment", StringType))) | ||
| QueryTest.checkAnswer( | ||
| descriptionDf, | ||
| Seq( | ||
| Row("data", "string", null), | ||
| Row("id", "bigint", null))) | ||
| } | ||
| } | ||
|
|
||
| test("Describing a partition is not supported") { | ||
| withNamespaceAndTable("ns", "table") { tbl => | ||
| spark.sql(s"CREATE TABLE $tbl (id bigint, data string) $defaultUsing " + | ||
| "PARTITIONED BY (id)") | ||
| val e = intercept[AnalysisException] { | ||
| sql(s"DESCRIBE TABLE $tbl PARTITION (id = 1)") | ||
| } | ||
| assert(e.message === "Partition not found in table 'table' database 'ns':\nid -> 1") | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * The class contains tests for the `DESCRIBE TABLE` command to check V1 In-Memory | ||
| * table catalog. | ||
| */ | ||
| class DescribeTableSuite extends DescribeTableSuiteBase with CommandSuiteBase { | ||
| override def commandVersion: String = super[DescribeTableSuiteBase].commandVersion | ||
|
|
||
| test("DESCRIBE TABLE EXTENDED of a partitioned table") { | ||
| withNamespaceAndTable("ns", "table") { tbl => | ||
| spark.sql(s"CREATE TABLE $tbl (id bigint, data string) $defaultUsing" + | ||
| " PARTITIONED BY (id)" + | ||
| " TBLPROPERTIES ('bar'='baz')" + | ||
| " COMMENT 'this is a test table'" + | ||
| " LOCATION 'file:/tmp/testcat/table_name'") | ||
| val descriptionDf = spark.sql(s"DESCRIBE TABLE EXTENDED $tbl") | ||
| assert(descriptionDf.schema.map(field => (field.name, field.dataType)) === Seq( | ||
| ("col_name", StringType), | ||
| ("data_type", StringType), | ||
| ("comment", StringType))) | ||
| QueryTest.checkAnswer( | ||
| descriptionDf.filter("col_name != 'Created Time'"), | ||
| Seq( | ||
| Row("data", "string", null), | ||
| Row("id", "bigint", null), | ||
| Row("# Partition Information", "", ""), | ||
| Row("# col_name", "data_type", "comment"), | ||
| Row("id", "bigint", null), | ||
| Row("", "", ""), | ||
| Row("# Detailed Table Information", "", ""), | ||
| Row("Database", "ns", ""), | ||
| Row("Table", "table", ""), | ||
| Row("Last Access", "UNKNOWN", ""), | ||
| Row("Created By", "Spark 3.4.0-SNAPSHOT", ""), | ||
| Row("Type", "EXTERNAL", ""), | ||
| Row("Provider", "parquet", ""), | ||
| Row("Comment", "this is a test table", ""), | ||
| Row("Table Properties", "[bar=baz]", ""), | ||
| Row("Location", "file:/tmp/testcat/table_name", ""), | ||
| Row("Partition Provider", "Catalog", ""))) | ||
| } | ||
| } | ||
| } | ||
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.
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.
we should filter out this row as well, otherwise we need to keep updating this test when making a new release. cc @MaxGekk
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.
Will do in another PR for
DESCRIBE TABLEtests.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.
Next time, let's address comments immediately. We missed fixing it in the next PR...