dusantism-db commented on code in PR #49445:
URL: https://github.com/apache/spark/pull/49445#discussion_r1926754225


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala:
##########
@@ -139,6 +139,9 @@ object FakeV2SessionCatalog extends TableCatalog with 
FunctionCatalog with Suppo
  *                              even if a temp view `t` has been created.
  * @param outerPlan The query plan from the outer query that can be used to 
resolve star
  *                  expressions in a subquery.
+ * @param isExecuteImmediate Whether the current plan is created by EXECUTE 
IMMEDIATE. Used when
+ *                           resolving variables, as SQL Scripting local 
variables should not be
+ *                           visible from EXECUTE IMMEDIATE.

Review Comment:
   EXECUTE IMMEDIATE has 3 parts - SQL string, INTO clause and USING clause. 
INTO (set variables) and USING  (capture variables) should be able to access 
local variables, however the query generated by the SQL string should **not**. 
It should be run as if it's not in a script.
   
   We add `isExecuteImmediate` to `AnalysisContext` to know if we are in a plan 
generated by EXECUTE IMMEDIATE. If we are, we cannot access local variables.
   
   USING clause is resolved before the SQL string, at this point 
`isExecuteImmeidate` is not set and we normally access local variables.
   
   INTO clause is not resolved before SQL string, so we have to make an 
exception for it. Since it internally uses `SetVariable`, we add a flag 
`isExecuteImmediateIntoClause` to `SetVariable`, which allows access to local 
variables if set to `true`.



-- 
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: reviews-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to