cloud-fan commented on code in PR #49427:
URL: https://github.com/apache/spark/pull/49427#discussion_r1938488686


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/SqlScriptingLogicalPlans.scala:
##########
@@ -298,3 +307,100 @@ case class ForStatement(
       ForStatement(query, variableName, body, label)
   }
 }
+
+/**
+ * Logical operator for an error condition.
+ * @param conditionName Name of the error condition.
+ * @param sqlState SQLSTATE or Error Code.
+ */
+case class ErrorCondition(
+    conditionName: String,
+    sqlState: String) extends CompoundPlanStatement {
+  override def output: Seq[Attribute] = Seq.empty
+
+  override def children: Seq[LogicalPlan] = Seq.empty
+
+  override protected def withNewChildrenInternal(
+      newChildren: IndexedSeq[LogicalPlan]): LogicalPlan = this.copy()
+}
+
+object HandlerType extends Enumeration {
+  type HandlerType = Value
+  val EXIT, CONTINUE = Value
+}
+
+/**
+ * Class holding information about what triggers the handler.
+ * @param sqlStates Set of sqlStates that will trigger handler.
+ * @param conditions  Set of error condition names that will trigger handler.
+ * @param sqlException Flag indicating if the handler is triggered by 
SQLEXCEPTION.
+ * @param notFound Flag indicating if the handler is triggered by NOT FOUND.
+ */
+class ExceptionHandlerTriggers(
+    val sqlStates: Set[String] = Set.empty,
+    val conditions: Set[String] = Set.empty,
+    var sqlException: Boolean = false,
+    var notFound: Boolean = false) {
+
+  def addUniqueSqlException(): Unit = {
+    if (sqlException) {
+      throw SqlScriptingErrors
+        .duplicateConditionInHandlerDeclaration(CurrentOrigin.get, 
"SQLEXCEPTION")
+    }
+    sqlException = true
+  }
+
+  def addUniqueNotFound(): Unit = {
+    if (notFound) {
+      throw SqlScriptingErrors
+        .duplicateConditionInHandlerDeclaration(CurrentOrigin.get, "NOT FOUND")
+    }
+    notFound = true
+  }
+
+  def addUniqueCondition(value: String): Unit = {
+    val uppercaseValue = value.toUpperCase(Locale.ROOT)
+    if (conditions.contains(uppercaseValue)) {
+      throw SqlScriptingErrors
+        .duplicateConditionInHandlerDeclaration(CurrentOrigin.get, 
uppercaseValue)
+    }
+    conditions += uppercaseValue
+  }
+
+  def addUniqueSqlState(value: String): Unit = {
+    val uppercaseValue = value.toUpperCase(Locale.ROOT)
+    if (sqlStates.contains(uppercaseValue)) {
+      throw SqlScriptingErrors
+        .duplicateSqlStateInHandlerDeclaration(CurrentOrigin.get, 
uppercaseValue)
+    }
+    sqlStates += uppercaseValue
+  }
+}
+
+/**
+ * Logical operator for an error handler.
+ * @param exceptionHandlerTriggers Collection of different handler triggers:
+ *        sqlStates -> set of sqlStates that will trigger handler
+ *        conditions -> set of conditions that will trigger handler
+ *        sqlException -> if handler is triggered by SQLEXCEPTION
+ *        notFound -> if handler is triggered by NotFound
+ * @param body CompoundBody of the handler.
+ * @param handlerType Type of the handler (CONTINUE or EXIT).
+ */
+case class ExceptionHandler(
+    exceptionHandlerTriggers: ExceptionHandlerTriggers,
+    body: CompoundBody,
+    handlerType: HandlerType) extends CompoundPlanStatement {

Review Comment:
   ditto, does it need to be a `CompoundPlanStatement`?



-- 
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]

Reply via email to