miland-db opened a new pull request, #53759:
URL: https://github.com/apache/spark/pull/53759
### What changes were proposed in this pull request?
This PR fixes a critical bug in `CONTINUE HANDLER` execution within loops.
When a `CONTINUE HANDLER` handled an exception that occurred inside a loop
body, the loop would exit completely instead of continuing to the next
iteration.
#### Root cause
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 to next iteration
The method unconditionally set `interrupted = true` on all conditional
statements, causing loops to exit even when the error occurred during body
execution.
#### The fix
The fix was to add `isInCondition: Boolean` method to
`ConditionalStatementExec` trait to track whether a conditional statement is
currently evaluating its condition or executing its body. It was also needed to
implement `isInCondition` for all 6 `ConditionalStatementExec`:
- IfElseStatementExec
- WhileStatementExec
- RepeatStatementExec
- ForStatementExec
- SearchedCaseStatementExec
- SimpleCaseStatementExec
### Why are the changes needed?
This ensures `CONTINUE HANDLER` only interrupts conditional statements when
exceptions occur during condition evaluation, allowing loops to continue
normally when exceptions occur in their bodies.
### Does this PR introduce _any_ user-facing change?
No.
### How was this patch tested?
Added comprehensive test coverage for `CONTINUE HANDLER` across all
conditional statement types. These tests verify that when an exception occurs
inside a loop body and is handled by a `CONTINUE HANDLER`, the loop continues
to the next iteration rather than exiting.
### Was this patch authored or co-authored using generative AI tooling?
<!--
If generative AI tooling has been used in the process of authoring this
patch, please include the
phrase: 'Generated-by: ' followed by the name of the tool and its version.
If no, write 'No'.
Please refer to the [ASF Generative Tooling
Guidance](https://www.apache.org/legal/generative-tooling.html) for details.
-->
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]