imback82 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_r339350734
 
 

 ##########
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala
 ##########
 @@ -2877,4 +2877,28 @@ class AstBuilder(conf: SQLConf) extends 
SqlBaseBaseVisitor[AnyRef] with Logging
   override def visitRefreshTable(ctx: RefreshTableContext): LogicalPlan = 
withOrigin(ctx) {
     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) {
+    val table = visitMultipartIdentifier(ctx.tableName)
+    if (ctx.namespace != null) {
+      val namespace = visitMultipartIdentifier(ctx.namespace)
+      if (table.length > 1 && namespace.length > 1) {
+        throw new ParseException(
+          s"If namespace is defined, table can not be multipart: 
${table.mkString(".")}", ctx)
+      }
+      ShowColumnsStatement(table, Some(namespace))
+    } else {
+      ShowColumnsStatement(table, None)
+    }
+  }
 
 Review comment:
   You can simplify the code a bit if you want:
   ```scala
       val table = visitMultipartIdentifier(ctx.tableName)
       val namespace = 
Option(ctx.multipartIdentifier).map(visitMultipartIdentifier)
       if (namespace.isDefined && namespace.get.length > 1 && table.length > 1) 
{
         throw new ParseException(
           s"If namespace is defined, table can not be multipart: 
${table.mkString(".")}", ctx)
       }
       ShowColumnsStatement(table, namespace)
   ```

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to