You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "davidm-db (via GitHub)" <gi...@apache.org> on 2024/07/23 14:13:15 UTC
Re: [PR] [WIP][SPARK-48347][SQL] Support for WHILE statement [spark]
davidm-db commented on code in PR #47462:
URL: https://github.com/apache/spark/pull/47462#discussion_r1688142916
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala:
##########
@@ -133,39 +133,90 @@ class AstBuilder extends DataTypeAstBuilder with SQLConfHelper with Logging {
private def visitCompoundBodyImpl(
ctx: CompoundBodyContext,
- label: Option[String]): CompoundBody = {
+ label: Option[String],
+ allowVarDeclare: Boolean): CompoundBody = {
val buff = ListBuffer[CompoundPlanStatement]()
ctx.compoundStatements.forEach(compoundStatement => {
buff += visit(compoundStatement).asInstanceOf[CompoundPlanStatement]
})
+ val compoundStatements = buff.toList
+
+ if (allowVarDeclare) {
+ val declareAfterPrefix = compoundStatements
+ .dropWhile(statement => statement.isInstanceOf[SingleStatement] &&
+ statement.asInstanceOf[SingleStatement].parsedPlan.isInstanceOf[CreateVariable])
+ .filter(_.isInstanceOf[SingleStatement])
+ .find(_.asInstanceOf[SingleStatement].parsedPlan.isInstanceOf[CreateVariable])
+
+ declareAfterPrefix match {
+ case Some(SingleStatement(parsedPlan)) =>
+ throw SqlScriptingErrors.variableDeclarationOnlyAtBeginning(
+ parsedPlan.asInstanceOf[CreateVariable].name.
+ asInstanceOf[UnresolvedIdentifier].nameParts.last,
+ parsedPlan.origin.line.get.toString)
+ case _ =>
+ }
+
+ } else {
+ val declare = compoundStatements
+ .filter(_.isInstanceOf[SingleStatement])
+ .find(_.asInstanceOf[SingleStatement].parsedPlan.isInstanceOf[CreateVariable])
+
+ declare match {
+ case Some(SingleStatement(parsedPlan)) =>
+ throw SqlScriptingErrors.variableDeclarationOnlyAtBeginning(
+ parsedPlan.asInstanceOf[CreateVariable].name.
+ asInstanceOf[UnresolvedIdentifier].nameParts.last,
+ parsedPlan.origin.line.get.toString)
+ case _ =>
+ }
+ }
+
CompoundBody(buff.toSeq, label)
}
- override def visitBeginEndCompoundBlock(ctx: BeginEndCompoundBlockContext): CompoundBody = {
- val beginLabelCtx = Option(ctx.beginLabel())
- val endLabelCtx = Option(ctx.endLabel())
+ private def generateLabelText(
Review Comment:
nit: indentation for parameters. also, even though it's private function, it's nice to provide return type for function declaration.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org