Search in sources :

Example 1 with SINGLE

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

the class SingleDistinctAggregationToGroupBy method apply.

@Override
public Result apply(AggregationNode aggregation, Captures captures, Context context) {
    List<Set<RowExpression>> argumentSets = extractArgumentSets(aggregation).collect(Collectors.toList());
    Set<VariableReferenceExpression> variables = Iterables.getOnlyElement(argumentSets).stream().map(OriginalExpressionUtils::castToExpression).map(context.getVariableAllocator()::toVariableReference).collect(Collectors.toSet());
    return Result.ofPlanNode(new AggregationNode(aggregation.getSourceLocation(), aggregation.getId(), new AggregationNode(aggregation.getSourceLocation(), context.getIdAllocator().getNextId(), aggregation.getSource(), ImmutableMap.of(), singleGroupingSet(ImmutableList.<VariableReferenceExpression>builder().addAll(aggregation.getGroupingKeys()).addAll(variables).build()), ImmutableList.of(), SINGLE, Optional.empty(), Optional.empty()), // remove DISTINCT flag from function calls
    aggregation.getAggregations().entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> removeDistinct(e.getValue()))), aggregation.getGroupingSets(), emptyList(), aggregation.getStep(), aggregation.getHashVariable(), aggregation.getGroupIdVariable()));
}
Also used : RowExpression(com.facebook.presto.spi.relation.RowExpression) Iterables(com.google.common.collect.Iterables) AggregationNode(com.facebook.presto.spi.plan.AggregationNode) Patterns.aggregation(com.facebook.presto.sql.planner.plan.Patterns.aggregation) ImmutableMap(com.google.common.collect.ImmutableMap) OriginalExpressionUtils(com.facebook.presto.sql.relational.OriginalExpressionUtils) Collections.emptyList(java.util.Collections.emptyList) Rule(com.facebook.presto.sql.planner.iterative.Rule) Captures(com.facebook.presto.matching.Captures) Set(java.util.Set) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) SINGLE(com.facebook.presto.spi.plan.AggregationNode.Step.SINGLE) Collectors(java.util.stream.Collectors) Pattern(com.facebook.presto.matching.Pattern) HashSet(java.util.HashSet) List(java.util.List) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Stream(java.util.stream.Stream) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) Aggregation(com.facebook.presto.spi.plan.AggregationNode.Aggregation) Optional(java.util.Optional) AggregationNode.singleGroupingSet(com.facebook.presto.spi.plan.AggregationNode.singleGroupingSet) Set(java.util.Set) HashSet(java.util.HashSet) AggregationNode.singleGroupingSet(com.facebook.presto.spi.plan.AggregationNode.singleGroupingSet) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) AggregationNode(com.facebook.presto.spi.plan.AggregationNode) OriginalExpressionUtils(com.facebook.presto.sql.relational.OriginalExpressionUtils) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map)

Example 2 with SINGLE

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

the class TestPushPartialAggregationThroughExchange method testNoPartialAggregationWhenReductionBelowThreshold.

@Test
public void testNoPartialAggregationWhenReductionBelowThreshold() {
    tester().assertThat(new PushPartialAggregationThroughExchange(getFunctionManager())).setSystemProperty(PARTIAL_AGGREGATION_STRATEGY, "AUTOMATIC").on(p -> {
        VariableReferenceExpression a = p.variable("a", DOUBLE);
        VariableReferenceExpression b = p.variable("b", DOUBLE);
        return p.aggregation(ab -> ab.source(p.exchange(e -> e.addSource(p.values(new PlanNodeId("values"), a, b)).addInputsSet(a, b).singleDistributionPartitioningScheme(a, b))).addAggregation(p.variable("SUM", DOUBLE), expression("SUM(a)"), ImmutableList.of(DOUBLE)).singleGroupingSet(b).step(SINGLE));
    }).overrideStats("values", PlanNodeStatsEstimate.builder().setOutputRowCount(1000).addVariableStatistics(variable("b", DOUBLE), new VariableStatsEstimate(0, 100, 0, 8, 800)).setConfident(true).build()).doesNotFire();
}
Also used : PARTIAL(com.facebook.presto.spi.plan.AggregationNode.Step.PARTIAL) PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) PlanNodeStatsEstimate(com.facebook.presto.cost.PlanNodeStatsEstimate) PlanMatchPattern.project(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.project) ImmutableMap(com.google.common.collect.ImmutableMap) DOUBLE(com.facebook.presto.common.type.DoubleType.DOUBLE) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) Test(org.testng.annotations.Test) PlanMatchPattern.exchange(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.exchange) SINGLE(com.facebook.presto.spi.plan.AggregationNode.Step.SINGLE) BaseRuleTest(com.facebook.presto.sql.planner.iterative.rule.test.BaseRuleTest) ImmutableList(com.google.common.collect.ImmutableList) PlanMatchPattern.values(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.values) Expressions.variable(com.facebook.presto.sql.relational.Expressions.variable) VariableStatsEstimate(com.facebook.presto.cost.VariableStatsEstimate) PlanBuilder.expression(com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder.expression) PlanMatchPattern.functionCall(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.functionCall) PARTIAL_AGGREGATION_STRATEGY(com.facebook.presto.SystemSessionProperties.PARTIAL_AGGREGATION_STRATEGY) PlanMatchPattern.aggregation(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.aggregation) PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) VariableStatsEstimate(com.facebook.presto.cost.VariableStatsEstimate) Test(org.testng.annotations.Test) BaseRuleTest(com.facebook.presto.sql.planner.iterative.rule.test.BaseRuleTest)

Example 3 with SINGLE

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

the class TestValidateStreamingAggregations method testValidateSuccessful.

@Test
public void testValidateSuccessful() {
    validatePlan(p -> p.aggregation(a -> a.step(SINGLE).singleGroupingSet(p.variable("nationkey")).source(p.tableScan(nationTableHandle, ImmutableList.of(p.variable("nationkey", BIGINT)), ImmutableMap.of(p.variable("nationkey", BIGINT), new TpchColumnHandle("nationkey", BIGINT))))));
    validatePlan(p -> p.aggregation(a -> a.step(SINGLE).singleGroupingSet(p.variable("unique"), p.variable("nationkey")).preGroupedVariables(p.variable("unique"), p.variable("nationkey")).source(p.assignUniqueId(p.variable("unique"), p.tableScan(nationTableHandle, ImmutableList.of(p.variable("nationkey", BIGINT)), ImmutableMap.of(p.variable("nationkey", BIGINT), new TpchColumnHandle("nationkey", BIGINT)))))));
}
Also used : WarningCollector(com.facebook.presto.spi.WarningCollector) BasePlanTest(com.facebook.presto.sql.planner.assertions.BasePlanTest) Test(org.testng.annotations.Test) SINGLE(com.facebook.presto.spi.plan.AggregationNode.Step.SINGLE) PrestoException(com.facebook.presto.spi.PrestoException) Function(java.util.function.Function) TpchTableLayoutHandle(com.facebook.presto.tpch.TpchTableLayoutHandle) TEST_SESSION(com.facebook.presto.SessionTestUtils.TEST_SESSION) ImmutableList(com.google.common.collect.ImmutableList) TypeProvider(com.facebook.presto.sql.planner.TypeProvider) PlanBuilder(com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder) TableHandle(com.facebook.presto.spi.TableHandle) BIGINT(com.facebook.presto.common.type.BigintType.BIGINT) PlanNodeIdAllocator(com.facebook.presto.spi.plan.PlanNodeIdAllocator) ImmutableMap(com.google.common.collect.ImmutableMap) BeforeClass(org.testng.annotations.BeforeClass) TestingTransactionHandle(com.facebook.presto.testing.TestingTransactionHandle) TupleDomain(com.facebook.presto.common.predicate.TupleDomain) SqlParser(com.facebook.presto.sql.parser.SqlParser) PlanNode(com.facebook.presto.spi.plan.PlanNode) TpchTableHandle(com.facebook.presto.tpch.TpchTableHandle) TpchColumnHandle(com.facebook.presto.tpch.TpchColumnHandle) Optional(java.util.Optional) ConnectorId(com.facebook.presto.spi.ConnectorId) Metadata(com.facebook.presto.metadata.Metadata) TpchColumnHandle(com.facebook.presto.tpch.TpchColumnHandle) BasePlanTest(com.facebook.presto.sql.planner.assertions.BasePlanTest) Test(org.testng.annotations.Test)

Aggregations

SINGLE (com.facebook.presto.spi.plan.AggregationNode.Step.SINGLE)3 ImmutableList (com.google.common.collect.ImmutableList)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 VariableReferenceExpression (com.facebook.presto.spi.relation.VariableReferenceExpression)2 Optional (java.util.Optional)2 Test (org.testng.annotations.Test)2 TEST_SESSION (com.facebook.presto.SessionTestUtils.TEST_SESSION)1 PARTIAL_AGGREGATION_STRATEGY (com.facebook.presto.SystemSessionProperties.PARTIAL_AGGREGATION_STRATEGY)1 TupleDomain (com.facebook.presto.common.predicate.TupleDomain)1 BIGINT (com.facebook.presto.common.type.BigintType.BIGINT)1 DOUBLE (com.facebook.presto.common.type.DoubleType.DOUBLE)1 PlanNodeStatsEstimate (com.facebook.presto.cost.PlanNodeStatsEstimate)1 VariableStatsEstimate (com.facebook.presto.cost.VariableStatsEstimate)1 Captures (com.facebook.presto.matching.Captures)1 Pattern (com.facebook.presto.matching.Pattern)1 Metadata (com.facebook.presto.metadata.Metadata)1 ConnectorId (com.facebook.presto.spi.ConnectorId)1 PrestoException (com.facebook.presto.spi.PrestoException)1 TableHandle (com.facebook.presto.spi.TableHandle)1 WarningCollector (com.facebook.presto.spi.WarningCollector)1