You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "miland-db (via GitHub)" <gi...@apache.org> on 2025/06/12 11:58:29 UTC

[PR] [SQL][MINOR] Forbid duplicate SQLEXCEPTION and NOT FOUND handlers inside SQL Script [spark]

miland-db opened a new pull request, #51168:
URL: https://github.com/apache/spark/pull/51168

   ### What changes were proposed in this pull request?
   In this PR we forbid duplicate SQLEXCEPTION or NOT FOUND exception handlers to be defined in the same scope. This was already done for different conditions and sqlstates but was not done for these 2 types of exception handlers. Code like this should fail:
   
   ```
   BEGIN
     DECLARE EXIT HANDLER FOR NOT FOUND
     BEGIN
       SELECT 1;
     END;
     DECLARE EXIT HANDLER FOR NOT FOUND
     BEGIN
       SELECT 2;
     END;
   END
   ```
   
   ### Why are the changes needed?
   This is a bug fix.
   
   ### Does this PR introduce _any_ user-facing change?
   No.
   
   
   ### How was this patch tested?
   New tests in `SqlScriptingInterpreterSuite`.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   No.
   


-- 
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-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SQL][MINOR] Forbid duplicate SQLEXCEPTION and NOT FOUND handlers inside SQL Script [spark]

Posted by "miland-db (via GitHub)" <gi...@apache.org>.
miland-db commented on PR #51168:
URL: https://github.com/apache/spark/pull/51168#issuecomment-2966413284

   Adding @cloud-fan , @davidm-db, @MaxGekk 


-- 
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-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-52489][SQL] Forbid duplicate SQLEXCEPTION and NOT FOUND handlers inside SQL Script [spark]

Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan closed pull request #51168: [SPARK-52489][SQL] Forbid duplicate SQLEXCEPTION and NOT FOUND handlers inside SQL Script
URL: https://github.com/apache/spark/pull/51168


-- 
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-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SQL][MINOR] Forbid duplicate SQLEXCEPTION and NOT FOUND handlers inside SQL Script [spark]

Posted by "davidm-db (via GitHub)" <gi...@apache.org>.
davidm-db commented on code in PR #51168:
URL: https://github.com/apache/spark/pull/51168#discussion_r2144269663


##########
sql/core/src/main/scala/org/apache/spark/sql/scripting/SqlScriptingInterpreter.scala:
##########
@@ -122,12 +122,21 @@ case class SqlScriptingInterpreter(session: SparkSession) {
 
       // Get NOT FOUND handler.
       notFoundHandler = if (handler.exceptionHandlerTriggers.notFound) {
-        Some(handlerExec)
+        if (notFoundHandler.isDefined) {
+          throw SqlScriptingErrors.duplicateHandlerForSameCondition(CurrentOrigin.get, "NOT FOUND")
+        } else {
+          Some(handlerExec)
+        }
       } else None
 
       // Get SQLEXCEPTION handler.
       sqlExceptionHandler = if (handler.exceptionHandlerTriggers.sqlException) {
-        Some(handlerExec)
+        if (sqlExceptionHandler.isDefined) {
+          throw SqlScriptingErrors
+            .duplicateHandlerForSameCondition(CurrentOrigin.get, "SQLEXCEPTION")

Review Comment:
   Correct, we should fix this. We should read origins from respective logical plans, since each one of them has its own origin already set. Let's do this as a follow-up PR.



-- 
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-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SQL][MINOR] Forbid duplicate SQLEXCEPTION and NOT FOUND handlers inside SQL Script [spark]

Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on PR #51168:
URL: https://github.com/apache/spark/pull/51168#issuecomment-2974922850

   Let's create a JIRA ticket. This is not a minor change. Otherwise LGTM


-- 
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-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-52489][SQL] Forbid duplicate SQLEXCEPTION and NOT FOUND handlers inside SQL Script [spark]

Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on PR #51168:
URL: https://github.com/apache/spark/pull/51168#issuecomment-2986179882

   thanks, merging to master/4.0!


-- 
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-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SQL][MINOR] Forbid duplicate SQLEXCEPTION and NOT FOUND handlers inside SQL Script [spark]

Posted by "dusantism-db (via GitHub)" <gi...@apache.org>.
dusantism-db commented on code in PR #51168:
URL: https://github.com/apache/spark/pull/51168#discussion_r2143026247


##########
sql/core/src/main/scala/org/apache/spark/sql/scripting/SqlScriptingInterpreter.scala:
##########
@@ -122,12 +122,21 @@ case class SqlScriptingInterpreter(session: SparkSession) {
 
       // Get NOT FOUND handler.
       notFoundHandler = if (handler.exceptionHandlerTriggers.notFound) {
-        Some(handlerExec)
+        if (notFoundHandler.isDefined) {
+          throw SqlScriptingErrors.duplicateHandlerForSameCondition(CurrentOrigin.get, "NOT FOUND")
+        } else {
+          Some(handlerExec)
+        }
       } else None
 
       // Get SQLEXCEPTION handler.
       sqlExceptionHandler = if (handler.exceptionHandlerTriggers.sqlException) {
-        Some(handlerExec)
+        if (sqlExceptionHandler.isDefined) {
+          throw SqlScriptingErrors
+            .duplicateHandlerForSameCondition(CurrentOrigin.get, "SQLEXCEPTION")

Review Comment:
   Question unrelated to this PR, as I see we already utilize this. Do we know what CurrentOrigin.get is going to return in this situation? AFAIK during parsing, we use the withOrigin methods to scope the origin, and return it to the previous value after. At this point we're finished with parsing so I'm curious what would come up.



-- 
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-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SQL][MINOR] Forbid duplicate SQLEXCEPTION and NOT FOUND handlers inside SQL Script [spark]

Posted by "miland-db (via GitHub)" <gi...@apache.org>.
miland-db commented on code in PR #51168:
URL: https://github.com/apache/spark/pull/51168#discussion_r2145036845


##########
sql/core/src/main/scala/org/apache/spark/sql/scripting/SqlScriptingInterpreter.scala:
##########
@@ -122,12 +122,21 @@ case class SqlScriptingInterpreter(session: SparkSession) {
 
       // Get NOT FOUND handler.
       notFoundHandler = if (handler.exceptionHandlerTriggers.notFound) {
-        Some(handlerExec)
+        if (notFoundHandler.isDefined) {
+          throw SqlScriptingErrors.duplicateHandlerForSameCondition(CurrentOrigin.get, "NOT FOUND")
+        } else {
+          Some(handlerExec)
+        }
       } else None
 
       // Get SQLEXCEPTION handler.
       sqlExceptionHandler = if (handler.exceptionHandlerTriggers.sqlException) {
-        Some(handlerExec)
+        if (sqlExceptionHandler.isDefined) {
+          throw SqlScriptingErrors
+            .duplicateHandlerForSameCondition(CurrentOrigin.get, "SQLEXCEPTION")

Review Comment:
   I will create work item.



-- 
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-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SQL][MINOR] Forbid duplicate SQLEXCEPTION and NOT FOUND handlers inside SQL Script [spark]

Posted by "davidm-db (via GitHub)" <gi...@apache.org>.
davidm-db commented on code in PR #51168:
URL: https://github.com/apache/spark/pull/51168#discussion_r2144276844


##########
sql/core/src/main/scala/org/apache/spark/sql/scripting/SqlScriptingInterpreter.scala:
##########
@@ -122,12 +122,21 @@ case class SqlScriptingInterpreter(session: SparkSession) {
 
       // Get NOT FOUND handler.
       notFoundHandler = if (handler.exceptionHandlerTriggers.notFound) {
-        Some(handlerExec)
+        if (notFoundHandler.isDefined) {
+          throw SqlScriptingErrors.duplicateHandlerForSameCondition(CurrentOrigin.get, "NOT FOUND")
+        } else {
+          Some(handlerExec)
+        }
       } else None
 
       // Get SQLEXCEPTION handler.
       sqlExceptionHandler = if (handler.exceptionHandlerTriggers.sqlException) {
-        Some(handlerExec)
+        if (sqlExceptionHandler.isDefined) {
+          throw SqlScriptingErrors
+            .duplicateHandlerForSameCondition(CurrentOrigin.get, "SQLEXCEPTION")

Review Comment:
   @miland-db Please create a work item for this fix.



-- 
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-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SQL][MINOR] Forbid duplicate SQLEXCEPTION and NOT FOUND handlers inside SQL Script [spark]

Posted by "davidm-db (via GitHub)" <gi...@apache.org>.
davidm-db commented on code in PR #51168:
URL: https://github.com/apache/spark/pull/51168#discussion_r2144276844


##########
sql/core/src/main/scala/org/apache/spark/sql/scripting/SqlScriptingInterpreter.scala:
##########
@@ -122,12 +122,21 @@ case class SqlScriptingInterpreter(session: SparkSession) {
 
       // Get NOT FOUND handler.
       notFoundHandler = if (handler.exceptionHandlerTriggers.notFound) {
-        Some(handlerExec)
+        if (notFoundHandler.isDefined) {
+          throw SqlScriptingErrors.duplicateHandlerForSameCondition(CurrentOrigin.get, "NOT FOUND")
+        } else {
+          Some(handlerExec)
+        }
       } else None
 
       // Get SQLEXCEPTION handler.
       sqlExceptionHandler = if (handler.exceptionHandlerTriggers.sqlException) {
-        Some(handlerExec)
+        if (sqlExceptionHandler.isDefined) {
+          throw SqlScriptingErrors
+            .duplicateHandlerForSameCondition(CurrentOrigin.get, "SQLEXCEPTION")

Review Comment:
   @miland-db Please create a work item for this fix in case you are not going to fix it immediately, so it doesn't get forgotten.



-- 
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-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-52489][SQL] Forbid duplicate SQLEXCEPTION and NOT FOUND handlers inside SQL Script [spark]

Posted by "miland-db (via GitHub)" <gi...@apache.org>.
miland-db commented on code in PR #51168:
URL: https://github.com/apache/spark/pull/51168#discussion_r2149957133


##########
sql/core/src/main/scala/org/apache/spark/sql/scripting/SqlScriptingInterpreter.scala:
##########
@@ -122,12 +122,21 @@ case class SqlScriptingInterpreter(session: SparkSession) {
 
       // Get NOT FOUND handler.
       notFoundHandler = if (handler.exceptionHandlerTriggers.notFound) {
-        Some(handlerExec)
+        if (notFoundHandler.isDefined) {
+          throw SqlScriptingErrors.duplicateHandlerForSameCondition(CurrentOrigin.get, "NOT FOUND")
+        } else {
+          Some(handlerExec)
+        }
       } else None
 
       // Get SQLEXCEPTION handler.
       sqlExceptionHandler = if (handler.exceptionHandlerTriggers.sqlException) {
-        Some(handlerExec)
+        if (sqlExceptionHandler.isDefined) {
+          throw SqlScriptingErrors
+            .duplicateHandlerForSameCondition(CurrentOrigin.get, "SQLEXCEPTION")

Review Comment:
   Work item: [SPARK-52490](https://issues.apache.org/jira/browse/SPARK-52490)



-- 
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-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-52489][SQL] Forbid duplicate SQLEXCEPTION and NOT FOUND handlers inside SQL Script [spark]

Posted by "miland-db (via GitHub)" <gi...@apache.org>.
miland-db commented on PR #51168:
URL: https://github.com/apache/spark/pull/51168#issuecomment-2976515348

   Hey @cloud-fan, I created a JIRA ticket. Thanks for the review!


-- 
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-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SQL][MINOR] Forbid duplicate SQLEXCEPTION and NOT FOUND handlers inside SQL Script [spark]

Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on PR #51168:
URL: https://github.com/apache/spark/pull/51168#issuecomment-2968952346

   `SqlScriptingInterpreterSuite` fails


-- 
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-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org