cetra3 opened a new pull request, #25891:
URL: https://github.com/apache/datafusion/pull/25891
## Which issue does this PR close?
- Closes #25890.
## Rationale for this change
`GROUP BY ROLLUP`, `CUBE`, or `GROUPING SETS` fails during analysis when a
member is a scalar function with an implicitly coerced literal argument, such
as `date_bin('5 minutes', ts)`:
```
type_coercion
caused by
Schema error: No field named "date_bin(Utf8(""5 minutes""),t.ts)". Did you
mean '"ROLLUP (date_bin(Utf8(""5 minutes""),t.ts))"'?
```
Type coercion now turns the literal into an interval value, which renames
the member. `TypeCoercion` then restored the original name by aliasing the
whole `Expr::GroupingSet`. An aliased grouping set is no longer recognized as a
grouping set: it becomes one ordinary group key named `ROLLUP (...)`, with no
`__grouping_id`, and the projection above can no longer find the member.
## What changes are included in this PR?
`TypeCoercion` now coerces each grouping set member individually through
`map_children`, saving and restoring each member's name, and leaves the
grouping set itself unaliased. This is the same approach `SimplifyExpressions`
has used since #14888.
## What is the testing strategy for this PR?
- New sqllogictest cases in `grouping.slt`: `ROLLUP` over the coerced member
with `grouping()` in the select list, and `GROUPING SETS` with a qualified
column next to the coerced member, which is repeated across sets. Both fail
without this change.
- New unit test `scalar_udf_in_grouping_set` in `type_coercion.rs`, checking
the analyzed plan shape and that a second coercion pass leaves the plan
unchanged.
## Are there any user-facing changes?
Queries of this shape now plan and run. No public API changes.
## AI assistance
This change was prepared with AI assistance. Assumptions called out for
reviewers:
- The fix is scoped to `TypeCoercion`. `SimplifyExpressions` already carries
the same grouping set workaround, and other rules that use `NamePreserver` on
an `Aggregate` could in principle hit the same whole-grouping-set alias. Moving
this into `NamePreserver` would fix it in one place, but changes the public
`SavedName` API, so I left that for a possible follow-up.
- Skipping `TypeCoercionRewriter` on the `Expr::GroupingSet` node itself
relies on the rewriter passing grouping sets through unchanged, which it does
today.
🤖 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]