Class AggregateValuesRule

All Implemented Interfaces:
SubstitutionRule, TransformationRule

@Enclosing public class AggregateValuesRule extends RelRule<AggregateValuesRule.Config> implements SubstitutionRule
Rule that 1. applies Aggregate to a Values (currently just an empty Values). 2. Aggregate and Values to a distinct Values.

This is still useful because PruneEmptyRules.AGGREGATE_INSTANCE doesn't handle Aggregate, which is in turn because Aggregate of empty relations need some special handling: a single row will be generated, where each column's value depends on the specific aggregate calls (e.g. COUNT is 0, SUM is NULL).

Sample query where this matters:

SELECT COUNT(*) FROM s.foo WHERE 1 = 0

This rule only applies to "grand totals", that is, GROUP BY (). Any non-empty GROUP BY clause will return one row per group key value, and each group will consist of at least one row.

This is useful because SubQueryRemoveRule doesn't remove duplicates for IN filter values.

LogicalAggregate(group=[{0}]) LogicalValues(tuples=[[{ 1 }, { 1 }, { 3 }]])

With the Rule would deduplicate the values and convert to:

LogicalValues(tuples=[[{ 1 }, { 3 }]])
See Also: