cloud-fan commented on code in PR #49427:
URL: https://github.com/apache/spark/pull/49427#discussion_r1928116677
##########
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/parser/SqlScriptingParserSuite.scala:
##########
@@ -2317,6 +2332,223 @@ class SqlScriptingParserSuite extends SparkFunSuite
with SQLHelper {
head.asInstanceOf[SingleStatement].getText == "SELECT 3")
}
+ test("declare condition: custom sqlstate") {
+ val sqlScriptText =
+ """
+ |BEGIN
+ | DECLARE test CONDITION FOR SQLSTATE '12000';
+ | SELECT 1;
+ |END""".stripMargin
+ val tree = parsePlan(sqlScriptText).asInstanceOf[CompoundBody]
+ assert(tree.conditions.size == 1)
+ assert(tree.conditions("test").equals("12000"))
+ }
+
+ ignore("declare condition: default sqlstate") {
+ val sqlScriptText =
+ """
+ |BEGIN
+ | DECLARE test CONDITION;
+ |END""".stripMargin
+ val tree = parsePlan(sqlScriptText).asInstanceOf[CompoundBody]
+ assert(tree.conditions.size == 1)
+ assert(tree.conditions("test").equals("45000")) // Default SQLSTATE
+ }
+
+ test("declare condition in wrong place") {
+ val sqlScriptText =
+ """
+ |BEGIN
+ | SELECT 1;
+ | DECLARE test_condition CONDITION FOR SQLSTATE '12345';
+ |END""".stripMargin
+ val exception = intercept[SqlScriptingException] {
+ parsePlan(sqlScriptText)
+ }
+ checkError(
+ exception = exception,
+ condition = "INVALID_ERROR_CONDITION_DECLARATION.ONLY_AT_BEGINNING",
+ parameters = Map("conditionName" -> "`test_condition`"))
+ assert(exception.origin.line.contains(2))
+ }
+
+ test("declare qualified condition") {
+ val sqlScriptText =
+ """
+ |BEGIN
+ | DECLARE TEST.CONDITION CONDITION FOR SQLSTATE '12345';
+ |END""".stripMargin
+ val exception = intercept[SqlScriptingException] {
+ parsePlan(sqlScriptText)
+ }
+ checkError(
+ exception = exception,
+ condition =
"INVALID_ERROR_CONDITION_DECLARATION.QUALIFIED_CONDITION_NAME",
+ parameters = Map("conditionName" -> "TEST.CONDITION"))
+ assert(exception.origin.line.contains(3))
+ }
+
+ test("declare handler in wrong place") {
+ val sqlScriptText =
+ """
+ |BEGIN
+ | SELECT 1;
+ | DECLARE EXIT HANDLER FOR test_condition BEGIN SELECT 1; END;
Review Comment:
let's add a negative test for qualified condition name in the HANDLER.
--
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]