Skip to content

Conversation

@miland-db
Copy link
Contributor

What changes were proposed in this pull request?

An unexpected behavior happens when an EXIT handler inside of an outer scope gets triggered by an exception inside an EXIT handler thats inside an inner nested scope: instead of leaving the outer scope after finishing all the exception handling, execution only leaves the inner scope.

In the example below, execution returns 3, 2 at the end, but it shouldn't reach that part of the code.

BEGIN
  DECLARE VARIABLE flag INT = -1;
  l1: BEGIN
    DECLARE EXIT HANDLER FOR UNRESOLVED_COLUMN.WITHOUT_SUGGESTION
    BEGIN
      SELECT flag;
      SET flag = 2;
    END;
    l2: BEGIN
      DECLARE EXIT HANDLER FOR DIVIDE_BY_ZERO
      BEGIN
        SELECT flag;
        SET flag = 1;
        select X; -- select non existing variable
        SELECT 2;
      END;
      SELECT 5;
      SELECT 1/0; -- divide by zero
      SELECT 6;
    END l2;
    SELECT 3, flag;
  END l1;
END 

In this PR I propose a fix for this issue.

Why are the changes needed?

This change is needed to fix the correctness behavior of the SQL Scripting engine.

Does this PR introduce any user-facing change?

No.

How was this patch tested?

New unit tests.

Was this patch authored or co-authored using generative AI tooling?

No.

@github-actions
Copy link

JIRA Issue Information

=== Sub-task SPARK-53758 ===
Summary: [M1] EXIT handler not exiting properly if triggered from another EXIT handler
Assignee: None
Status: Open
Affected: ["4.1.0","4.0.1"]


This comment was automatically generated by GitHub Actions

@github-actions github-actions bot added the SQL label Jan 10, 2026
@miland-db
Copy link
Contributor Author

cc @cloud-fan

@cloud-fan
Copy link
Contributor

SqlScriptingExecutionSuite fails...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants