-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-48659][SQL][TESTS] Unify v1 and v2 ALTER TABLE .. SET TBLPROPERTIES tests #47018
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,55 @@ | ||
| /* | ||
| * 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.SparkThrowable | ||
| import org.apache.spark.sql.catalyst.analysis.{AnalysisTest, UnresolvedTable} | ||
| import org.apache.spark.sql.catalyst.parser.CatalystSqlParser.parsePlan | ||
| import org.apache.spark.sql.catalyst.parser.ParseException | ||
| import org.apache.spark.sql.catalyst.plans.logical.SetTableProperties | ||
| import org.apache.spark.sql.test.SharedSparkSession | ||
|
|
||
| class AlterTableSetTblPropertiesParserSuite extends AnalysisTest with SharedSparkSession { | ||
|
|
||
| private def parseException(sqlText: String): SparkThrowable = { | ||
| intercept[ParseException](sql(sqlText).collect()) | ||
| } | ||
|
|
||
| // ALTER TABLE table_name SET TBLPROPERTIES ('comment' = new_comment); | ||
| test("alter table: alter table properties") { | ||
|
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. Ported from |
||
| val sql1_table = "ALTER TABLE table_name SET TBLPROPERTIES ('test' = 'test', " + | ||
| "'comment' = 'new_comment')" | ||
| comparePlans( | ||
| parsePlan(sql1_table), | ||
| SetTableProperties( | ||
| UnresolvedTable(Seq("table_name"), "ALTER TABLE ... SET TBLPROPERTIES", true), | ||
| Map("test" -> "test", "comment" -> "new_comment"))) | ||
| } | ||
|
|
||
| test("alter table - property values must be set") { | ||
|
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. Ported from |
||
| val sql = "ALTER TABLE my_tab SET TBLPROPERTIES('key_without_value', 'key_with_value'='x')" | ||
| checkError( | ||
| exception = parseException(sql), | ||
| errorClass = "_LEGACY_ERROR_TEMP_0035", | ||
| parameters = Map("message" -> "Values must be specified for key(s): [key_without_value]"), | ||
| context = ExpectedContext( | ||
| fragment = sql, | ||
| start = 0, | ||
| stop = 78)) | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| /* | ||
| * 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.catalyst.TableIdentifier | ||
|
|
||
| /** | ||
| * This base suite contains unified tests for the `ALTER TABLE .. SET 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.AlterTableSetTblPropertiesSuite` | ||
| * - V1 table catalog tests: | ||
| * `org.apache.spark.sql.execution.command.v1.AlterTableSetTblPropertiesSuiteBase` | ||
| * - V1 In-Memory catalog: | ||
| * `org.apache.spark.sql.execution.command.v1.AlterTableSetTblPropertiesSuite` | ||
| * - V1 Hive External catalog: | ||
| * `org.apache.spark.sql.hive.execution.command.AlterTableSetTblPropertiesSuite` | ||
| */ | ||
| trait AlterTableSetTblPropertiesSuiteBase extends QueryTest with DDLCommandTestUtils { | ||
| override val command = "ALTER TABLE .. SET TBLPROPERTIES" | ||
|
|
||
| def checkTblProps(tableIdent: TableIdentifier, expectedTblProps: Map[String, String]): Unit | ||
|
|
||
| test("alter table set tblproperties") { | ||
| withNamespaceAndTable("ns", "tbl") { t => | ||
| sql(s"CREATE TABLE $t (col1 int, col2 string, a int, b int) $defaultUsing") | ||
| val tableIdent = TableIdentifier("tbl", Some("ns"), Some(catalog)) | ||
| checkTblProps(tableIdent, Map.empty[String, String]) | ||
|
|
||
| sql(s"ALTER TABLE $t SET TBLPROPERTIES ('k1' = 'v1', 'k2' = 'v2', 'k3' = 'v3')") | ||
| checkTblProps(tableIdent, Map("k1" -> "v1", "k2" -> "v2", "k3" -> "v3")) | ||
|
|
||
| sql(s"USE $catalog.ns") | ||
| sql(s"ALTER TABLE tbl SET TBLPROPERTIES ('k1' = 'v1', 'k2' = 'v2', 'k3' = 'v3')") | ||
| checkTblProps(tableIdent, Map("k1" -> "v1", "k2" -> "v2", "k3" -> "v3")) | ||
|
|
||
| sql(s"ALTER TABLE $t SET TBLPROPERTIES ('k1' = 'v1', 'k2' = 'v8')") | ||
| checkTblProps(tableIdent, Map("k1" -> "v1", "k2" -> "v8", "k3" -> "v3")) | ||
|
|
||
| // table to alter does not exist | ||
| checkError( | ||
| exception = intercept[AnalysisException] { | ||
| sql("ALTER TABLE does_not_exist SET TBLPROPERTIES ('winner' = 'loser')") | ||
| }, | ||
| errorClass = "TABLE_OR_VIEW_NOT_FOUND", | ||
| parameters = Map("relationName" -> "`does_not_exist`"), | ||
| context = ExpectedContext(fragment = "does_not_exist", start = 12, stop = 25) | ||
| ) | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| /* | ||
| * 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.catalyst.TableIdentifier | ||
| import org.apache.spark.sql.execution.command | ||
| import org.apache.spark.sql.internal.StaticSQLConf.CATALOG_IMPLEMENTATION | ||
|
|
||
| /** | ||
| * This base suite contains unified tests for the `ALTER TABLE .. SET TBLPROPERTIES` | ||
| * command that check 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.AlterTableSetTblPropertiesSuite` | ||
| * - V1 Hive External catalog: | ||
| * `org.apache.spark.sql.hive.execution.command.AlterTableSetTblPropertiesSuite` | ||
| */ | ||
| trait AlterTableSetTblPropertiesSuiteBase extends command.AlterTableSetTblPropertiesSuiteBase { | ||
|
|
||
| private[sql] lazy val sessionCatalog = spark.sessionState.catalog | ||
|
|
||
| private def isUsingHiveMetastore: Boolean = { | ||
| spark.sparkContext.conf.get(CATALOG_IMPLEMENTATION) == "hive" | ||
| } | ||
|
|
||
| private def normalizeTblProps(props: Map[String, String]): Map[String, String] = { | ||
| props.filterNot(p => Seq("transient_lastDdlTime").contains(p._1)) | ||
| } | ||
|
|
||
| private def getTableProperties(tableIdent: TableIdentifier): Map[String, String] = { | ||
| sessionCatalog.getTableMetadata(tableIdent).properties | ||
| } | ||
|
|
||
| override def checkTblProps(tableIdent: TableIdentifier, | ||
| expectedTblProps: Map[String, String]): Unit = { | ||
| val actualTblProps = getTableProperties(tableIdent) | ||
| if (isUsingHiveMetastore) { | ||
| assert(normalizeTblProps(actualTblProps) == expectedTblProps) | ||
| } else { | ||
| assert(actualTblProps == expectedTblProps) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| class AlterTableSetTblPropertiesSuite | ||
| extends AlterTableSetTblPropertiesSuiteBase with CommandSuiteBase |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| /* | ||
| * 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 scala.jdk.CollectionConverters._ | ||
|
|
||
| import org.apache.spark.sql.catalyst.TableIdentifier | ||
| import org.apache.spark.sql.connector.catalog.{Identifier, Table} | ||
| import org.apache.spark.sql.connector.catalog.CatalogV2Implicits.CatalogHelper | ||
| import org.apache.spark.sql.execution.command | ||
|
|
||
| /** | ||
| * The class contains tests for the `ALTER TABLE .. SET TBLPROPERTIES` command to | ||
| * check V2 table catalogs. | ||
| */ | ||
| class AlterTableSetTblPropertiesSuite | ||
| extends command.AlterTableSetTblPropertiesSuiteBase with CommandSuiteBase { | ||
|
|
||
| private def normalizeTblProps(props: Map[String, String]): Map[String, String] = { | ||
| props.filterNot(p => Seq("provider", "owner").contains(p._1)) | ||
| } | ||
|
|
||
| private def getTableMetadata(tableIndent: TableIdentifier): Table = { | ||
| val nameParts = tableIndent.nameParts | ||
| val v2Catalog = spark.sessionState.catalogManager.catalog(nameParts.head).asTableCatalog | ||
| val namespace = nameParts.drop(1).init.toArray | ||
| v2Catalog.loadTable(Identifier.of(namespace, nameParts.last)) | ||
| } | ||
|
|
||
| override def checkTblProps(tableIdent: TableIdentifier, | ||
| expectedTblProps: Map[String, String]): Unit = { | ||
| val actualTblProps = getTableMetadata(tableIdent).properties.asScala.toMap | ||
| assert(normalizeTblProps(actualTblProps) === expectedTblProps) | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| /* | ||
| * 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.hive.execution.command | ||
|
|
||
| import org.apache.spark.sql.execution.command.v1 | ||
|
|
||
| /** | ||
| * The class contains tests for the `ALTER TABLE .. SET TBLPROPERTIES` command to check | ||
| * V1 Hive external table catalog. | ||
| */ | ||
| class AlterTableSetTblPropertiesSuite | ||
| extends v1.AlterTableSetTblPropertiesSuiteBase 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.
Only tests related to
SEThave been moved, and tests related toUNSETwill doing in another PR