davidm-db commented on code in PR #46665:
URL: https://github.com/apache/spark/pull/46665#discussion_r1633655767
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala:
##########
@@ -116,6 +116,57 @@ class AstBuilder extends DataTypeAstBuilder with
SQLConfHelper with Logging {
}
}
+ override def visitCompoundOrSingleStatement(
+ ctx: CompoundOrSingleStatementContext): CompoundBody = {
+ if (ctx.singleCompound() != null) {
+ visit(ctx.singleCompound()).asInstanceOf[CompoundBody]
+ } else {
+ val logicalPlan = visitSingleStatement(ctx.singleStatement())
+ CompoundBody(List(SparkStatementWithPlan(
+ parsedPlan = logicalPlan,
+ sourceStart = ctx.start.getStartIndex,
+ sourceEnd = ctx.stop.getStopIndex + 1)))
+ }
+ }
+
+ override def visitSingleCompound(ctx: SingleCompoundContext): CompoundBody =
{
+ visit(ctx.beginEndCompoundBlock()).asInstanceOf[CompoundBody]
+ }
+
+ private def visitCompoundBodyImpl(ctx: CompoundBodyContext): CompoundBody = {
+ val buff = ListBuffer[CompoundPlanStatement]()
+ for (i <- 0 until ctx.getChildCount) {
+ val child = ctx.getChild(i)
+ val visitedChild = visit(ctx.getChild(i))
+ visitedChild match {
+ case statement: CompoundPlanStatement => buff += statement
+ case null if child.isInstanceOf[TerminalNodeImpl] =>
Review Comment:
This basically happens within every SQL statement - `TerminalNodeImpl`
corresponds to keywords from the SQL grammar, so for example if the query is
like:
<img width="328" alt="image"
src="https://github.com/apache/spark/assets/163021185/3f033dd4-0fea-4274-883e-a40f910eb9d9">
Then, on the top level, `TerminalNodeImpl` are semicolons:
<img width="328" alt="image"
src="https://github.com/apache/spark/assets/163021185/f293b22c-609b-47e0-945e-69507970286f">
And then deeper in the tree it could be a `SELECT`:
<img width="1060" alt="image"
src="https://github.com/apache/spark/assets/163021185/d4636fa3-c6db-4771-950f-a915bca8aa74">
Or whichever other keyword.
--
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]