Search in sources :

Example 1 with GATHER

use of io.prestosql.sql.planner.plan.ExchangeNode.Type.GATHER in project hetu-core by openlookeng.

the class TestWindow method testWindow.

@Test
public void testWindow() {
    // Window partition key is pre-bucketed.
    assertDistributedPlan("SELECT rank() OVER (PARTITION BY orderkey) FROM orders", anyTree(window(pattern -> pattern.specification(specification(ImmutableList.of("orderkey"), ImmutableList.of(), ImmutableMap.of())).addFunction(functionCall("rank", Optional.empty(), ImmutableList.of())), project(tableScan("orders", ImmutableMap.of("orderkey", "orderkey"))))));
    assertDistributedPlan("SELECT row_number() OVER (PARTITION BY orderkey) FROM orders", anyTree(rowNumber(pattern -> pattern.partitionBy(ImmutableList.of("orderkey")), project(tableScan("orders", ImmutableMap.of("orderkey", "orderkey"))))));
    // Window partition key is not pre-bucketed.
    assertDistributedPlan("SELECT rank() OVER (PARTITION BY orderstatus) FROM orders", anyTree(window(pattern -> pattern.specification(specification(ImmutableList.of("orderstatus"), ImmutableList.of(), ImmutableMap.of())).addFunction(functionCall("rank", Optional.empty(), ImmutableList.of())), exchange(LOCAL, GATHER, exchange(REMOTE, REPARTITION, project(tableScan("orders", ImmutableMap.of("orderstatus", "orderstatus"))))))));
    assertDistributedPlan("SELECT row_number() OVER (PARTITION BY orderstatus) FROM orders", anyTree(rowNumber(pattern -> pattern.partitionBy(ImmutableList.of("orderstatus")), exchange(LOCAL, GATHER, exchange(REMOTE, REPARTITION, project(tableScan("orders", ImmutableMap.of("orderstatus", "orderstatus"))))))));
    // Window to TopN RankingFunction
    for (RankingFunction rankingFunction : RankingFunction.values()) {
        assertDistributedPlan(format("SELECT orderkey FROM (SELECT orderkey, %s() OVER (PARTITION BY orderkey ORDER BY custkey) n FROM orders) WHERE n = 1", rankingFunction.getName().getObjectName()), anyTree(topNRankingNumber(pattern -> pattern.specification(ImmutableList.of("orderkey"), ImmutableList.of("custkey"), ImmutableMap.of("custkey", ASC_NULLS_LAST)), project(tableScan("orders", ImmutableMap.of("orderkey", "orderkey", "custkey", "custkey"))))));
        assertDistributedPlan(format("SELECT orderstatus FROM (SELECT orderstatus, %s() OVER (PARTITION BY orderstatus ORDER BY custkey) n FROM orders) WHERE n = 1", rankingFunction.getName().getObjectName()), anyTree(topNRankingNumber(pattern -> pattern.specification(ImmutableList.of("orderstatus"), ImmutableList.of("custkey"), ImmutableMap.of("custkey", ASC_NULLS_LAST)).partial(false), exchange(LOCAL, GATHER, exchange(REMOTE, REPARTITION, topNRankingNumber(topNRowNumber -> topNRowNumber.specification(ImmutableList.of("orderstatus"), ImmutableList.of("custkey"), ImmutableMap.of("custkey", ASC_NULLS_LAST)).partial(true), project(tableScan("orders", ImmutableMap.of("orderstatus", "orderstatus", "custkey", "custkey")))))))));
    }
}
Also used : PlanMatchPattern.project(io.prestosql.sql.planner.assertions.PlanMatchPattern.project) PlanMatchPattern.tableScan(io.prestosql.sql.planner.assertions.PlanMatchPattern.tableScan) REPLICATED(io.prestosql.spi.plan.JoinNode.DistributionType.REPLICATED) PlanMatchPattern.equiJoinClause(io.prestosql.sql.planner.assertions.PlanMatchPattern.equiJoinClause) PlanMatchPattern.specification(io.prestosql.sql.planner.assertions.PlanMatchPattern.specification) JoinDistributionType(io.prestosql.sql.analyzer.FeaturesConfig.JoinDistributionType) Test(org.testng.annotations.Test) PARTITIONED(io.prestosql.spi.plan.JoinNode.DistributionType.PARTITIONED) PlanMatchPattern.singleGroupingSet(io.prestosql.sql.planner.assertions.PlanMatchPattern.singleGroupingSet) JOIN_REORDERING_STRATEGY(io.prestosql.SystemSessionProperties.JOIN_REORDERING_STRATEGY) REMOTE(io.prestosql.sql.planner.plan.ExchangeNode.Scope.REMOTE) GATHER(io.prestosql.sql.planner.plan.ExchangeNode.Type.GATHER) ImmutableList(com.google.common.collect.ImmutableList) PlanMatchPattern.functionCall(io.prestosql.sql.planner.assertions.PlanMatchPattern.functionCall) JoinReorderingStrategy(io.prestosql.sql.analyzer.FeaturesConfig.JoinReorderingStrategy) REPARTITION(io.prestosql.sql.planner.plan.ExchangeNode.Type.REPARTITION) Session(io.prestosql.Session) FORCE_SINGLE_NODE_OUTPUT(io.prestosql.SystemSessionProperties.FORCE_SINGLE_NODE_OUTPUT) PlanMatchPattern.exchange(io.prestosql.sql.planner.assertions.PlanMatchPattern.exchange) REPLICATE(io.prestosql.sql.planner.plan.ExchangeNode.Type.REPLICATE) PlanMatchPattern.window(io.prestosql.sql.planner.assertions.PlanMatchPattern.window) PlanMatchPattern.anyTree(io.prestosql.sql.planner.assertions.PlanMatchPattern.anyTree) ASC_NULLS_LAST(io.prestosql.spi.block.SortOrder.ASC_NULLS_LAST) BasePlanTest(io.prestosql.sql.planner.assertions.BasePlanTest) PlanMatchPattern.join(io.prestosql.sql.planner.assertions.PlanMatchPattern.join) ImmutableMap(com.google.common.collect.ImmutableMap) FINAL(io.prestosql.spi.plan.AggregationNode.Step.FINAL) String.format(java.lang.String.format) PlanMatchPattern.rowNumber(io.prestosql.sql.planner.assertions.PlanMatchPattern.rowNumber) LOCAL(io.prestosql.sql.planner.plan.ExchangeNode.Scope.LOCAL) INNER(io.prestosql.spi.plan.JoinNode.Type.INNER) RankingFunction(io.prestosql.operator.window.RankingFunction) Optional(java.util.Optional) PlanMatchPattern.topNRankingNumber(io.prestosql.sql.planner.assertions.PlanMatchPattern.topNRankingNumber) PlanMatchPattern.aggregation(io.prestosql.sql.planner.assertions.PlanMatchPattern.aggregation) JOIN_DISTRIBUTION_TYPE(io.prestosql.SystemSessionProperties.JOIN_DISTRIBUTION_TYPE) RankingFunction(io.prestosql.operator.window.RankingFunction) Test(org.testng.annotations.Test) BasePlanTest(io.prestosql.sql.planner.assertions.BasePlanTest)

Example 2 with GATHER

use of io.prestosql.sql.planner.plan.ExchangeNode.Type.GATHER in project hetu-core by openlookeng.

the class TestUnion method testUnionUnderTopN.

@Test
public void testUnionUnderTopN() {
    Plan plan = plan("SELECT * FROM (" + "   SELECT regionkey FROM nation " + "   UNION ALL " + "   SELECT nationkey FROM nation" + ") t(a) " + "ORDER BY a LIMIT 1", LogicalPlanner.Stage.OPTIMIZED_AND_VALIDATED, false);
    List<PlanNode> remotes = searchFrom(plan.getRoot()).where(TestUnion::isRemoteExchange).findAll();
    assertEquals(remotes.size(), 1, "There should be exactly one RemoteExchange");
    assertEquals(((ExchangeNode) Iterables.getOnlyElement(remotes)).getType(), GATHER);
    int numberOfpartialTopN = searchFrom(plan.getRoot()).where(planNode -> planNode instanceof TopNNode && ((TopNNode) planNode).getStep().equals(TopNNode.Step.PARTIAL)).count();
    assertEquals(numberOfpartialTopN, 2, "There should be exactly two partial TopN nodes");
    assertPlanIsFullyDistributed(plan);
}
Also used : BasePlanTest(io.prestosql.sql.planner.assertions.BasePlanTest) Iterables(com.google.common.collect.Iterables) Assert.assertEquals(org.testng.Assert.assertEquals) Plan(io.prestosql.sql.planner.Plan) Test(org.testng.annotations.Test) PlanNode(io.prestosql.spi.plan.PlanNode) LogicalPlanner(io.prestosql.sql.planner.LogicalPlanner) AggregationNode(io.prestosql.spi.plan.AggregationNode) PlanNodeSearcher.searchFrom(io.prestosql.sql.planner.optimizations.PlanNodeSearcher.searchFrom) REMOTE(io.prestosql.sql.planner.plan.ExchangeNode.Scope.REMOTE) ExchangeNode(io.prestosql.sql.planner.plan.ExchangeNode) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) GATHER(io.prestosql.sql.planner.plan.ExchangeNode.Type.GATHER) TopNNode(io.prestosql.spi.plan.TopNNode) Map(java.util.Map) REPARTITION(io.prestosql.sql.planner.plan.ExchangeNode.Type.REPARTITION) Assert.assertTrue(org.testng.Assert.assertTrue) Assert.assertFalse(org.testng.Assert.assertFalse) JoinNode(io.prestosql.spi.plan.JoinNode) PlanNode(io.prestosql.spi.plan.PlanNode) Plan(io.prestosql.sql.planner.Plan) TopNNode(io.prestosql.spi.plan.TopNNode) BasePlanTest(io.prestosql.sql.planner.assertions.BasePlanTest) Test(org.testng.annotations.Test)

Aggregations

BasePlanTest (io.prestosql.sql.planner.assertions.BasePlanTest)2 REMOTE (io.prestosql.sql.planner.plan.ExchangeNode.Scope.REMOTE)2 GATHER (io.prestosql.sql.planner.plan.ExchangeNode.Type.GATHER)2 REPARTITION (io.prestosql.sql.planner.plan.ExchangeNode.Type.REPARTITION)2 Test (org.testng.annotations.Test)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Iterables (com.google.common.collect.Iterables)1 Session (io.prestosql.Session)1 FORCE_SINGLE_NODE_OUTPUT (io.prestosql.SystemSessionProperties.FORCE_SINGLE_NODE_OUTPUT)1 JOIN_DISTRIBUTION_TYPE (io.prestosql.SystemSessionProperties.JOIN_DISTRIBUTION_TYPE)1 JOIN_REORDERING_STRATEGY (io.prestosql.SystemSessionProperties.JOIN_REORDERING_STRATEGY)1 RankingFunction (io.prestosql.operator.window.RankingFunction)1 ASC_NULLS_LAST (io.prestosql.spi.block.SortOrder.ASC_NULLS_LAST)1 AggregationNode (io.prestosql.spi.plan.AggregationNode)1 FINAL (io.prestosql.spi.plan.AggregationNode.Step.FINAL)1 JoinNode (io.prestosql.spi.plan.JoinNode)1 PARTITIONED (io.prestosql.spi.plan.JoinNode.DistributionType.PARTITIONED)1 REPLICATED (io.prestosql.spi.plan.JoinNode.DistributionType.REPLICATED)1 INNER (io.prestosql.spi.plan.JoinNode.Type.INNER)1