davidm-db commented on code in PR #47423:
URL: https://github.com/apache/spark/pull/47423#discussion_r1713695736
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala:
##########
@@ -229,6 +273,29 @@ class AstBuilder extends DataTypeAstBuilder
)
}
+ override def visitDeclareCondition(ctx: DeclareConditionContext):
ErrorCondition = {
+ val conditionName = ctx.multipartIdentifier().getText
+ val conditionValue =
Option(ctx.stringLit()).map(_.getText).getOrElse("'45000'").
+ replace("'", "")
+
+ val sqlStateRegex = "^[A-Za-z0-9]{5}$".r
+ assert(sqlStateRegex.findFirstIn(conditionValue).isDefined)
+
+ ErrorCondition(conditionName, conditionValue)
+ }
+
+ override def visitDeclareHandler(ctx: DeclareHandlerContext): ErrorHandler =
{
+ val conditions = visit(ctx.conditionValueList()).asInstanceOf[Seq[String]]
+ val handlerType = Option(ctx.EXIT()).map(_ =>
HandlerType.EXIT).getOrElse(HandlerType.CONTINUE)
+
+ val body = Option(ctx.compoundBody()).map(visit).getOrElse {
+ val logicalPlan = visit(ctx.statement()).asInstanceOf[LogicalPlan]
+ CompoundBody(Seq(SingleStatement(parsedPlan = logicalPlan)))
+ }.asInstanceOf[CompoundBody]
Review Comment:
I would use the same logic as in `visitCompoundStatement` here - `Option`
checks for `statement` and `setStatementWithOptionalVarKeyword` and
`.getOrElse` for `visitChildren`. It will make it cleaner when you add
`setStatementWithOptionalVarKeyword` to the grammar rule.
--
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]