miland-db commented on code in PR #53530:
URL: https://github.com/apache/spark/pull/53530#discussion_r2692437434
##########
sql/core/src/main/scala/org/apache/spark/sql/scripting/SqlScriptingExecutionContext.scala:
##########
@@ -57,26 +57,86 @@ class SqlScriptingExecutionContext extends
SqlScriptingExecutionContextExtension
/**
* Find a cursor by its normalized name in the current scope and parent
scopes.
* Implementation of SqlScriptingExecutionContextExtension API.
+ *
+ * Searches across all frames (script frame first, then handler frames) to
support
+ * cursor access from exception handlers.
*/
override def findCursorByName(normalizedName: String):
Option[CursorDefinition] = {
if (frames.isEmpty) {
None
} else {
- currentFrame.findCursorByName(normalizedName)
+ // Search in script frame first (frames.head), then current frame
+ // This allows handlers to access cursors declared in the main script
+ frames.head.findCursorByName(normalizedName)
+ .orElse(if (frames.size > 1)
currentFrame.findCursorByName(normalizedName) else None)
Review Comment:
Is `normalizedName` a qualified cursor name? Asking because search logic is
to first try to resolve in main script and only then in handler, so I am
worried what happens when cursor is shadowed by creating another one in handler
with the same name as one in the main script. Which one would be found in that
case?
--
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]