Search in sources :

Example 1 with RankingFunction

use of io.prestosql.operator.window.RankingFunction in project hetu-core by openlookeng.

the class TestWindowFilterPushDown method testFilterAboveWindow.

@Test
public void testFilterAboveWindow() {
    String sqlFormat = "SELECT * FROM " + "(SELECT %s() OVER (PARTITION BY suppkey ORDER BY orderkey) partition_row_number FROM lineitem) " + "WHERE partition_row_number < 10";
    for (RankingFunction rankingFunction : RankingFunction.values()) {
        @Language("SQL") String sql = format(sqlFormat, rankingFunction.getName().getObjectName());
        assertPlanWithSession(sql, optimizeTopNRankingNumber(true), true, anyTree(anyNot(FilterNode.class, node(TopNRankingNumberNode.class, anyTree(tableScan("lineitem"))))));
        assertPlanWithSession(sql, optimizeTopNRankingNumber(false), true, anyTree(node(FilterNode.class, anyTree(node(WindowNode.class, anyTree(tableScan("lineitem")))))));
    }
}
Also used : TopNRankingNumberNode(io.prestosql.sql.planner.plan.TopNRankingNumberNode) RankingFunction(io.prestosql.operator.window.RankingFunction) Language(org.intellij.lang.annotations.Language) BasePlanTest(io.prestosql.sql.planner.assertions.BasePlanTest) Test(org.testng.annotations.Test)

Example 2 with RankingFunction

use of io.prestosql.operator.window.RankingFunction in project hetu-core by openlookeng.

the class TestWindowFilterPushDown method testLimitAboveWindow.

@Test
public void testLimitAboveWindow() {
    String sqlFormat = "SELECT " + "%s() OVER (PARTITION BY suppkey ORDER BY orderkey) partition_number FROM lineitem LIMIT 10";
    for (RankingFunction rankingFunction : RankingFunction.values()) {
        @Language("SQL") String sql = format(sqlFormat, rankingFunction.getName().getObjectName());
        assertPlanWithSession(sql, optimizeTopNRankingNumber(true), true, anyTree(limit(10, anyTree(node(TopNRankingNumberNode.class, anyTree(tableScan("lineitem")))))));
        assertPlanWithSession(sql, optimizeTopNRankingNumber(false), true, anyTree(limit(10, anyTree(node(WindowNode.class, anyTree(tableScan("lineitem")))))));
    }
}
Also used : RankingFunction(io.prestosql.operator.window.RankingFunction) Language(org.intellij.lang.annotations.Language) BasePlanTest(io.prestosql.sql.planner.assertions.BasePlanTest) Test(org.testng.annotations.Test)

Example 3 with RankingFunction

use of io.prestosql.operator.window.RankingFunction 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)

Aggregations

RankingFunction (io.prestosql.operator.window.RankingFunction)3 BasePlanTest (io.prestosql.sql.planner.assertions.BasePlanTest)3 Test (org.testng.annotations.Test)3 Language (org.intellij.lang.annotations.Language)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)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 ASC_NULLS_LAST (io.prestosql.spi.block.SortOrder.ASC_NULLS_LAST)1 FINAL (io.prestosql.spi.plan.AggregationNode.Step.FINAL)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 JoinDistributionType (io.prestosql.sql.analyzer.FeaturesConfig.JoinDistributionType)1 JoinReorderingStrategy (io.prestosql.sql.analyzer.FeaturesConfig.JoinReorderingStrategy)1 PlanMatchPattern.aggregation (io.prestosql.sql.planner.assertions.PlanMatchPattern.aggregation)1 PlanMatchPattern.anyTree (io.prestosql.sql.planner.assertions.PlanMatchPattern.anyTree)1 PlanMatchPattern.equiJoinClause (io.prestosql.sql.planner.assertions.PlanMatchPattern.equiJoinClause)1