srielau commented on code in PR #52334:
URL: https://github.com/apache/spark/pull/52334#discussion_r2433408649
##########
sql/core/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveExecuteImmediate.scala:
##########
@@ -84,23 +86,44 @@ case class ResolveExecuteImmediate(sparkSession:
SparkSession, catalogManager: C
// Extract the query string from the queryParam expression
val sqlString = extractQueryString(sqlStmtStr)
- // Parse and validate the query
- val parsedPlan = sparkSession.sessionState.sqlParser.parsePlan(sqlString)
- validateQuery(sqlString, parsedPlan)
+ // Create the origin for EXECUTE IMMEDIATE context - this will be used by
expressions
+ // during parsing to set their queryContext, similar to how views work
+ val executeImmediateOrigin = Origin(
+ objectType = Some("EXECUTE IMMEDIATE"),
+ objectName = None, // No named object for EXECUTE IMMEDIATE, unlike views
+ sqlText = Some(sqlString),
+ startIndex = Some(0),
+ stopIndex = Some(sqlString.length - 1)
+ )
+
+ // Execute the query recursively with isolated local variable context and
EXECUTE IMMEDIATE
+ // origin. The isolation must cover parsing, analysis, and execution
phases.
+ // CurrentOrigin.withOrigin ensures expressions created during parsing get
the proper context
+ val result = withIsolatedLocalVariableContext {
+ CurrentOrigin.withOrigin(executeImmediateOrigin) {
+ // Parse and validate the query inside the isolation context to ensure
+ // local variables are not accessible during parsing
+ if (args.isEmpty) {
+ val parsedPlan =
sparkSession.sessionState.sqlParser.parsePlan(sqlString)
Review Comment:
We are blocking SQL Scripting here which is an existing limitations. I'm
updating teh comment.
--
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]