Class AggregateRemoveDuplicateKeysRule

All Implemented Interfaces:
TransformationRule

@Enclosing public class AggregateRemoveDuplicateKeysRule extends RelRule<AggregateRemoveDuplicateKeysRule.Config> implements TransformationRule
Planner rule that removes redundant grouping keys from an Aggregate when the later keys are functionally determined by the earlier retained keys.

The original output schema is preserved by adding ANY_VALUE aggregate calls for removed grouping keys and then projecting the row back into the original field order.

The original SQL:


 SELECT deptno, name, count(*) AS c
 FROM sales.dept
 GROUP BY deptno, name
 

The original logical plan:

 LogicalAggregate(group=[{0, 1}], C=[COUNT()])
   LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
 

After optimization:

 LogicalAggregate(group=[{0}], NAME=[ANY_VALUE($1)], C=[COUNT()])
   LogicalTableScan(table=[[CATALOG, SALES, DEPT]])