Repository navigation
Commit 0566b55
fix: preserve grouping set member names during type coercion (#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)
Co-authored-by: Claude Opus 5.5 <[email protected]>1 parent 1814c6c commit 0566b55
2 files changed
Lines changed: 84 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
177 | 177 | | |
178 | 178 | | |
179 | 179 | | |
180 | | - | |
181 | | - | |
| 180 | + | |
182 | 181 | | |
183 | 182 | | |
184 | 183 | | |
| |||
192 | 191 | | |
193 | 192 | | |
194 | 193 | | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
195 | 205 | | |
196 | 206 | | |
197 | 207 | | |
| |||
1775 | 1785 | | |
1776 | 1786 | | |
1777 | 1787 | | |
1778 | | - | |
| 1788 | + | |
1779 | 1789 | | |
1780 | 1790 | | |
1781 | 1791 | | |
1782 | 1792 | | |
1783 | 1793 | | |
1784 | | - | |
| 1794 | + | |
1785 | 1795 | | |
1786 | 1796 | | |
1787 | 1797 | | |
| |||
2373 | 2383 | | |
2374 | 2384 | | |
2375 | 2385 | | |
| 2386 | + | |
| 2387 | + | |
| 2388 | + | |
| 2389 | + | |
| 2390 | + | |
| 2391 | + | |
| 2392 | + | |
| 2393 | + | |
| 2394 | + | |
| 2395 | + | |
| 2396 | + | |
| 2397 | + | |
| 2398 | + | |
| 2399 | + | |
| 2400 | + | |
| 2401 | + | |
| 2402 | + | |
| 2403 | + | |
| 2404 | + | |
| 2405 | + | |
| 2406 | + | |
| 2407 | + | |
| 2408 | + | |
| 2409 | + | |
| 2410 | + | |
| 2411 | + | |
| 2412 | + | |
| 2413 | + | |
| 2414 | + | |
| 2415 | + | |
| 2416 | + | |
| 2417 | + | |
| 2418 | + | |
| 2419 | + | |
| 2420 | + | |
2376 | 2421 | | |
2377 | 2422 | | |
2378 | 2423 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
445 | 445 | | |
446 | 446 | | |
447 | 447 | | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
0 commit comments