davidm-db commented on code in PR #47423:
URL: https://github.com/apache/spark/pull/47423#discussion_r1713834953
##########
sql/core/src/main/scala/org/apache/spark/sql/scripting/SqlScriptingInterpreter.scala:
##########
@@ -58,44 +61,108 @@ case class SqlScriptingInterpreter() {
case _ => None
}
+ private def transformBodyIntoExec(
+ compoundBody: CompoundBody,
+ isExitHandler: Boolean = false,
+ label: String = ""): CompoundBodyExec = {
+ val variables = compoundBody.collection.flatMap {
+ case st: SingleStatement => getDeclareVarNameFromPlan(st.parsedPlan)
+ case _ => None
+ }
+ val dropVariables = variables
+ .map(varName => DropVariable(varName, ifExists = true))
+ .map(new SingleStatementExec(_, Origin(), isInternal = true))
+ .reverse
+
+ val conditionHandlerMap = mutable.HashMap[String, ErrorHandlerExec]()
+ val handlers = ListBuffer[ErrorHandlerExec]()
+ compoundBody.handlers.foreach(handler => {
+ val handlerBodyExec =
+ transformBodyIntoExec(handler.body,
+ handler.handlerType == HandlerType.EXIT,
+ compoundBody.label.get)
+ val handlerExec = new ErrorHandlerExec(handlerBodyExec)
+
+ handler.conditions.foreach(condition => {
+ val conditionValue = compoundBody.conditions.getOrElse(condition,
condition)
+ conditionHandlerMap.get(conditionValue) match {
+ case Some(_) =>
+ throw SqlScriptingErrors.duplicateHandlerForSameSqlState(
+ CurrentOrigin.get, conditionValue)
+ case None => conditionHandlerMap.put(conditionValue, handlerExec)
+ }
Review Comment:
transform this into if/else maybe, it would be easier to understand
--
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]