Search in sources :

Example 1 with ROW_NUMBER

use of io.trino.sql.planner.plan.TopNRankingNode.RankingType.ROW_NUMBER in project trino by trinodb.

the class TestWindowFilterPushDown method testFilterAboveRowNumber.

@Test
public void testFilterAboveRowNumber() {
    // remove subplan if predicate on row number symbol can't be satisfied
    assertPlan("SELECT * FROM (SELECT name, row_number() OVER() FROM nation) t(name, row_number) WHERE row_number < 0", output(ImmutableList.of("name", "row_number"), values("name", "row_number")));
    // include limit into RowNUmberNode on the basis of predicate; remove filter because predicate is satisfied
    assertPlan("SELECT * FROM (SELECT name, row_number() OVER() FROM nation) t(name, row_number) WHERE row_number < 2", output(ImmutableList.of("name", "row_number"), rowNumber(pattern -> pattern.maxRowCountPerPartition(Optional.of(1)), any(tableScan("nation", ImmutableMap.of("name", "name")))).withAlias("row_number", new RowNumberSymbolMatcher())));
    // include limit into RowNUmberNode on the basis of predicate; remove filter because predicate is satisfied
    assertPlan("SELECT * FROM (SELECT name, row_number() OVER() FROM nation) t(name, row_number) WHERE row_number <= 1", output(ImmutableList.of("name", "row_number"), rowNumber(pattern -> pattern.maxRowCountPerPartition(Optional.of(1)), any(tableScan("nation", ImmutableMap.of("name", "name")))).withAlias("row_number", new RowNumberSymbolMatcher())));
    // include limit into RowNUmberNode on the basis of predicate; remove filter because predicate is satisfied
    assertPlan("SELECT * FROM (SELECT name, row_number() OVER() FROM nation) t(name, row_number) WHERE row_number <= 1 AND row_number > -10", output(ImmutableList.of("name", "row_number"), rowNumber(pattern -> pattern.maxRowCountPerPartition(Optional.of(1)), any(tableScan("nation", ImmutableMap.of("name", "name")))).withAlias("row_number", new RowNumberSymbolMatcher())));
    // include limit into RowNUmberNode on the basis of predicate; cannot remove filter because predicate is not satisfied
    assertPlan("SELECT * FROM (SELECT name, row_number() OVER() FROM nation) t(name, row_number) WHERE row_number > 1 AND row_number < 3", output(ImmutableList.of("name", "row_number"), filter("(row_number > BIGINT '1') AND (row_number < BIGINT '3')", rowNumber(pattern -> pattern.maxRowCountPerPartition(Optional.of(2)), any(tableScan("nation", ImmutableMap.of("name", "name")))).withAlias("row_number", new RowNumberSymbolMatcher()))));
}
Also used : ROW_NUMBER(io.trino.sql.planner.plan.TopNRankingNode.RankingType.ROW_NUMBER) PlanMatchPattern.any(io.trino.sql.planner.assertions.PlanMatchPattern.any) TopNRankingSymbolMatcher(io.trino.sql.planner.assertions.TopNRankingSymbolMatcher) Test(org.testng.annotations.Test) PlanMatchPattern.filter(io.trino.sql.planner.assertions.PlanMatchPattern.filter) FilterNode(io.trino.sql.planner.plan.FilterNode) PlanMatchPattern.limit(io.trino.sql.planner.assertions.PlanMatchPattern.limit) ImmutableList(com.google.common.collect.ImmutableList) BasePlanTest(io.trino.sql.planner.assertions.BasePlanTest) RowNumberSymbolMatcher(io.trino.sql.planner.assertions.RowNumberSymbolMatcher) ImmutableMap(com.google.common.collect.ImmutableMap) Language(org.intellij.lang.annotations.Language) PlanMatchPattern.topNRanking(io.trino.sql.planner.assertions.PlanMatchPattern.topNRanking) RANK(io.trino.sql.planner.plan.TopNRankingNode.RankingType.RANK) PlanMatchPattern.values(io.trino.sql.planner.assertions.PlanMatchPattern.values) String.format(java.lang.String.format) OPTIMIZE_TOP_N_RANKING(io.trino.SystemSessionProperties.OPTIMIZE_TOP_N_RANKING) PlanMatchPattern.node(io.trino.sql.planner.assertions.PlanMatchPattern.node) ASC_NULLS_LAST(io.trino.spi.connector.SortOrder.ASC_NULLS_LAST) PlanMatchPattern.anyTree(io.trino.sql.planner.assertions.PlanMatchPattern.anyTree) PlanMatchPattern.project(io.trino.sql.planner.assertions.PlanMatchPattern.project) RankingType(io.trino.sql.planner.plan.TopNRankingNode.RankingType) Optional(java.util.Optional) WindowNode(io.trino.sql.planner.plan.WindowNode) PlanMatchPattern.output(io.trino.sql.planner.assertions.PlanMatchPattern.output) PlanMatchPattern.rowNumber(io.trino.sql.planner.assertions.PlanMatchPattern.rowNumber) PlanMatchPattern.tableScan(io.trino.sql.planner.assertions.PlanMatchPattern.tableScan) Session(io.trino.Session) PlanMatchPattern.anyNot(io.trino.sql.planner.assertions.PlanMatchPattern.anyNot) RowNumberSymbolMatcher(io.trino.sql.planner.assertions.RowNumberSymbolMatcher) Test(org.testng.annotations.Test) BasePlanTest(io.trino.sql.planner.assertions.BasePlanTest)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Session (io.trino.Session)1 OPTIMIZE_TOP_N_RANKING (io.trino.SystemSessionProperties.OPTIMIZE_TOP_N_RANKING)1 ASC_NULLS_LAST (io.trino.spi.connector.SortOrder.ASC_NULLS_LAST)1 BasePlanTest (io.trino.sql.planner.assertions.BasePlanTest)1 PlanMatchPattern.any (io.trino.sql.planner.assertions.PlanMatchPattern.any)1 PlanMatchPattern.anyNot (io.trino.sql.planner.assertions.PlanMatchPattern.anyNot)1 PlanMatchPattern.anyTree (io.trino.sql.planner.assertions.PlanMatchPattern.anyTree)1 PlanMatchPattern.filter (io.trino.sql.planner.assertions.PlanMatchPattern.filter)1 PlanMatchPattern.limit (io.trino.sql.planner.assertions.PlanMatchPattern.limit)1 PlanMatchPattern.node (io.trino.sql.planner.assertions.PlanMatchPattern.node)1 PlanMatchPattern.output (io.trino.sql.planner.assertions.PlanMatchPattern.output)1 PlanMatchPattern.project (io.trino.sql.planner.assertions.PlanMatchPattern.project)1 PlanMatchPattern.rowNumber (io.trino.sql.planner.assertions.PlanMatchPattern.rowNumber)1 PlanMatchPattern.tableScan (io.trino.sql.planner.assertions.PlanMatchPattern.tableScan)1 PlanMatchPattern.topNRanking (io.trino.sql.planner.assertions.PlanMatchPattern.topNRanking)1 PlanMatchPattern.values (io.trino.sql.planner.assertions.PlanMatchPattern.values)1 RowNumberSymbolMatcher (io.trino.sql.planner.assertions.RowNumberSymbolMatcher)1 TopNRankingSymbolMatcher (io.trino.sql.planner.assertions.TopNRankingSymbolMatcher)1