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")))))));
}
}
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")))))));
}
}
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")))))))));
}
}
Aggregations