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

   
   ### What changes were proposed in this pull request?
   
   Preserve original expression IDs in `ReplaceDeduplicateWithAggregate` when 
wrapping non-key columns in `First()` aliases.
   
   ### Why are the changes needed?
   
   When `dropDuplicates(columns)` is followed by `exceptAll`, the query fails 
with `INTERNAL_ERROR_ATTRIBUTE_NOT_FOUND` because 
`ReplaceDeduplicateWithAggregate` generates new expression IDs for non-key 
columns via `Alias(...)()`, but `RewriteExceptAll` (which runs in the same 
optimizer batch) has already captured references to the original expression 
IDs. The stale references cannot be resolved against the new Aggregate output.
   
   The fix passes `exprId = attr.exprId` to the `Alias` constructor so the 
aggregate output preserves the same expression IDs as the original 
`Deduplicate` output.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes. `df.dropDuplicates(columns).exceptAll(other)` and 
`.intersectAll(other)` no longer throw an internal error.
   
   ### How was this patch tested?
   
   - Unit test in `ReplaceOperatorSuite` verifying expression IDs are preserved 
after optimization.
   - End-to-end test in `DataFrameSuite` for `dropDuplicates(columns)` followed 
by `exceptAll` and `intersectAll`.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Yes. Generated-by: 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