-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[SPARK-34332][SQL][TEST] Unify v1 and v2 ALTER NAMESPACE .. SET LOCATION tests #34610
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
imback82
wants to merge
7
commits into
apache:master
from
imback82:alter_namespace_set_loation_tests2
Closed
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a17986e
initial commit
imback82 4629166
move empty location string
imback82 6df9efd
address PR comments
imback82 b1874f1
Merge remote-tracking branch 'upstream/master' into alter_namespace_s…
imback82 b32d397
move empty locatio test
imback82 c93eb8c
Merge branch 'master' into alter_namespace_set_loation_tests2
imback82 caacba6
clean up test
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
41 changes: 41 additions & 0 deletions
41
...t/scala/org/apache/spark/sql/execution/command/AlterNamespaceSetLocationParserSuite.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,41 @@ | ||
| /* | ||
| * 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.SetNamespaceLocation | ||
|
|
||
| class AlterNamespaceSetLocationParserSuite extends AnalysisTest { | ||
| test("set namespace location") { | ||
| comparePlans( | ||
| parsePlan("ALTER DATABASE a.b.c SET LOCATION '/home/user/db'"), | ||
| SetNamespaceLocation( | ||
| UnresolvedNamespace(Seq("a", "b", "c")), "/home/user/db")) | ||
|
|
||
| comparePlans( | ||
| parsePlan("ALTER SCHEMA a.b.c SET LOCATION '/home/user/db'"), | ||
| SetNamespaceLocation( | ||
| UnresolvedNamespace(Seq("a", "b", "c")), "/home/user/db")) | ||
|
|
||
| comparePlans( | ||
| parsePlan("ALTER NAMESPACE a.b.c SET LOCATION '/home/user/db'"), | ||
| SetNamespaceLocation( | ||
| UnresolvedNamespace(Seq("a", "b", "c")), "/home/user/db")) | ||
| } | ||
| } |
74 changes: 74 additions & 0 deletions
74
...est/scala/org/apache/spark/sql/execution/command/AlterNamespaceSetLocationSuiteBase.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,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 | ||
|
|
||
| import org.apache.spark.sql.{AnalysisException, QueryTest} | ||
| import org.apache.spark.sql.connector.catalog.SupportsNamespaces | ||
|
|
||
| /** | ||
| * This base suite contains unified tests for the `ALTER NAMESPACE ... SET LOCATION` 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.AlterNamespaceSetLocationSuite` | ||
| * - V1 table catalog tests: | ||
| * `org.apache.spark.sql.execution.command.v1.AlterNamespaceSetLocationSuiteBase` | ||
| * - V1 In-Memory catalog: | ||
| * `org.apache.spark.sql.execution.command.v1.AlterNamespaceSetLocationSuite` | ||
| * - V1 Hive External catalog: | ||
| * `org.apache.spark.sql.hive.execution.command.AlterNamespaceSetLocationSuite` | ||
| */ | ||
| trait AlterNamespaceSetLocationSuiteBase extends QueryTest with DDLCommandTestUtils { | ||
| override val command = "ALTER NAMESPACE ... SET LOCATION" | ||
|
|
||
| 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 LOCATION 'loc'") | ||
| }.getMessage | ||
| assert(message.contains(s"$notFoundMsgPrefix '$ns' not found")) | ||
| } | ||
|
|
||
| // Hive catalog does not support "ALTER NAMESPACE ... SET LOCATION", thus | ||
| // this is called from non-Hive v1 and v2 tests. | ||
| protected def runBasicTest(): Unit = { | ||
| val ns = s"$catalog.$namespace" | ||
| withNamespace(ns) { | ||
| sql(s"CREATE NAMESPACE IF NOT EXISTS $ns COMMENT " + | ||
| "'test namespace' LOCATION '/tmp/loc_test_1'") | ||
| sql(s"ALTER NAMESPACE $ns SET LOCATION '/tmp/loc_test_2'") | ||
| // v1 command stores the location as URI ("file:/tmp/loc_test_2") whereas | ||
| // v2 command stores the location as string ("/tmp/loc_test_2"). | ||
|
imback82 marked this conversation as resolved.
Outdated
|
||
| assert(getLocation(ns).contains("/tmp/loc_test_2")) | ||
| } | ||
| } | ||
|
|
||
| protected def getLocation(namespace: String): String = { | ||
| val locationRow = sql(s"DESCRIBE NAMESPACE EXTENDED $namespace") | ||
| .toDF("key", "value") | ||
| .where(s"key like '${SupportsNamespaces.PROP_LOCATION.capitalize}%'") | ||
| .collect() | ||
| assert(locationRow.length == 1) | ||
| locationRow(0).getString(1) | ||
| } | ||
| } | ||
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
60 changes: 60 additions & 0 deletions
60
...test/scala/org/apache/spark/sql/execution/command/v1/AlterNamespaceSetLocationSuite.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.execution.command | ||
|
|
||
| /** | ||
| * This base suite contains unified tests for the `ALTER NAMESPACE ... SET LOCATION` 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.AlterNamespaceSetLocationSuite` | ||
| * - V1 Hive External catalog: | ||
| * `org.apache.spark.sql.hive.execution.command.AlterNamespaceSetLocationSuite` | ||
| */ | ||
| trait AlterNamespaceSetLocationSuiteBase extends command.AlterNamespaceSetLocationSuiteBase | ||
| with command.TestsV1AndV2Commands { | ||
| override def namespace: String = "db" | ||
| override def notFoundMsgPrefix: String = "Database" | ||
|
|
||
| test("Empty location string") { | ||
| val ns = s"$catalog.$namespace" | ||
| withNamespace(ns) { | ||
| sql(s"CREATE NAMESPACE $ns") | ||
| val message = intercept[IllegalArgumentException] { | ||
| sql(s"ALTER NAMESPACE $ns SET LOCATION ''") | ||
| }.getMessage | ||
| assert(message.contains("Can not create a Path from an empty string")) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * The class contains tests for the `ALTER NAMESPACE ... SET LOCATION` command to | ||
| * check V1 In-Memory table catalog. | ||
| */ | ||
| class AlterNamespaceSetLocationSuite extends AlterNamespaceSetLocationSuiteBase | ||
| with CommandSuiteBase { | ||
| override def commandVersion: String = super[AlterNamespaceSetLocationSuiteBase].commandVersion | ||
|
|
||
| test("basic test") { | ||
| runBasicTest() | ||
| } | ||
| } |
43 changes: 43 additions & 0 deletions
43
...test/scala/org/apache/spark/sql/execution/command/v2/AlterNamespaceSetLocationSuite.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,43 @@ | ||
| /* | ||
| * 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 `ALTER NAMESPACE ... SET LOCATION` command to check V2 table | ||
| * catalogs. | ||
| */ | ||
| class AlterNamespaceSetLocationSuite extends command.AlterNamespaceSetLocationSuiteBase | ||
| with CommandSuiteBase { | ||
| override def namespace: String = "ns1.ns2" | ||
| override def notFoundMsgPrefix: String = "Namespace" | ||
|
|
||
| test("basic test") { | ||
| runBasicTest() | ||
| } | ||
|
|
||
| test("Empty location string is allowed") { | ||
|
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 is another difference. v1 doesn't allow empty string because it converts the string to URI. |
||
| val ns = s"$catalog.$namespace" | ||
| withNamespace(ns) { | ||
| sql(s"CREATE NAMESPACE $ns") | ||
| sql(s"ALTER NAMESPACE $ns SET LOCATION ''") | ||
| assert(getLocation(ns) === "") | ||
| } | ||
| } | ||
| } | ||
41 changes: 41 additions & 0 deletions
41
...st/scala/org/apache/spark/sql/hive/execution/command/AlterNamespaceSetLocationSuite.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,41 @@ | ||
| /* | ||
| * 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.AnalysisException | ||
| import org.apache.spark.sql.execution.command.v1 | ||
|
|
||
| /** | ||
| * The class contains tests for the `ALTER NAMESPACE ... SET LOCATION` command to check | ||
| * V1 Hive external table catalog. | ||
| */ | ||
| class AlterNamespaceSetLocationSuite extends v1.AlterNamespaceSetLocationSuiteBase | ||
| with CommandSuiteBase { | ||
|
cloud-fan marked this conversation as resolved.
|
||
| override def commandVersion: String = super[AlterNamespaceSetLocationSuiteBase].commandVersion | ||
|
|
||
| test("Hive catalog not supported") { | ||
| val ns = s"$catalog.$namespace" | ||
| withNamespace(ns) { | ||
| sql(s"CREATE NAMESPACE $ns") | ||
| val e = intercept[AnalysisException] { | ||
| sql(s"ALTER DATABASE $ns SET LOCATION 'loc'") | ||
| } | ||
| assert(e.getMessage.contains("does not support altering database location")) | ||
| } | ||
| } | ||
| } | ||
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.
maybe we can have a
and in the hive test we override it
Then we can define the test in base trait
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.
or we just allow using
NAMESPACEin hive context as well.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.
I meant Hive doesn't support altering location:
spark/sql/hive/src/main/scala/org/apache/spark/sql/hive/client/HiveClientImpl.scala
Lines 356 to 360 in 04671bd
Uh oh!
There was an error while loading. Please reload this page.
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.
I see, thanks for the explanation!