ulysses-you opened a new pull request, #60288: URL: https://github.com/apache/spark/pull/60288
### What changes were proposed in this pull request? Backport of #60236 to `branch-4.3`. Applies unchanged: no conflicts, and the cherry-pick's patch-id matches the master commit (`cherry picked from commit fea3ac7a665`). ### Why are the changes needed? `UnionExec.doConsume` projected each child column through an `Alias` 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 columns, and the generated row declared that input variable twice, which Janino rejects with "Redefinition of local variable". The fix reads the child row positionally, with one `BoundReference` per union output column, which is what `doExecute` already does. The repeated-`ExprId` shape needs `spark.sql.analyzer.unionIsResolvedWhenDuplicatesPerChildResolved=false` and `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. On `branch-4.3` the union whole-stage codegen is on by default. Unions whose child outputs do not repeat an `ExprId` are unaffected: binding by position and binding by `ExprId` pick the same position when the `ExprId` is unique. ### How was this patch tested? `UnionCodegenSuite`, `UnionCodegenAnsiSuite` and `UnionCodegenAqeSuite` pass 177/177 on `branch-4.3`, including the new `SPARK-61232` case, which runs in all three suites. ### Was this patch authored or co-authored using generative AI tooling? Yes. Generated-by: Claude Code. 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- 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]
