joelrobin18 opened a new pull request, #56321:
URL: https://github.com/apache/spark/pull/56321

   What changes were proposed in this pull request?
   This PR fixes variable resolution in the REPLACE WHERE clause of INSERT INTO 
statements.
   
   REPLACE WHERE is represented as OverwriteByExpression.deleteExpr during 
analysis. Previously, this expression was resolved only against the target 
table output because resolveExpressionByPlanOutput was called without 
includeLastResort = true.
   
   This PR enables last-resort resolution for OverwriteByExpression.deleteExpr, 
allowing SQL variables declared with DECLARE to be resolved in REPLACE WHERE 
predicates while preserving table-column precedence.
   
   Why are the changes needed?
   [SPARK-57260](https://issues.apache.org/jira/browse/SPARK-57260) reports 
that SQL variables can be used in the VALUES clause of INSERT INTO, but not in 
the REPLACE WHERE clause.
   
   For example, this previously failed during analysis:
   
   ```
   BEGIN
     DECLARE x INT DEFAULT 1;
     INSERT INTO table_y
       REPLACE WHERE y = x
       VALUES (x);
   END
   ```
   The predicate y = x could not resolve x as a SQL variable, resulting in an 
unresolved column/variable error.
   
   Does this PR introduce any user-facing change?
   Yes.
   
   INSERT INTO ... REPLACE WHERE can now resolve SQL variables declared with 
DECLARE in the REPLACE WHERE predicate.
   
   How was this patch tested?
   Added test coverage for variable resolution in INSERT INTO ... REPLACE 
WHERE, including:
   
   session variables
   SQL scripting local variables
   table-column precedence over SQL scripting variables
   
   Was this patch authored or co-authored using generative AI tooling?
   Generated-by: Cursor GPT-5.5


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