-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[SPARK-37590][SQL][TEST] Unify v1 and v2 ALTER TABLE .. SET PROPERTIES tests #34842
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 7 commits
4425aab
ebba2b9
dee8d61
54d6f50
4ef927b
5ac94f6
bef81fa
cf1ea86
aaf0e5c
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,49 @@ | ||
| /* | ||
| * 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.parser.ParseException | ||
| import org.apache.spark.sql.catalyst.plans.logical.SetNamespaceProperties | ||
|
|
||
| class AlterNamespaceSetPropertiesParserSuite extends AnalysisTest { | ||
| test("set namespace properties") { | ||
| Seq("DATABASE", "SCHEMA", "NAMESPACE").foreach { nsToken => | ||
| Seq("PROPERTIES", "DBPROPERTIES").foreach { propToken => | ||
| comparePlans( | ||
| parsePlan(s"ALTER $nsToken a.b.c SET $propToken ('a'='a', 'b'='b', 'c'='c')"), | ||
| SetNamespaceProperties( | ||
| UnresolvedNamespace(Seq("a", "b", "c")), Map("a" -> "a", "b" -> "b", "c" -> "c"))) | ||
|
|
||
| comparePlans( | ||
| parsePlan(s"ALTER $nsToken a.b.c SET $propToken ('a'='a')"), | ||
| SetNamespaceProperties( | ||
| UnresolvedNamespace(Seq("a", "b", "c")), Map("a" -> "a"))) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| test("property values must be set") { | ||
| val e = intercept[ParseException] { | ||
| parsePlan("ALTER NAMESPACE my_db SET PROPERTIES('key_without_value', 'key_with_value'='x')") | ||
| } | ||
| assert(e.getMessage.contains( | ||
| "Operation not allowed: Values must be specified for key(s): [key_without_value]")) | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change | |||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,115 @@ | |||||||||||||||||||||||||||||||||||||||||||
| /* | |||||||||||||||||||||||||||||||||||||||||||
| * 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.parser.ParseException | |||||||||||||||||||||||||||||||||||||||||||
| import org.apache.spark.sql.connector.catalog.{CatalogV2Util, SupportsNamespaces} | |||||||||||||||||||||||||||||||||||||||||||
| import org.apache.spark.sql.internal.SQLConf | |||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||
| /** | |||||||||||||||||||||||||||||||||||||||||||
| * This base suite contains unified tests for the `ALTER NAMESPACE ... SET PROPERTIES` 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.AlterNamespaceSetPropertiesSuite` | |||||||||||||||||||||||||||||||||||||||||||
| * - V1 table catalog tests: | |||||||||||||||||||||||||||||||||||||||||||
| * `org.apache.spark.sql.execution.command.v1.AlterNamespaceSetPropertiesSuiteBase` | |||||||||||||||||||||||||||||||||||||||||||
| * - V1 In-Memory catalog: | |||||||||||||||||||||||||||||||||||||||||||
| * `org.apache.spark.sql.execution.command.v1.AlterNamespaceSetPropertiesSuite` | |||||||||||||||||||||||||||||||||||||||||||
| * - V1 Hive External catalog: | |||||||||||||||||||||||||||||||||||||||||||
| * `org.apache.spark.sql.hive.execution.command.AlterNamespaceSetPropertiesSuite` | |||||||||||||||||||||||||||||||||||||||||||
| */ | |||||||||||||||||||||||||||||||||||||||||||
| trait AlterNamespaceSetPropertiesSuiteBase extends QueryTest with DDLCommandTestUtils { | |||||||||||||||||||||||||||||||||||||||||||
| override val command = "ALTER NAMESPACE ... SET PROPERTIES" | |||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||
| protected def namespace: String | |||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||
| protected def notFoundMsgPrefix: String | |||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||
| test("Namespace does not exist") { | |||||||||||||||||||||||||||||||||||||||||||
| val ns = "not_exist" | |||||||||||||||||||||||||||||||||||||||||||
| val message = intercept[AnalysisException] { | |||||||||||||||||||||||||||||||||||||||||||
| sql(s"ALTER DATABASE $catalog.$ns SET PROPERTIES ('d'='d')") | |||||||||||||||||||||||||||||||||||||||||||
| }.getMessage | |||||||||||||||||||||||||||||||||||||||||||
| assert(message.contains(s"$notFoundMsgPrefix '$ns' not found")) | |||||||||||||||||||||||||||||||||||||||||||
| } | |||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||
| test("basic test") { | |||||||||||||||||||||||||||||||||||||||||||
| val ns = s"$catalog.$namespace" | |||||||||||||||||||||||||||||||||||||||||||
| withNamespace(ns) { | |||||||||||||||||||||||||||||||||||||||||||
| sql(s"CREATE NAMESPACE $ns") | |||||||||||||||||||||||||||||||||||||||||||
| assert(getProperties(ns) === "") | |||||||||||||||||||||||||||||||||||||||||||
| sql(s"ALTER NAMESPACE $ns SET PROPERTIES ('a'='a', 'b'='b', 'c'='c')") | |||||||||||||||||||||||||||||||||||||||||||
| assert(getProperties(ns) === "((a,a), (b,b), (c,c))") | |||||||||||||||||||||||||||||||||||||||||||
| sql(s"ALTER DATABASE $ns SET PROPERTIES ('d'='d')") | |||||||||||||||||||||||||||||||||||||||||||
| assert(getProperties(ns) === "((a,a), (b,b), (c,c), (d,d))") | |||||||||||||||||||||||||||||||||||||||||||
| } | |||||||||||||||||||||||||||||||||||||||||||
| } | |||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||
| test("test with properties set while creating namespace") { | |||||||||||||||||||||||||||||||||||||||||||
| val ns = s"$catalog.$namespace" | |||||||||||||||||||||||||||||||||||||||||||
| withNamespace(ns) { | |||||||||||||||||||||||||||||||||||||||||||
| sql(s"CREATE NAMESPACE $ns WITH PROPERTIES ('a'='a','b'='b','c'='c')") | |||||||||||||||||||||||||||||||||||||||||||
| assert(getProperties(ns) === "((a,a), (b,b), (c,c))") | |||||||||||||||||||||||||||||||||||||||||||
| sql(s"ALTER NAMESPACE $ns SET PROPERTIES ('a'='b', 'b'='a')") | |||||||||||||||||||||||||||||||||||||||||||
| assert(getProperties(ns) === "((a,b), (b,a), (c,c))") | |||||||||||||||||||||||||||||||||||||||||||
| } | |||||||||||||||||||||||||||||||||||||||||||
| } | |||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||
| test("test reserved properties") { | |||||||||||||||||||||||||||||||||||||||||||
| import SupportsNamespaces._ | |||||||||||||||||||||||||||||||||||||||||||
| import org.apache.spark.sql.connector.catalog.CatalogV2Implicits._ | |||||||||||||||||||||||||||||||||||||||||||
| val ns = s"$catalog.$namespace" | |||||||||||||||||||||||||||||||||||||||||||
| withSQLConf((SQLConf.LEGACY_PROPERTY_NON_RESERVED.key, "false")) { | |||||||||||||||||||||||||||||||||||||||||||
| CatalogV2Util.NAMESPACE_RESERVED_PROPERTIES.filterNot(_ == PROP_COMMENT).foreach { key => | |||||||||||||||||||||||||||||||||||||||||||
| withNamespace(ns) { | |||||||||||||||||||||||||||||||||||||||||||
| sql(s"CREATE NAMESPACE $ns") | |||||||||||||||||||||||||||||||||||||||||||
| val exception = intercept[ParseException] { | |||||||||||||||||||||||||||||||||||||||||||
| sql(s"ALTER NAMESPACE $ns SET PROPERTIES ('$key'='dummyVal')") | |||||||||||||||||||||||||||||||||||||||||||
| } | |||||||||||||||||||||||||||||||||||||||||||
| assert(exception.getMessage.contains(s"$key is a reserved namespace property")) | |||||||||||||||||||||||||||||||||||||||||||
| } | |||||||||||||||||||||||||||||||||||||||||||
| } | |||||||||||||||||||||||||||||||||||||||||||
| } | |||||||||||||||||||||||||||||||||||||||||||
| withSQLConf((SQLConf.LEGACY_PROPERTY_NON_RESERVED.key, "true")) { | |||||||||||||||||||||||||||||||||||||||||||
| CatalogV2Util.NAMESPACE_RESERVED_PROPERTIES.filterNot(_ == PROP_COMMENT).foreach { key => | |||||||||||||||||||||||||||||||||||||||||||
| withNamespace(ns) { | |||||||||||||||||||||||||||||||||||||||||||
| sql(s"CREATE NAMESPACE $ns") | |||||||||||||||||||||||||||||||||||||||||||
| assert(getProperties(ns) === "") | |||||||||||||||||||||||||||||||||||||||||||
| sql(s"ALTER NAMESPACE $ns SET PROPERTIES ('$key'='foo')") | |||||||||||||||||||||||||||||||||||||||||||
| assert(getProperties(ns) === "", s"$key is a reserved namespace property and ignored") | |||||||||||||||||||||||||||||||||||||||||||
| val meta = spark.sessionState.catalogManager.catalog(catalog) | |||||||||||||||||||||||||||||||||||||||||||
| .asNamespaceCatalog.loadNamespaceMetadata(namespace.split('.')) | |||||||||||||||||||||||||||||||||||||||||||
| assert(meta.get(key) == null || !meta.get(key).contains("foo"), | |||||||||||||||||||||||||||||||||||||||||||
|
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. is this a behavior difference between v1 and v2? null vs empty string
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. This was taken from In the above loop, the
I think the
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. For the location, I think it's OK. The catalog implementation should decide the default location (or even no location if the source is not file-based). We should accept this difference. For the owner, it seems a bug that
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. For the owner, the difference comes because v2 command always adds the owner when the namespace is created: Lines 45 to 47 in 7b00011
, whereas for v1 command doesn't add the owner when the database is created. Instead, for v1 Hive catalog, the user property is inserted when the database is retrieved: spark/sql/hive/src/main/scala/org/apache/spark/sql/hive/client/HiveClientImpl.scala Lines 370 to 373 in 7b00011
Meanwhile, the v1 in-memory catalog implementation doesn't add the owner when the database is retrieved, so we see One thing we can do is to update the v1 in-memory catalog to add the owner when the database is created or retrieved, but it is still not consistent since adding the owner is a responsibility of the command in v2, but a responsibility of the catalog in v1. Any thoughts?
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. It may be too risky to change the v1 behavior now (Hive metastore fills the owner field). Let's just update the v1 in-memory catalog to fill the owner field as well. @yaooqinn which one do you think should set the owner field? Spark or the underlying catalog?
Member
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. for v1 and v2 database and table creation, we both respect the
Member
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. for alter properties and if it's not an explicitly ower change, we shall respect the catalog settings
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. I added an owner while creating a database in |
|||||||||||||||||||||||||||||||||||||||||||
| "reserved properties should not have side effects") | |||||||||||||||||||||||||||||||||||||||||||
| } | |||||||||||||||||||||||||||||||||||||||||||
| } | |||||||||||||||||||||||||||||||||||||||||||
| } | |||||||||||||||||||||||||||||||||||||||||||
| } | |||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||
| protected def getProperties(namespace: String): String = { | |||||||||||||||||||||||||||||||||||||||||||
| val propsRow = sql(s"DESCRIBE NAMESPACE EXTENDED $namespace") | |||||||||||||||||||||||||||||||||||||||||||
| .toDF("key", "value") | |||||||||||||||||||||||||||||||||||||||||||
| .where(s"key like 'Properties%'") | |||||||||||||||||||||||||||||||||||||||||||
| .collect() | |||||||||||||||||||||||||||||||||||||||||||
| assert(propsRow.length == 1) | |||||||||||||||||||||||||||||||||||||||||||
| propsRow(0).getString(1) | |||||||||||||||||||||||||||||||||||||||||||
| } | |||||||||||||||||||||||||||||||||||||||||||
| } | |||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| /* | ||
| * 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.execution.command | ||
|
|
||
| /** | ||
| * This base suite contains unified tests for the `ALTER NAMESPACE ... SET PROPERTIES` 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.AlterNamespaceSetPropertiesSuite` | ||
| * - V1 Hive External catalog: | ||
| * `org.apache.spark.sql.hive.execution.command.AlterNamespaceSetPropertiesSuite` | ||
| */ | ||
| trait AlterNamespaceSetPropertiesSuiteBase extends command.AlterNamespaceSetPropertiesSuiteBase | ||
| with command.TestsV1AndV2Commands { | ||
| override def namespace: String = "db" | ||
| override def notFoundMsgPrefix: String = "Database" | ||
| } | ||
|
|
||
| /** | ||
| * The class contains tests for the `ALTER NAMESPACE ... SET PROPERTIES` command to | ||
| * check V1 In-Memory table catalog. | ||
| */ | ||
| class AlterNamespaceSetPropertiesSuite extends AlterNamespaceSetPropertiesSuiteBase | ||
| with CommandSuiteBase { | ||
| override def commandVersion: String = super[AlterNamespaceSetPropertiesSuiteBase].commandVersion | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.