miland-db commented on code in PR #49427: URL: https://github.com/apache/spark/pull/49427#discussion_r1944352830
########## sql/core/src/test/scala/org/apache/spark/sql/scripting/SqlScriptingExecutionSuite.scala: ########## @@ -65,6 +69,557 @@ class SqlScriptingExecutionSuite extends QueryTest with SharedSparkSession { } } + // Handler tests + test("duplicate handler for the same condition") { + val sqlScript = + """ + |BEGIN + | DECLARE duplicate_condition CONDITION FOR SQLSTATE '12345'; + | DECLARE OR REPLACE flag INT = -1; + | DECLARE EXIT HANDLER FOR duplicate_condition + | BEGIN + | SET VAR flag = 1; + | END; + | DECLARE EXIT HANDLER FOR duplicate_condition + | BEGIN + | SET VAR flag = 2; + | END; + | SELECT 1/0; + | SELECT flag; + |END + |""".stripMargin + checkError( + exception = intercept[SqlScriptingException] { + verifySqlScriptResult(sqlScript, Seq.empty) + }, + condition = "DUPLICATE_EXCEPTION_HANDLER.CONDITION", + parameters = Map("condition" -> "DUPLICATE_CONDITION")) + } + + test("duplicate handler for the same sqlState") { + val sqlScript = + """ + |BEGIN + | DECLARE OR REPLACE flag INT = -1; + | DECLARE EXIT HANDLER FOR SQLSTATE '12345' + | BEGIN + | SET VAR flag = 1; + | END; + | DECLARE EXIT HANDLER FOR SQLSTATE '12345' + | BEGIN + | SET VAR flag = 2; + | END; + | SELECT 1/0; + | SELECT flag; + |END + |""".stripMargin + checkError( + exception = intercept[SqlScriptingException] { + verifySqlScriptResult(sqlScript, Seq.empty) + }, + condition = "DUPLICATE_EXCEPTION_HANDLER.SQLSTATE", + parameters = Map("sqlState" -> "12345")) + } + + test("Specific condition takes precedence over sqlState") { Review Comment: I will fix this. The issue is that zero division is not throwing an error when `SPARK_ANSI_SQL_MODE=false`. The solution can be to override this config for this suite, or to find some other error that has the same behavior regardless of the ANSI. Any thoughts @LuciferYang? -- 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