-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-37195][SQL][TESTS] Unify v1 and v2 SHOW TBLPROPERTIES tests #34476
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 all 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,37 @@ | ||
| /* | ||
| * 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.ShowTableProperties | ||
|
|
||
| class ShowTblPropertiesParserSuite extends AnalysisTest { | ||
| test("show tblproperties") { | ||
| comparePlans( | ||
| parsePlan("SHOW TBLPROPERTIES a.b.c"), | ||
| ShowTableProperties( | ||
| UnresolvedTableOrView(Seq("a", "b", "c"), "SHOW TBLPROPERTIES", true), | ||
| None)) | ||
|
|
||
| comparePlans( | ||
| parsePlan("SHOW TBLPROPERTIES a.b.c('propKey1')"), | ||
| ShowTableProperties( | ||
| UnresolvedTableOrView(Seq("a", "b", "c"), "SHOW TBLPROPERTIES", true), Some("propKey1"))) | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| /* | ||
| * 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.types.{StringType, StructType} | ||
|
|
||
| /** | ||
| * This base suite contains unified tests for the `SHOW TBLPROPERTIES` 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.ShowTblPropertiesSuite` | ||
| * - V1 table catalog tests: | ||
| * `org.apache.spark.sql.execution.command.v1.ShowTblPropertiesSuiteBase` | ||
| * - V1 In-Memory catalog: `org.apache.spark.sql.execution.command.v1.ShowTblPropertiesSuite` | ||
| * - V1 Hive External catalog: | ||
| * `org.apache.spark.sql.hive.execution.command.ShowTblPropertiesSuite` | ||
| */ | ||
| trait ShowTblPropertiesSuiteBase extends QueryTest with DDLCommandTestUtils { | ||
| override val command = "SHOW TBLPROPERTIES" | ||
|
|
||
| test("SHOW TBLPROPERTIES BASIC") { | ||
| withNamespaceAndTable("ns1", "tbl") { tbl => | ||
| val user = "andrew" | ||
| val status = "new" | ||
| spark.sql(s"CREATE TABLE $tbl (id bigint, data string) $defaultUsing " + | ||
| s"TBLPROPERTIES ('user'='$user', 'status'='$status')") | ||
|
|
||
| val properties = sql(s"SHOW TBLPROPERTIES $tbl").filter("key != 'transient_lastDdlTime'") | ||
| val schema = new StructType() | ||
| .add("key", StringType, nullable = false) | ||
| .add("value", StringType, nullable = false) | ||
| val expected = Seq( | ||
| Row("status", status), | ||
| Row("user", user)) | ||
|
|
||
| assert(properties.schema === schema) | ||
| checkAnswer(properties.sort("key"), expected) | ||
|
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. v2: sort the result. v1: without the sort. So the test case sort the result before the compare
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. v1 should sort as well. We can fix this in a followup. |
||
| } | ||
| } | ||
|
|
||
| test("SHOW TBLPROPERTIES(KEY)") { | ||
| withNamespaceAndTable("ns1", "tbl") { tbl => | ||
| val user = "andrew" | ||
| val status = "new" | ||
| spark.sql(s"CREATE TABLE $tbl (id bigint, data string) $defaultUsing " + | ||
| s"TBLPROPERTIES ('user'='$user', 'status'='$status')") | ||
|
|
||
| val properties = sql(s"SHOW TBLPROPERTIES $tbl ('status')") | ||
| val expected = Seq(Row("status", status)) | ||
| checkAnswer(properties, expected) | ||
| } | ||
| } | ||
|
|
||
| test("SHOW TBLPROPERTIES WITH TABLE NOT EXIST") { | ||
| val message = intercept[AnalysisException] { | ||
| sql("SHOW TBLPROPERTIES BADTABLE") | ||
| }.getMessage | ||
| assert(message.contains("Table or view not found: BADTABLE")) | ||
| } | ||
|
|
||
| test("SHOW TBLPROPERTIES(KEY) KEY NOT FOUND") { | ||
| withNamespaceAndTable("ns1", "tbl") { tbl => | ||
| val nonExistingKey = "nonExistingKey" | ||
| spark.sql(s"CREATE TABLE $tbl (id bigint, data string) $defaultUsing " + | ||
| s"TBLPROPERTIES ('user'='andrew', 'status'='new')") | ||
|
|
||
| val res = sql(s"SHOW TBLPROPERTIES $tbl ('$nonExistingKey')").collect() | ||
| assert(res.length == 1) | ||
| assert(res.head.getString(0) == nonExistingKey) | ||
| assert(res.head.getString(1).contains(s"does not have property: $nonExistingKey")) | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| /* | ||
| * 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.execution.command | ||
| import org.apache.spark.sql.internal.SQLConf | ||
|
|
||
| /** | ||
| * This base suite contains unified tests for the `SHOW TBLPROPERTIES` 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.ShowTblPropertiesSuite` | ||
| * - V1 Hive External catalog: | ||
| * `org.apache.spark.sql.hive.execution.command.ShowTblPropertiesSuite` | ||
| */ | ||
| trait ShowTblPropertiesSuiteBase extends command.ShowTblPropertiesSuiteBase | ||
| with command.TestsV1AndV2Commands { | ||
|
|
||
| test("SHOW TBLPROPERTIES WITH LEGACY_KEEP_COMMAND_OUTPUT_SCHEMA") { | ||
| withNamespaceAndTable("ns1", "tbl") { tbl => | ||
| spark.sql(s"CREATE TABLE $tbl (id bigint, data string) $defaultUsing " + | ||
| s"TBLPROPERTIES ('user'='andrew', 'status'='new')") | ||
| withSQLConf(SQLConf.LEGACY_KEEP_COMMAND_OUTPUT_SCHEMA.key -> "true") { | ||
|
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. In V1. We can set |
||
| checkAnswer(sql(s"SHOW TBLPROPERTIES $tbl('user')"), Row("andrew")) | ||
| checkAnswer(sql(s"SHOW TBLPROPERTIES $tbl('status')"), Row("new")) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| test("SHOW TBLPROPERTIES FOR VIEW") { | ||
|
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. The reason to have these 2 tests here is because hive can return more properties?
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. if so can we add a comment to explain it?
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. An additional attribute |
||
| val v = "testview" | ||
| withView(v) { | ||
| spark.sql(s"CREATE VIEW $v TBLPROPERTIES('p1'='v1', 'p2'='v2') AS SELECT 1 AS c1") | ||
| checkAnswer(sql(s"SHOW TBLPROPERTIES $v").filter("key != 'transient_lastDdlTime'"), | ||
| Seq(Row("p1", "v1"), Row("p2", "v2"))) | ||
| checkAnswer(sql(s"SHOW TBLPROPERTIES $v('p1')"), Row("p1", "v1")) | ||
| checkAnswer(sql(s"SHOW TBLPROPERTIES $v('p3')"), | ||
| Row("p3", s"Table default.$v does not have property: p3")) | ||
| } | ||
| } | ||
|
|
||
| test("SHOW TBLPROPERTIES FOR TEMPORARY IEW") { | ||
| val v = "testview" | ||
| withView(v) { | ||
| spark.sql(s"CREATE TEMPORARY VIEW $v AS SELECT 1 AS c1;") | ||
| checkAnswer(sql(s"SHOW TBLPROPERTIES $v"), Seq.empty) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * The class contains tests for the `SHOW TBLPROPERTIES` command to check V1 In-Memory | ||
| * table catalog. | ||
| */ | ||
| class ShowTblPropertiesSuite extends ShowTblPropertiesSuiteBase with CommandSuiteBase { | ||
| override def commandVersion: String = super[ShowTblPropertiesSuiteBase].commandVersion | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| /* | ||
| * 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.execution.command | ||
|
|
||
| /** | ||
| * The class contains tests for the `SHOW TBLPROPERTIES` command to check V2 table catalogs. | ||
| */ | ||
| class ShowTblPropertiesSuite extends command.ShowTblPropertiesSuiteBase with CommandSuiteBase { | ||
| } |
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.
In order to be compatible Hive table, so add the filter action.