dbatomic commented on code in PR #46665:
URL: https://github.com/apache/spark/pull/46665#discussion_r1606714783


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala:
##########
@@ -116,6 +116,78 @@ class AstBuilder extends DataTypeAstBuilder with 
SQLConfHelper with Logging {
     }
   }
 
+  override def visitBatchOrSingleStatement(ctx: 
BatchOrSingleStatementContext): BatchBody = {
+    if (ctx.batchCompound() != null) {
+      visit(ctx.batchCompound()).asInstanceOf[BatchBody]
+    } else {
+      val logicalPlan = visitSingleStatement(ctx.singleStatement())
+      BatchBody(List(SparkStatementWithPlan(
+        parsedPlan = logicalPlan,
+        sourceStart = ctx.start.getStartIndex,
+        sourceEnd = ctx.stop.getStopIndex + 1)))
+    }
+  }
+
+  override def visitBatchCompound(ctx: BatchCompoundContext): BatchBody = {
+    visitBatchBody(ctx.batchBody(), allowDeclareAtTop = true)
+  }
+
+  private def visitBatchBody(ctx: BatchBodyContext, allowDeclareAtTop: 
Boolean): BatchBody = {
+    val buff = ListBuffer[BatchPlanStatement]()
+    for (i <- 0 until ctx.getChildCount) {
+      val child = visit(ctx.getChild(i))
+      child match {
+        case statement: BatchPlanStatement => buff += statement
+        case null => // When terminal nodes are visited (like SEMICOLON, EOF, 
etc.)
+      }
+    }
+
+    val statements = buff.toList
+    if (allowDeclareAtTop) {

Review Comment:
   I think that we should move variable stuff to separate PR.



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

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to