davidm-db commented on code in PR #46665:
URL: https://github.com/apache/spark/pull/46665#discussion_r1607338855
##########
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:
Done. Removed exceptions as well, since we needed them only for variable
stuff... Created a separate work item to add exception support (saved the code
as well, so it's easy to do it).
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/ParserInterface.scala:
##########
@@ -62,4 +62,10 @@ trait ParserInterface extends DataTypeParserInterface {
*/
@throws[ParseException]("Text cannot be parsed to a LogicalPlan")
def parseQuery(sqlText: String): LogicalPlan
+
+ /**
+ * Parse a query string to a [[BatchBody]].
+ */
+ @throws[ParseException]("")
Review Comment:
Done.
--
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]