Milan Dankovic created SPARK-55005:
--------------------------------------

             Summary: CONTINUE handler not working properly when exception 
occurs inside loops
                 Key: SPARK-55005
                 URL: https://issues.apache.org/jira/browse/SPARK-55005
             Project: Spark
          Issue Type: Sub-task
          Components: Spark Core
    Affects Versions: 4.2.0
            Reporter: Milan Dankovic


In the example below, after continue handler is executed, the whole loop will 
be skipped instead of continuing with iteration. The bug was introduced in this 
PR: [https://github.com/apache/spark/pull/52371], because the 
interruptConditionalStatements method in SqlScriptingExecution.scala was 
designed to skip conditional statements when exceptions occurred in their 
condition evaluation (e.g., WHILE 1/0 > 0). However, it didn't distinguish 
between:
 * Exception in condition → loop should be skipped

 * Exception in body → loop should continue iteration

 
 

 
{code:java}
BEGIN
  -- Multi-variable declaration (New in 4.1)
  DECLARE x, y = 1;
  
  -- Define error handling logic
  DECLARE CONTINUE HANDLER FOR DIVIDE_BY_ZERO
  BEGIN
    SET y = -1;
  END;
  -- Loop logic
  WHILE x < 8 DO
    SET x = x + 1;
    -- This might throw a divide-by-zero error, but the handler will catch it
    SET y = y / (x - 3); 
  END WHILE;
  SELECT x, y;
END;
{code}
 



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to