Search in sources :

Example 21 with Aggregation

use of com.facebook.presto.spi.plan.AggregationNode.Aggregation in project presto by prestodb.

the class AddIntermediateAggregations method outputsAsInputs.

/**
 * Rewrite assignments so that inputs are in terms of the output symbols.
 * <p>
 * Example:
 * 'a' := sum('b') => 'a' := sum('a')
 * 'a' := count(*) => 'a' := count('a')
 */
private static Map<VariableReferenceExpression, Aggregation> outputsAsInputs(Map<VariableReferenceExpression, Aggregation> assignments) {
    ImmutableMap.Builder<VariableReferenceExpression, Aggregation> builder = ImmutableMap.builder();
    for (Map.Entry<VariableReferenceExpression, Aggregation> entry : assignments.entrySet()) {
        VariableReferenceExpression output = entry.getKey();
        Aggregation aggregation = entry.getValue();
        checkState(!aggregation.getOrderBy().isPresent(), "Intermediate aggregation does not support ORDER BY");
        builder.put(output, new Aggregation(new CallExpression(aggregation.getCall().getSourceLocation(), aggregation.getCall().getDisplayName(), aggregation.getCall().getFunctionHandle(), aggregation.getCall().getType(), ImmutableList.of(output)), Optional.empty(), Optional.empty(), false, // No mask for INTERMEDIATE
        Optional.empty()));
    }
    return builder.build();
}
Also used : Aggregation(com.facebook.presto.spi.plan.AggregationNode.Aggregation) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) CallExpression(com.facebook.presto.spi.relation.CallExpression) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

Aggregation (com.facebook.presto.spi.plan.AggregationNode.Aggregation)21 VariableReferenceExpression (com.facebook.presto.spi.relation.VariableReferenceExpression)19 AggregationNode (com.facebook.presto.spi.plan.AggregationNode)16 Map (java.util.Map)13 ImmutableMap (com.google.common.collect.ImmutableMap)11 CallExpression (com.facebook.presto.spi.relation.CallExpression)10 PlanNode (com.facebook.presto.spi.plan.PlanNode)7 Type (com.facebook.presto.common.type.Type)5 ProjectNode (com.facebook.presto.spi.plan.ProjectNode)5 Session (com.facebook.presto.Session)4 RowExpression (com.facebook.presto.spi.relation.RowExpression)4 ImmutableList (com.google.common.collect.ImmutableList)4 Pattern (com.facebook.presto.matching.Pattern)3 FunctionHandle (com.facebook.presto.spi.function.FunctionHandle)3 OriginalExpressionUtils (com.facebook.presto.sql.relational.OriginalExpressionUtils)3 Optional (java.util.Optional)3 Set (java.util.Set)3 Page (com.facebook.presto.common.Page)2 Block (com.facebook.presto.common.block.Block)2 BlockBuilder (com.facebook.presto.common.block.BlockBuilder)2