[CALCITE-7647] Support SELECT * in GROUP BY ALL and ORDER BY ALL#5089
[CALCITE-7647] Support SELECT * in GROUP BY ALL and ORDER BY ALL#5089tisyabhatia wants to merge 1 commit into
Conversation
Expand a bare or qualified star in the SELECT clause to its underlying columns when rewriting GROUP BY ALL / ORDER BY ALL, so those clauses no longer reject SELECT *. Star items are expanded via the existing column-enumeration path (matching normal SELECT * semantics, including NATURAL JOIN coalescing), before the placeholder is replaced with the concrete keys.
| * memoized grouping set with the not-yet-rewritten placeholder. The fresh | ||
| * {@code items}/{@code fields} must stay paired for NATURAL/USING index | ||
| * alignment. */ | ||
| private List<SqlNode> expandStarForAllRewrite(SqlSelect select, SqlNode starItem) { |
There was a problem hiding this comment.
how does this differ from expand star?
Can this be avoided by doing the rewriteOrderByAll after the star expansion?
There was a problem hiding this comment.
expandStarForAllRewrite just runs the normal star expansion on the *. I don't call the public expandStar because it expands the whole SELECT list before GROUP BY ALL is replaced and that makes the real columns look "not grouped."
There was a problem hiding this comment.
Could you give an example? I don't quite understand either.
There was a problem hiding this comment.
Let's say I had a query like SELECT *, UPPER(ename) FROM emp GROUP BY ALL. When we first type-check a column, we figure out which columns we're grouping by and cache that answer for good. So if I use the public expandStar, it type-checks UPPER(name) before I've replaced GROUP BY ALL with the actual columns. So internally, that stores "we don't have to group by anything." After that, I can't change the that memory. We get the error "Expression EMP.EMPNO is not being grouped."
It reports EMPNO (first column), not UPPER(ename).
Note: SELECT * FROM emp GROUP BY ALL works fine, but the extra UPPER(ename) makes Calcite type-check early.
This helper only touches the * so nothing gets locked in before we've decided the grouping columns.
|
|
|
||
| # [CALCITE-7647] GROUP BY ALL expands SELECT * to every underlying column; | ||
| # the star columns become grouping keys and the aggregate is excluded | ||
| select *, count(*) as c from (values (1, 'a'), (1, 'a'), (2, 'b')) as t(x, y) |
There was a problem hiding this comment.
I would like to know if this has been verified through specific database testing which @mihaibudiu also metioned in jira.



Jira Link
CALCITE-7647
Changes Proposed
Expand a bare or qualified star in the
SELECTclause to its underlying columns when rewritingGROUP BY ALL/ORDER BY ALL, so those clauses no longer rejectSELECT *. Star items are expanded via the existing column-enumeration path (matching normalSELECT *semantics), before the placeholder is replaced with the concrete keys.