-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-48668][SQL] Support ALTER NAMESPACE ... UNSET PROPERTIES in v2 #47038
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
12f8f71
48e3b44
363ad49
7ddf703
1f3ed06
960f32a
0748ea4
53a9a25
33fbc7c
0d09a65
b3b60ac
0e925c6
87b0bcb
f5efc77
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.sql.{Row, SparkSession} | ||
| import org.apache.spark.sql.catalyst.analysis.ResolvedNamespace | ||
| import org.apache.spark.sql.catalyst.plans.logical.LogicalPlan | ||
| import org.apache.spark.sql.connector.catalog.CatalogV2Implicits.CatalogHelper | ||
| import org.apache.spark.sql.connector.catalog.NamespaceChange | ||
|
|
||
| /** | ||
| * A command that unsets database/schema/namespace properties. | ||
| * | ||
| * The syntax of this command is: | ||
| * {{{ | ||
| * ALTER (DATABASE|SCHEMA|NAMESPACE) ... | ||
| * UNSET (DBPROPERTIES|PROPERTIES) ('key1', 'key2', ...); | ||
| * }}} | ||
| */ | ||
| case class UnsetNamespacePropertiesCommand( | ||
|
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 have to define |
||
| ident: LogicalPlan, | ||
| propKeys: Seq[String]) extends UnaryRunnableCommand { | ||
|
|
||
| override def run(sparkSession: SparkSession): Seq[Row] = { | ||
| val ResolvedNamespace(catalog, ns, _) = child | ||
| val changes = propKeys.map { | ||
| NamespaceChange.removeProperty | ||
| } | ||
| // If the property does not exist, the change should succeed. | ||
| catalog.asNamespaceCatalog.alterNamespace(ns.toArray, changes: _*) | ||
cloud-fan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| Seq.empty | ||
| } | ||
|
|
||
| override def child: LogicalPlan = ident | ||
|
|
||
| override protected def withNewChildInternal( | ||
| newChild: LogicalPlan): UnsetNamespacePropertiesCommand = | ||
| copy(ident = newChild) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,7 +26,7 @@ import org.apache.spark.sql.catalyst.{CatalystTypeConverters, InternalRow} | |
| import org.apache.spark.sql.catalyst.expressions.{Attribute, AttributeReference} | ||
| import org.apache.spark.sql.catalyst.plans.QueryPlan | ||
| import org.apache.spark.sql.catalyst.plans.logical.{Command, LogicalPlan, SupervisingCommand} | ||
| import org.apache.spark.sql.catalyst.trees.LeafLike | ||
| import org.apache.spark.sql.catalyst.trees.{LeafLike, UnaryLike} | ||
| import org.apache.spark.sql.connector.ExternalCommandRunner | ||
| import org.apache.spark.sql.execution.{CommandExecutionMode, ExplainMode, LeafExecNode, SparkPlan, UnaryExecNode} | ||
| import org.apache.spark.sql.execution.metric.SQLMetric | ||
|
|
@@ -51,6 +51,7 @@ trait RunnableCommand extends Command { | |
| } | ||
|
|
||
| trait LeafRunnableCommand extends RunnableCommand with LeafLike[LogicalPlan] | ||
| trait UnaryRunnableCommand extends RunnableCommand with UnaryLike[LogicalPlan] | ||
|
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. Because |
||
|
|
||
| /** | ||
| * A physical operator that executes the run method of a `RunnableCommand` and | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -83,10 +83,19 @@ trait AlterNamespaceSetPropertiesSuiteBase extends QueryTest with DDLCommandTest | |
| 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")) | ||
| val sqlText = s"ALTER NAMESPACE $ns SET PROPERTIES ('$key'='dummyVal')" | ||
|
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. Not related to this PR, |
||
| checkErrorMatchPVals( | ||
| exception = intercept[ParseException] { | ||
| sql(sqlText) | ||
| }, | ||
| errorClass = "UNSUPPORTED_FEATURE.SET_NAMESPACE_PROPERTY", | ||
| parameters = Map("property" -> key, "msg" -> ".*"), | ||
| sqlState = None, | ||
| context = ExpectedContext( | ||
| fragment = sqlText, | ||
| start = 0, | ||
| stop = 46 + ns.length + key.length) | ||
| ) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| /* | ||
| * 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, UnresolvedNamespace} | ||
| import org.apache.spark.sql.catalyst.parser.ParseException | ||
| import org.apache.spark.sql.catalyst.plans.logical.LogicalPlan | ||
| import org.apache.spark.sql.execution.SparkSqlParser | ||
| import org.apache.spark.sql.test.SharedSparkSession | ||
|
|
||
| class AlterNamespaceUnsetPropertiesParserSuite extends AnalysisTest with SharedSparkSession { | ||
|
|
||
| private lazy val parser = new SparkSqlParser() | ||
|
|
||
| private def parseException(sqlText: String): SparkThrowable = { | ||
| intercept[ParseException](sql(sqlText).collect()) | ||
| } | ||
|
|
||
| private def parsePlan(sqlText: String): LogicalPlan = { | ||
| parser.parsePlan(sqlText) | ||
| } | ||
|
|
||
| test("unset namespace properties") { | ||
| Seq("DATABASE", "SCHEMA", "NAMESPACE").foreach { nsToken => | ||
| Seq("PROPERTIES", "DBPROPERTIES").foreach { propToken => | ||
| comparePlans( | ||
| parsePlan(s"ALTER $nsToken a.b.c UNSET $propToken ('a', 'b', 'c')"), | ||
| UnsetNamespacePropertiesCommand( | ||
| UnresolvedNamespace(Seq("a", "b", "c")), Seq("a", "b", "c"))) | ||
|
|
||
| comparePlans( | ||
| parsePlan(s"ALTER $nsToken a.b.c UNSET $propToken ('a')"), | ||
| UnsetNamespacePropertiesCommand(UnresolvedNamespace(Seq("a", "b", "c")), Seq("a"))) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| test("property values must not be set") { | ||
| val sql = "ALTER NAMESPACE my_db UNSET PROPERTIES('key_without_value', 'key_with_value'='x')" | ||
| checkError( | ||
| exception = parseException(sql), | ||
| errorClass = "_LEGACY_ERROR_TEMP_0035", | ||
| parameters = Map("message" -> "Values should not be specified for key(s): [key_with_value]"), | ||
| context = ExpectedContext( | ||
| fragment = sql, | ||
| start = 0, | ||
| stop = 80)) | ||
| } | ||
|
|
||
| test("not support clause - IF EXISTS") { | ||
| Seq("DATABASE", "SCHEMA", "NAMESPACE").foreach { nsToken => | ||
| Seq("PROPERTIES", "DBPROPERTIES").foreach { propToken => | ||
| val sql = s"ALTER $nsToken a.b.c UNSET $propToken IF EXISTS ('a', 'b', 'c')" | ||
| checkError( | ||
| exception = parseException(sql), | ||
| errorClass = "PARSE_SYNTAX_ERROR", | ||
| parameters = Map("error" -> "'IF'", "hint" -> ": missing '('") | ||
| ) | ||
| } | ||
| } | ||
| } | ||
| } |
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 have to put the parse process of
UnsetNamespacePropertiesCommandhere, becauseUnsetNamespacePropertiesCommandcan only be defined within the modulesql/core, andAstBuildercannot access the classUnsetNamespacePropertiesCommandwithin the module