srielau commented on code in PR #53530:
URL: https://github.com/apache/spark/pull/53530#discussion_r2704078815
##########
sql/core/src/main/scala/org/apache/spark/sql/scripting/SqlScriptingExecutionContext.scala:
##########
@@ -53,6 +55,108 @@ class SqlScriptingExecutionContext extends
SqlScriptingExecutionContextExtension
def currentFrame: SqlScriptingExecutionFrame = frames.last
def currentScope: SqlScriptingExecutionScope = currentFrame.currentScope
+ /**
+ * Find a cursor by its normalized name in the current scope and parent
scopes.
+ * Implementation of SqlScriptingExecutionContextExtension API.
+ *
+ * Searches current frame first (respects shadowing), then script frame (for
cross-frame access).
+ * This ensures cursors declared in handlers shadow cursors with the same
name in the script.
+ */
+ override def findCursorByName(normalizedName: String):
Option[CursorDefinition] = {
Review Comment:
A namespace is a domain of (qualified) names within which objects must be
unique.
For example: VIEW and TABLE sharte the same namespace. They are both
relations.
scalar FUNCTION, table FUNCTION and PROCEDURE share the same namespace. They
are all routines.
Things get more interesting with leaf nodes of expressions. These can be
variables, columns/aliases, or parameters. Hence more complicated occlusion
rules (columns in from, the lateral, within the statement, then local
variables, then parameters, then session varicbles).
Cursors are yet another namespace, and condition yet another.
Key is that distinct namespaces do not collide by definition.
So you can have a cursor with the same name as a local variable defined in
the same compound statement.
And you could declare a local table (if we had such a thing) with the same
name as a variable.
Specifically for cursors: They can only be referenced in OPEN, CLOSE, FETCH.
You cannot SET a cursor, or use it in an expression.
That's why when you pass a table to a polymorphic table function you have to
say foo(TABLE t). The table keyword makes it clear that t is not a variable, or
column, but a relation.
One of teh unsolved issues around "TABLEREF" is whether they can be used
directly or also need a keyword.
SELECT * FROM t;
How do we know t is a table ref from the variable namspace and not a
relation?
--
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]