miland-db commented on code in PR #49427:
URL: https://github.com/apache/spark/pull/49427#discussion_r1923911342


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala:
##########
@@ -159,15 +159,104 @@ class AstBuilder extends DataTypeAstBuilder
     script
   }
 
+  private def assertSqlState(sqlState: String): Unit = {
+    val sqlStateRegex = "^[A-Za-z0-9]{5}$".r
+    if (sqlStateRegex.findFirstIn(sqlState).isEmpty
+      || sqlState.startsWith("00")
+      || sqlState.startsWith("01")
+      || sqlState.startsWith("XX")) {
+      throw SqlScriptingErrors.invalidSqlStateValue(CurrentOrigin.get, 
sqlState)
+    }
+  }
+
+  override def visitConditionValue(ctx: ConditionValueContext): String = {
+    Option(ctx.sqlStateValue())
+      .map { sqlStateValueContext =>
+        val sqlState = sqlStateValueContext.getText.replace("'", "")
+        assertSqlState(sqlState)
+        sqlState
+      }
+      .getOrElse(ctx.getText)
+  }
+
+  override def visitConditionValues(ctx: ConditionValuesContext): Seq[String] 
= {
+    val buff = scala.collection.mutable.Set[String]()
+    ctx.cvList.forEach { conditionValue =>
+      val elem = visit(conditionValue).asInstanceOf[String]
+      if (buff(elem)) {
+        throw 
SqlScriptingErrors.duplicateConditionInHandlerDeclaration(CurrentOrigin.get, 
elem)
+      }
+      buff += elem
+    }
+    buff.toSeq
+  }
+
+  private def visitDeclareConditionStatementImpl(
+      ctx: DeclareConditionStatementContext): ErrorCondition = {
+    val conditionName = ctx.multipartIdentifier().getText

Review Comment:
   This will come in the follow-up PR, or together with `SIGNAL/RESIGNAL` 
statements.



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

Reply via email to