cloud-fan commented on a change in pull request #32442:
URL: https://github.com/apache/spark/pull/32442#discussion_r628032519



##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala
##########
@@ -193,13 +193,32 @@ class AstBuilder extends SqlBaseBaseVisitor[AnyRef] with 
SQLConfHelper with Logg
    * This is only used for Common Table Expressions.
    */
   override def visitNamedQuery(ctx: NamedQueryContext): SubqueryAlias = 
withOrigin(ctx) {
-    val subQuery: LogicalPlan = plan(ctx.query).optionalMap(ctx.columnAliases)(
+    val logicalPlan = Option(ctx.query).map(plan).orElse(
+      Option(ctx.ddlStatementForQuery).map(visitDdlStatementForQuery)).get
+    val subQuery: LogicalPlan = logicalPlan.optionalMap(ctx.columnAliases)(
       (columnAliases, plan) =>
         UnresolvedSubqueryColumnAliases(visitIdentifierList(columnAliases), 
plan)
     )
     SubqueryAlias(ctx.name.getText, subQuery)
   }
 
+  override def visitDdlQuery(ctx: DdlQueryContext): LogicalPlan = 
withOrigin(ctx) {
+    visitDdlStatementForQuery(ctx.ddlStatementForQuery())
+  }
+
+  def visitDdlStatementForQuery(ctx: DdlStatementForQueryContext): LogicalPlan 
= withOrigin(ctx) {
+    ctx match {
+      case namespaces: ShowNamespacesContext => visitShowNamespaces(namespaces)
+      case tables: ShowTablesContext => visitShowTables(tables)
+      case tblProperties: ShowTblPropertiesContext => 
visitShowTblProperties(tblProperties)
+      case partitions: ShowPartitionsContext => visitShowPartitions(partitions)
+      case columns: ShowColumnsContext => visitShowColumns(columns)
+      case views: ShowViewsContext => visitShowViews(views)
+      case functions: ShowFunctionsContext => visitShowFunctions(functions)
+      case _ => throw 
QueryParsingErrors.unsupportedDdlStatementForQueryError(ctx)

Review comment:
       This can't happen, and is an assert like error




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



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

Reply via email to