[ 
https://issues.apache.org/jira/browse/CALCITE-7479?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18076446#comment-18076446
 ] 

Zhen Chen commented on CALCITE-7479:
------------------------------------

Fixed in  
[{{0344850}}|https://github.com/apache/calcite/commit/0344850d5465bb4ce9af0640b1950920e5114ee5]

Thanks for review [~mbudiu] 

> Remove redundant aggregate group keys with FD
> ---------------------------------------------
>
>                 Key: CALCITE-7479
>                 URL: https://issues.apache.org/jira/browse/CALCITE-7479
>             Project: Calcite
>          Issue Type: New Feature
>          Components: core
>    Affects Versions: 1.41.0
>            Reporter: Zhen Chen
>            Priority: Minor
>              Labels: pull-request-available
>
> {*}Proposal{*}​
> Add a new {{AGGREGATE}} rewrite rule to identify and remove redundant 
> grouping keys from an {{AGGREGATE}} that are functionally determined by 
> preceding grouping keys. To preserve the original semantics, the rewrite will:
>  * Shorten the grouping key list of the {{AGGREGATE}}
>  * Use ANY_VALUE to restore the removed grouping column(s)
>  * Reorder the output columns to match the original order using a {{PROJECT}}
> {*}Example of the Planned Change{*}​
> Original SQL:
> {code:java}
> select deptno, name, count() as c
> from sales.dept
> group by deptno, name {code}
> Original plan:
> {code:java}
> LogicalAggregate(group=[{0, 1}], C=[COUNT()])
>   LogicalTableScan(table=[[CATALOG, SALES, DEPT]]) {code}
> Rewritten plan:
> {code:java}
> LogicalProject(DEPTNO=[$0], NAME=[$1], C=[$2])
>   LogicalAggregate(group=[{0}], NAME=[ANY_VALUE($1)], C=[COUNT()])
>     LogicalTableScan(table=[[CATALOG, SALES, DEPT]]) {code}
> {*}Explanation{*}​
> If {{{}name{}}}is functionally determined by {{{}deptno{}}}, then 
> {{{}name{}}}is removed from the grouping keys.
>  * ANY_VALUE is used to retain the value of the removed column semantically.
>  * The PROJECT restores the final output column order and field names.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to