Search in sources :

Example 1 with REPARTITION

use of io.prestosql.sql.planner.plan.ExchangeNode.Type.REPARTITION 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 REPARTITION

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

the class TestValidateAggregationsWithDefaultValues method testWithPartialAggregationBelowJoin.

@Test
public void testWithPartialAggregationBelowJoin() {
    Symbol symbolObj = new Symbol("symbol");
    PlanNode root = builder.aggregation(af -> af.step(FINAL).groupingSets(groupingSets(ImmutableList.of(symbolObj), 2, ImmutableSet.of(0))).source(builder.join(INNER, builder.exchange(e -> e.type(REPARTITION).scope(LOCAL).fixedHashDistributionParitioningScheme(ImmutableList.of(symbolObj), ImmutableList.of(symbolObj)).addInputsSet(symbolObj).addSource(builder.aggregation(ap -> ap.step(PARTIAL).groupingSets(groupingSets(ImmutableList.of(symbolObj), 2, ImmutableSet.of(0))).source(tableScanNode)))), builder.values())));
    validatePlan(root, true);
}
Also used : TpchTableHandle(io.prestosql.plugin.tpch.TpchTableHandle) TpchColumnHandle(io.prestosql.plugin.tpch.TpchColumnHandle) TypeProvider(io.prestosql.sql.planner.TypeProvider) Test(org.testng.annotations.Test) SqlParser(io.prestosql.sql.parser.SqlParser) TableHandle(io.prestosql.spi.metadata.TableHandle) PARTIAL(io.prestosql.spi.plan.AggregationNode.Step.PARTIAL) TypeAnalyzer(io.prestosql.sql.planner.TypeAnalyzer) REMOTE(io.prestosql.sql.planner.plan.ExchangeNode.Scope.REMOTE) WarningCollector(io.prestosql.execution.warnings.WarningCollector) ImmutableList(com.google.common.collect.ImmutableList) REPARTITION(io.prestosql.sql.planner.plan.ExchangeNode.Type.REPARTITION) BIGINT(io.prestosql.spi.type.BigintType.BIGINT) Symbol(io.prestosql.spi.plan.Symbol) BasePlanTest(io.prestosql.sql.planner.assertions.BasePlanTest) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) BeforeClass(org.testng.annotations.BeforeClass) CatalogName(io.prestosql.spi.connector.CatalogName) TableScanNode(io.prestosql.spi.plan.TableScanNode) PlanNode(io.prestosql.spi.plan.PlanNode) FINAL(io.prestosql.spi.plan.AggregationNode.Step.FINAL) Metadata(io.prestosql.metadata.Metadata) AggregationNode.groupingSets(io.prestosql.spi.plan.AggregationNode.groupingSets) TestingTransactionHandle(io.prestosql.testing.TestingTransactionHandle) LOCAL(io.prestosql.sql.planner.plan.ExchangeNode.Scope.LOCAL) PlanNodeIdAllocator(io.prestosql.spi.plan.PlanNodeIdAllocator) INNER(io.prestosql.spi.plan.JoinNode.Type.INNER) Optional(java.util.Optional) PlanBuilder(io.prestosql.sql.planner.iterative.rule.test.PlanBuilder) PlanNode(io.prestosql.spi.plan.PlanNode) Symbol(io.prestosql.spi.plan.Symbol) Test(org.testng.annotations.Test) BasePlanTest(io.prestosql.sql.planner.assertions.BasePlanTest)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 FINAL (io.prestosql.spi.plan.AggregationNode.Step.FINAL)2 INNER (io.prestosql.spi.plan.JoinNode.Type.INNER)2 BasePlanTest (io.prestosql.sql.planner.assertions.BasePlanTest)2 LOCAL (io.prestosql.sql.planner.plan.ExchangeNode.Scope.LOCAL)2 REMOTE (io.prestosql.sql.planner.plan.ExchangeNode.Scope.REMOTE)2 REPARTITION (io.prestosql.sql.planner.plan.ExchangeNode.Type.REPARTITION)2 Optional (java.util.Optional)2 Test (org.testng.annotations.Test)2 ImmutableSet (com.google.common.collect.ImmutableSet)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 WarningCollector (io.prestosql.execution.warnings.WarningCollector)1 Metadata (io.prestosql.metadata.Metadata)1 RankingFunction (io.prestosql.operator.window.RankingFunction)1 TpchColumnHandle (io.prestosql.plugin.tpch.TpchColumnHandle)1 TpchTableHandle (io.prestosql.plugin.tpch.TpchTableHandle)1