dbatomic commented on code in PR #47146: URL: https://github.com/apache/spark/pull/47146#discussion_r1670236815
########## sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala: ########## @@ -121,24 +121,40 @@ class AstBuilder extends DataTypeAstBuilder with SQLConfHelper with Logging { visit(s).asInstanceOf[CompoundBody] }.getOrElse { val logicalPlan = visitSingleStatement(ctx.singleStatement()) - CompoundBody(Seq(SingleStatement(parsedPlan = logicalPlan))) + CompoundBody(Seq(SingleStatement(parsedPlan = logicalPlan)), + java.util.UUID.randomUUID.toString) } } override def visitSingleCompoundStatement(ctx: SingleCompoundStatementContext): CompoundBody = { visit(ctx.beginEndCompoundBlock()).asInstanceOf[CompoundBody] } - private def visitCompoundBodyImpl(ctx: CompoundBodyContext): CompoundBody = { + private def visitCompoundBodyImpl(ctx: CompoundBodyContext, label: String = ""): CompoundBody = { val buff = ListBuffer[CompoundPlanStatement]() ctx.compoundStatements.forEach(compoundStatement => { buff += visit(compoundStatement).asInstanceOf[CompoundPlanStatement] }) - CompoundBody(buff.toSeq) + CompoundBody(buff.toSeq, label) } override def visitBeginEndCompoundBlock(ctx: BeginEndCompoundBlockContext): CompoundBody = { - visitCompoundBodyImpl(ctx.compoundBody()) + val beginLabelCtx = Option(ctx.beginLabel()) + val endLabelCtx = Option(ctx.endLabel()) + + (beginLabelCtx, endLabelCtx) match { + case (Some(bl: BeginLabelContext), Some(el: EndLabelContext)) + if bl.multipartIdentifier().getText.nonEmpty && + bl.multipartIdentifier().getText != el.multipartIdentifier().getText => + throw SparkException.internalError("Both labels should be same.") Review Comment: This should be `QueryParsingErrors` and not `internalError`. ########## sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala: ########## @@ -121,24 +121,40 @@ class AstBuilder extends DataTypeAstBuilder with SQLConfHelper with Logging { visit(s).asInstanceOf[CompoundBody] }.getOrElse { val logicalPlan = visitSingleStatement(ctx.singleStatement()) - CompoundBody(Seq(SingleStatement(parsedPlan = logicalPlan))) + CompoundBody(Seq(SingleStatement(parsedPlan = logicalPlan)), + java.util.UUID.randomUUID.toString) } } override def visitSingleCompoundStatement(ctx: SingleCompoundStatementContext): CompoundBody = { visit(ctx.beginEndCompoundBlock()).asInstanceOf[CompoundBody] } - private def visitCompoundBodyImpl(ctx: CompoundBodyContext): CompoundBody = { + private def visitCompoundBodyImpl(ctx: CompoundBodyContext, label: String = ""): CompoundBody = { val buff = ListBuffer[CompoundPlanStatement]() ctx.compoundStatements.forEach(compoundStatement => { buff += visit(compoundStatement).asInstanceOf[CompoundPlanStatement] }) - CompoundBody(buff.toSeq) + CompoundBody(buff.toSeq, label) } override def visitBeginEndCompoundBlock(ctx: BeginEndCompoundBlockContext): CompoundBody = { - visitCompoundBodyImpl(ctx.compoundBody()) + val beginLabelCtx = Option(ctx.beginLabel()) + val endLabelCtx = Option(ctx.endLabel()) + + (beginLabelCtx, endLabelCtx) match { + case (Some(bl: BeginLabelContext), Some(el: EndLabelContext)) + if bl.multipartIdentifier().getText.nonEmpty && + bl.multipartIdentifier().getText != el.multipartIdentifier().getText => + throw SparkException.internalError("Both labels should be same.") + case (None, Some(_)) => + throw SparkException.internalError("End label can't exist without begin label.") Review Comment: Same as above. -- 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-unsubscr...@spark.apache.org 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