Skip to content

[SPARK-54558][SQL] Fix Internal Exception when Exception Handlers with no BEGIN/END are used#53271

Closed
miland-db wants to merge 2 commits intoapache:masterfrom
miland-db:milan-dankovic_data/fix-no-body-handlers
Closed

[SPARK-54558][SQL] Fix Internal Exception when Exception Handlers with no BEGIN/END are used#53271
miland-db wants to merge 2 commits intoapache:masterfrom
miland-db:milan-dankovic_data/fix-no-body-handlers

Conversation

@miland-db
Copy link
Contributor

What changes were proposed in this pull request?

When Exception Handlers which don't have BEGIN-END body are triggered, internal exception java.util.NoSuchElementException was thrown instead of executing properly or propagating/raising the new error if it happens in handler.

BEGIN
  DECLARE EXIT HANDLER FOR SQLEXCEPTION
    SELECT 1;
  
  SELECT 1/0;
END 

Why are the changes needed?

Code was encountering a bug which throws internal error for what should be valid user code.

Does this PR introduce any user-facing change?

No.

How was this patch tested?

New unit tests in SqlScriptingExecutionSuite.

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

No.

@github-actions github-actions bot added the SQL label Dec 1, 2025
@miland-db
Copy link
Contributor Author

miland-db commented Dec 1, 2025

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

@miland-db
Copy link
Contributor Author

Hi @cloud-fan, failure in ProtobufCatalystDataConversionSuite does not look related to changes in this PR

@cloud-fan
Copy link
Contributor

thanks, merging to master/4.1!

@cloud-fan cloud-fan closed this in 4435a3a Dec 2, 2025
cloud-fan pushed a commit that referenced this pull request Dec 2, 2025
…h no BEGIN/END are used

### What changes were proposed in this pull request?
When Exception Handlers which don't have BEGIN-END body are triggered, internal exception `java.util.NoSuchElementException` was thrown instead of executing properly or propagating/raising the new error if it happens in handler.

```
BEGIN
  DECLARE EXIT HANDLER FOR SQLEXCEPTION
    SELECT 1;

  SELECT 1/0;
END
```

### Why are the changes needed?
Code was encountering a bug which throws internal error for what should be valid user code.

### Does this PR introduce _any_ user-facing change?
No.

### How was this patch tested?
New unit tests in `SqlScriptingExecutionSuite`.

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

Closes #53271 from miland-db/milan-dankovic_data/fix-no-body-handlers.

Authored-by: Milan Dankovic <milan.dankovic@databricks.com>
Signed-off-by: Wenchen Fan <wenchen@databricks.com>
(cherry picked from commit 4435a3a)
Signed-off-by: Wenchen Fan <wenchen@databricks.com>
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.

4 participants