cloud-fan commented on a change in pull request #26182: [SPARK-29523][SQL] SHOW
COLUMNS should do multi-catalog resolution.
URL: https://github.com/apache/spark/pull/26182#discussion_r340436799
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala
##########
@@ -2912,6 +2912,32 @@ class AstBuilder(conf: SQLConf) extends
SqlBaseBaseVisitor[AnyRef] with Logging
RefreshTableStatement(visitMultipartIdentifier(ctx.multipartIdentifier()))
}
+ /**
+ * A command for users to list the column names for a table.
+ * This function creates a [[ShowColumnsStatement]] logical plan.
+ *
+ * The syntax of using this command in SQL is:
+ * {{{
+ * SHOW COLUMNS (FROM | IN) tableName=multipartIdentifier
+ * ((FROM | IN) namespace=multipartIdentifier)?
+ * }}}
+ */
+ override def visitShowColumns(ctx: ShowColumnsContext): LogicalPlan =
withOrigin(ctx) {
+ import org.apache.spark.sql.connector.catalog.CatalogV2Implicits._
+
+ val table = visitMultipartIdentifier(ctx.table)
+ val namespace = Option(ctx.namespace).map(visitMultipartIdentifier)
+ if (namespace.isDefined && namespace.get.length > 1) {
+ throw new ParseException(
+ s"Namespace name should have only one part if specified:
${namespace.get.quoted}", ctx)
+ }
+ if (table.length > 2) {
+ throw new ParseException(
+ s"Table name should have at most two parts: ${table.quoted}", ctx)
+ }
Review comment:
This is a tricky problem. Ideally, we should have a check at the parser
that: if namespace is specified, then table name should be a single part.
Unfortunately we support `SHOW COLUMNS FROM db1.t1 IN db1`. To keep
supporting it, we can't check anything in the parser. In the analyzer, we can
add a check before converting to the v1 command: if namespace is specified, it
must be a single part, and the table name must have <= 2 parts.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]