This is an automated email from the ASF dual-hosted git repository.
dongjoon pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark.git
The following commit(s) were added to refs/heads/master by this push:
new d233977 [SPARK-36848][SQL][FOLLOWUP] Simplify SHOW CURRENT NAMESPACE
command
d233977 is described below
commit d233977d186ffd65da01924c76c3b85cbe0d5345
Author: Wenchen Fan <[email protected]>
AuthorDate: Tue Sep 28 10:31:59 2021 -0700
[SPARK-36848][SQL][FOLLOWUP] Simplify SHOW CURRENT NAMESPACE command
### What changes were proposed in this pull request?
This is a followup of https://github.com/apache/spark/pull/34104
`SHOW CURRENT NAMESPACE` is a very simple command that does not involve v2
catalog API, does not need analysis, does not have children. We can simply use
`RunnableCommand` to save defining the physical plan.
### Why are the changes needed?
code simplification
### Does this PR introduce _any_ user-facing change?
no
### How was this patch tested?
existing tests
Closes #34128 from cloud-fan/follow.
Authored-by: Wenchen Fan <[email protected]>
Signed-off-by: Dongjoon Hyun <[email protected]>
---
.../spark/sql/catalyst/parser/AstBuilder.scala | 8 --------
.../sql/catalyst/plans/logical/v2Commands.scala | 9 --------
.../spark/sql/catalyst/parser/DDLParserSuite.scala | 6 ------
.../spark/sql/execution/SparkSqlParser.scala | 8 ++++++++
.../ShowCurrentNamespaceCommand.scala} | 24 ++++++++++++----------
.../datasources/v2/DataSourceV2Strategy.scala | 5 +----
.../sql/execution/command/DDLParserSuite.scala | 6 ++++++
7 files changed, 28 insertions(+), 38 deletions(-)
diff --git
a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala
b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala
index 1d0fcf5..e7c7f62 100644
---
a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala
+++
b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala
@@ -3573,14 +3573,6 @@ class AstBuilder extends SqlBaseBaseVisitor[AnyRef] with
SQLConfHelper with Logg
}
/**
- * Create a [[ShowCurrentNamespace]].
- */
- override def visitShowCurrentNamespace(
- ctx: ShowCurrentNamespaceContext) : LogicalPlan = withOrigin(ctx) {
- ShowCurrentNamespace()
- }
-
- /**
* Create a [[ShowTables]] command.
*/
override def visitShowTables(ctx: ShowTablesContext): LogicalPlan =
withOrigin(ctx) {
diff --git
a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/v2Commands.scala
b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/v2Commands.scala
index 2d025b1..5a5cb30 100644
---
a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/v2Commands.scala
+++
b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/v2Commands.scala
@@ -637,15 +637,6 @@ case class RefreshTable(child: LogicalPlan) extends
UnaryCommand {
}
/**
- * The logical plan of the SHOW CURRENT NAMESPACE command.
- */
-case class ShowCurrentNamespace() extends LeafCommand {
- override val output: Seq[Attribute] = Seq(
- AttributeReference("catalog", StringType, nullable = false)(),
- AttributeReference("namespace", StringType, nullable = false)())
-}
-
-/**
* The logical plan of the SHOW TBLPROPERTIES command.
*/
case class ShowTableProperties(
diff --git
a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/parser/DDLParserSuite.scala
b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/parser/DDLParserSuite.scala
index 5d79e51..8719b72 100644
---
a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/parser/DDLParserSuite.scala
+++
b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/parser/DDLParserSuite.scala
@@ -2101,12 +2101,6 @@ class DDLParserSuite extends AnalysisTest {
""".stripMargin)
}
- test("show current namespace") {
- comparePlans(
- parsePlan("SHOW CURRENT NAMESPACE"),
- ShowCurrentNamespace())
- }
-
test("alter table: SerDe properties") {
val sql1 = "ALTER TABLE table_name SET SERDE 'org.apache.class'"
val hint = Some("Please use ALTER VIEW instead.")
diff --git
a/sql/core/src/main/scala/org/apache/spark/sql/execution/SparkSqlParser.scala
b/sql/core/src/main/scala/org/apache/spark/sql/execution/SparkSqlParser.scala
index ea74ce6..db77019 100644
---
a/sql/core/src/main/scala/org/apache/spark/sql/execution/SparkSqlParser.scala
+++
b/sql/core/src/main/scala/org/apache/spark/sql/execution/SparkSqlParser.scala
@@ -232,6 +232,14 @@ class SparkSqlAstBuilder extends AstBuilder {
}
/**
+ * Create a [[ShowCurrentNamespaceCommand]] logical command.
+ */
+ override def visitShowCurrentNamespace(
+ ctx: ShowCurrentNamespaceContext) : LogicalPlan = withOrigin(ctx) {
+ ShowCurrentNamespaceCommand()
+ }
+
+ /**
* Converts a multi-part identifier to a TableIdentifier.
*
* If the multi-part identifier has too many parts, this will throw a
ParseException.
diff --git
a/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/ShowCurrentNamespaceExec.scala
b/sql/core/src/main/scala/org/apache/spark/sql/execution/command/ShowCurrentNamespaceCommand.scala
similarity index 55%
rename from
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/ShowCurrentNamespaceExec.scala
rename to
sql/core/src/main/scala/org/apache/spark/sql/execution/command/ShowCurrentNamespaceCommand.scala
index 0977452..76a0180 100644
---
a/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/ShowCurrentNamespaceExec.scala
+++
b/sql/core/src/main/scala/org/apache/spark/sql/execution/command/ShowCurrentNamespaceCommand.scala
@@ -15,21 +15,23 @@
* limitations under the License.
*/
-package org.apache.spark.sql.execution.datasources.v2
+package org.apache.spark.sql.execution.command
-import org.apache.spark.sql.catalyst.InternalRow
-import org.apache.spark.sql.catalyst.expressions.Attribute
-import org.apache.spark.sql.connector.catalog.CatalogManager
+import org.apache.spark.sql.{Row, SparkSession}
+import org.apache.spark.sql.catalyst.expressions.{Attribute,
AttributeReference}
import
org.apache.spark.sql.connector.catalog.CatalogV2Implicits.NamespaceHelper
+import org.apache.spark.sql.types.StringType
/**
- * Physical plan node for showing current catalog/namespace.
+ * The command for `SHOW CURRENT NAMESPACE`.
*/
-case class ShowCurrentNamespaceExec(
- output: Seq[Attribute],
- catalogManager: CatalogManager)
- extends LeafV2CommandExec {
- override protected def run(): Seq[InternalRow] = {
- Seq(toCatalystRow(catalogManager.currentCatalog.name,
catalogManager.currentNamespace.quoted))
+case class ShowCurrentNamespaceCommand() extends LeafRunnableCommand {
+ override val output: Seq[Attribute] = Seq(
+ AttributeReference("catalog", StringType, nullable = false)(),
+ AttributeReference("namespace", StringType, nullable = false)())
+
+ override def run(sparkSession: SparkSession): Seq[Row] = {
+ val catalogManager = sparkSession.sessionState.catalogManager
+ Seq(Row(catalogManager.currentCatalog.name,
catalogManager.currentNamespace.quoted))
}
}
diff --git
a/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/DataSourceV2Strategy.scala
b/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/DataSourceV2Strategy.scala
index 1868898..db61d61 100644
---
a/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/DataSourceV2Strategy.scala
+++
b/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/DataSourceV2Strategy.scala
@@ -335,10 +335,7 @@ class DataSourceV2Strategy(session: SparkSession) extends
Strategy with Predicat
case SetCatalogAndNamespace(catalogManager, catalogName, ns) =>
SetCatalogAndNamespaceExec(catalogManager, catalogName, ns) :: Nil
- case r: ShowCurrentNamespace =>
- ShowCurrentNamespaceExec(r.output, session.sessionState.catalogManager)
:: Nil
-
- case r @ ShowTableProperties(rt: ResolvedTable, propertyKey, output) =>
+ case ShowTableProperties(rt: ResolvedTable, propertyKey, output) =>
ShowTablePropertiesExec(output, rt.table, propertyKey) :: Nil
case AnalyzeTable(_: ResolvedTable, _, _) | AnalyzeColumn(_:
ResolvedTable, _, _) =>
diff --git
a/sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLParserSuite.scala
b/sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLParserSuite.scala
index 6c337e3..37e558a 100644
---
a/sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLParserSuite.scala
+++
b/sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLParserSuite.scala
@@ -48,6 +48,12 @@ class DDLParserSuite extends AnalysisTest with
SharedSparkSession {
comparePlans(plan, expected, checkAnalysis = false)
}
+ test("show current namespace") {
+ comparePlans(
+ parser.parsePlan("SHOW CURRENT NAMESPACE"),
+ ShowCurrentNamespaceCommand())
+ }
+
test("alter database - property values must be set") {
assertUnsupported(
sql = "ALTER DATABASE my_db SET DBPROPERTIES('key_without_value',
'key_with_value'='x')",
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]