mihailotim-db opened a new pull request, #55606:
URL: https://github.com/apache/spark/pull/55606

   ## What changes were proposed in this pull request?
   
     Wrap outer star expansion results in Alias in 
ResolveReferences.expandStarExpressionInValidOperators. When a targeted star 
(e.g. t1.*)
      inside a scalar subquery resolves from the outer scope, each expanded 
attribute is now wrapped in Alias(OuterReference(attr), name)
     instead of bare OuterReference(attr).
   
     For struct star expansion (e.g. t1.s.*), the expansion already produces 
Alias(GetStructField(...), fieldName). In that case we wrap
     only the inner child with OuterReference, preserving the existing Alias to 
avoid double aliasing.
   
   ## Why are the changes needed?
   
     Without the Alias, the OuterReference attribute's ExprId leaks into the 
subquery scope via Project.output (since
     OuterReference.toAttribute strips the wrapper). When a derived table wraps 
the outer star expansion, downstream operators (e.g. SELECT
      *) reference this leaked ExprId directly, which can cause issues with 
expression ID tracking. Wrapping in Alias gives each outer
     reference a fresh ExprId in the subquery's scope.
   
     Example:
     SELECT (SELECT * FROM (SELECT t1.* FROM VALUES(2) AS t2(col1) LIMIT 1)) 
FROM VALUES(1) AS t1(col1)
   
   ## Does this PR introduce any user-facing change?
   
     No.
   
   ## How was this patch tested?
   
     Added SQL golden file tests in scalar-subquery-select.sql:
     - Outer star expansion (t1.* from outer scope)
     - Outer struct star expansion (t1.s.*)
     - Untargeted star does NOT expand from outer scope
     - Inner scope wins when both match
     - Outer star through derived table wrapper
   
     Also fixed a pre-existing missing semicolon in the test file.
   
   ## Was this patch authored or co-authored using generative AI tooling?
   
     Generated-by: Claude Code (claude-opus-4-6)


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