ulysses-you opened a new pull request, #60236:
URL: https://github.com/apache/spark/pull/60236

   ### What changes were proposed in this pull request?
   
   `UnionExec.doConsume` projected each child column through an `Alias` over 
the child's
   `Attribute` and bound it with `BindReferences`, which resolves an `ExprId` 
to its first
   occurrence in the child's output. A child output that repeats an `ExprId` (a 
union that
   concatenates a `SELECT p, p, w` branch) therefore read the first position 
for both, so the
   second union output column took the first column's value, and the generated 
row declared
   that input variable twice, which Janino rejects with "Redefinition of local 
variable".
   
   Read the child row positionally instead: one `BoundReference` per union 
output column at
   its own position. That is what `doExecute` does, since it concatenates child 
rows as they
   are. `perChildProjections`, its `Alias` wrapper and the `BindReferences` 
call are removed.
   
   ### Why are the changes needed?
   
   The union's whole-stage codegen path has to keep each output column at its 
own position,
   not at the first occurrence of its `ExprId`: otherwise the wrong column is 
read and the
   shared input variable's declaration is emitted twice, which fails the stage.
   
   The union whole-stage codegen was added in 4.2.0 (SPARK-56482); it is off by 
default on the
   4.2 line and on by default from 4.3. The repeated-`ExprId` shape also needs 
the two
   analyzer confs below disabled, so the default analyzer path never reaches it:
   
   - `spark.sql.analyzer.unionIsResolvedWhenDuplicatesPerChildResolved=false`
   - `spark.sql.enforceTypeCoercionBeforeUnionDeduplication.enabled=false`
   
   The analyzer otherwise removes a repeated output column with 
`DeduplicateUnionChildOutput`.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes, a bug fix. Unions that do not repeat an `ExprId` in a child's output 
are unaffected:
   binding by position and binding by `ExprId` pick the same position when the 
`ExprId` is
   unique. Only the union's whole-stage codegen path changes; `doExecute` was 
already
   positional.
   
   ### How was this patch tested?
   
   Added a `SPARK-61232` case to `UnionCodegenSuite`. It builds the 
repeated-`ExprId` shape,
   asserts that the plan still carries a union child with a repeated `ExprId` 
and that the
   outer union fuses over its query stages, and compares the fused result with 
the interpreted
   one. Before the fix it fails with the Janino redefinition; after it, 
`UnionCodegenSuite`,
   `UnionCodegenAnsiSuite` and `UnionCodegenAqeSuite` pass 177/177.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Yes, with Claude Code.
   
   Assisted-by: deepseek-flash
   


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