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

   ### What changes were proposed in this pull request?
   
   Skip unbound lambda subtrees while resolving lateral column aliases. Lambda 
binding can then resolve references against the input before looking for 
aliases in the select list. Add DataFrame regressions and a migration note.
   
   ### Why are the changes needed?
   
   [SPARK-61768](https://issues.apache.org/jira/browse/SPARK-61768) reports 
that a DataFrame API reference inside a lambda can bind to an earlier alias 
instead of a same-named input column. The equivalent SQL query uses the input 
column. Early alias resolution can therefore change results or assign the wrong 
type to an expression.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes. For input `a=1, b=100, arr=[1,2]`, selecting `b AS a` and a DataFrame 
`transform(arr, x => x + col("a"))` now produces `[2,3]`, matching SQL, instead 
of `[101,102]`. The same input-column precedence applies to `withColumns` and 
nested lambdas.
   
   ### How was this patch tested?
   
   Before the fix, four new regression cases fail with lateral aliases enabled: 
`select`, `withColumns`, nested lambdas, and a map-valued reference shadowed by 
an integer alias. The same cases pass with lateral aliases disabled. Controls 
also verify SQL parity and valid references to preceding aliases when no input 
column has that name.
   
   - Complete `LateralColumnAliasSuiteBase` and `LateralColumnAliasSuite`: 39 
tests passed.
   - Scoped `DataFrameFunctionsSuite` coverage for transform/map functions, 
identifier resolution, and nested lambda captures: 15 tests passed.
   - Catalyst production and SQL test ScalaStyle: passed.
   - Apache RAT: passed with the repository exclusions plus the `.git` worktree 
metadata file.
   
   The SQL suites emitted possible-daemon-thread-leak warnings in baseline and 
patched runs; the patched checks exited successfully.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Generated-by: OpenAI Codex (gpt-6.1-sol; exact tool build unavailable). 
Codex assisted with the implementation, tests, migration note, and this 
description.
   


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