srielau commented on code in PR #53530:
URL: https://github.com/apache/spark/pull/53530#discussion_r2692868801


##########
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:
   Good catch.



-- 
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]

Reply via email to