Search in sources :

Example 16 with OrderingScheme

use of io.trino.sql.planner.OrderingScheme in project trino by trinodb.

the class TestPushdownFilterIntoWindow method assertNoUpperBound.

private void assertNoUpperBound(String rankingFunctionName) {
    ResolvedFunction ranking = tester().getMetadata().resolveFunction(tester().getSession(), QualifiedName.of(rankingFunctionName), fromTypes());
    tester().assertThat(new PushdownFilterIntoWindow(tester().getPlannerContext())).on(p -> {
        Symbol rowNumberSymbol = p.symbol("row_number_1");
        Symbol a = p.symbol("a");
        OrderingScheme orderingScheme = new OrderingScheme(ImmutableList.of(a), ImmutableMap.of(a, SortOrder.ASC_NULLS_FIRST));
        return p.filter(expression("cast(3 as bigint) < row_number_1"), p.window(new WindowNode.Specification(ImmutableList.of(a), Optional.of(orderingScheme)), ImmutableMap.of(rowNumberSymbol, newWindowNodeFunction(ranking, a)), p.values(a)));
    }).doesNotFire();
}
Also used : Symbol(io.trino.sql.planner.Symbol) ImmutableMap(com.google.common.collect.ImmutableMap) BaseRuleTest(io.trino.sql.planner.iterative.rule.test.BaseRuleTest) PlanMatchPattern.topNRanking(io.trino.sql.planner.assertions.PlanMatchPattern.topNRanking) ResolvedFunction(io.trino.metadata.ResolvedFunction) TopNRankingSymbolMatcher(io.trino.sql.planner.assertions.TopNRankingSymbolMatcher) TypeSignatureProvider.fromTypes(io.trino.sql.analyzer.TypeSignatureProvider.fromTypes) Test(org.testng.annotations.Test) PlanMatchPattern.filter(io.trino.sql.planner.assertions.PlanMatchPattern.filter) PlanMatchPattern.values(io.trino.sql.planner.assertions.PlanMatchPattern.values) OrderingScheme(io.trino.sql.planner.OrderingScheme) DEFAULT_FRAME(io.trino.sql.planner.plan.WindowNode.Frame.DEFAULT_FRAME) SortOrder(io.trino.spi.connector.SortOrder) QualifiedName(io.trino.sql.tree.QualifiedName) ImmutableList(com.google.common.collect.ImmutableList) BIGINT(io.trino.spi.type.BigintType.BIGINT) Optional(java.util.Optional) WindowNode(io.trino.sql.planner.plan.WindowNode) PlanBuilder.expression(io.trino.sql.planner.iterative.rule.test.PlanBuilder.expression) OrderingScheme(io.trino.sql.planner.OrderingScheme) WindowNode(io.trino.sql.planner.plan.WindowNode) ResolvedFunction(io.trino.metadata.ResolvedFunction) Symbol(io.trino.sql.planner.Symbol)

Example 17 with OrderingScheme

use of io.trino.sql.planner.OrderingScheme in project trino by trinodb.

the class TestPushdownFilterIntoWindow method assertEliminateFilter.

private void assertEliminateFilter(String rankingFunctionName) {
    ResolvedFunction ranking = tester().getMetadata().resolveFunction(tester().getSession(), QualifiedName.of(rankingFunctionName), fromTypes());
    tester().assertThat(new PushdownFilterIntoWindow(tester().getPlannerContext())).on(p -> {
        Symbol rankSymbol = p.symbol("rank_1");
        Symbol a = p.symbol("a", BIGINT);
        OrderingScheme orderingScheme = new OrderingScheme(ImmutableList.of(a), ImmutableMap.of(a, SortOrder.ASC_NULLS_FIRST));
        return p.filter(expression("rank_1 < cast(100 as bigint)"), p.window(new WindowNode.Specification(ImmutableList.of(a), Optional.of(orderingScheme)), ImmutableMap.of(rankSymbol, newWindowNodeFunction(ranking, a)), p.values(p.symbol("a"))));
    }).matches(topNRanking(pattern -> pattern.maxRankingPerPartition(99).partial(false), values("a")));
}
Also used : Symbol(io.trino.sql.planner.Symbol) ImmutableMap(com.google.common.collect.ImmutableMap) BaseRuleTest(io.trino.sql.planner.iterative.rule.test.BaseRuleTest) PlanMatchPattern.topNRanking(io.trino.sql.planner.assertions.PlanMatchPattern.topNRanking) ResolvedFunction(io.trino.metadata.ResolvedFunction) TopNRankingSymbolMatcher(io.trino.sql.planner.assertions.TopNRankingSymbolMatcher) TypeSignatureProvider.fromTypes(io.trino.sql.analyzer.TypeSignatureProvider.fromTypes) Test(org.testng.annotations.Test) PlanMatchPattern.filter(io.trino.sql.planner.assertions.PlanMatchPattern.filter) PlanMatchPattern.values(io.trino.sql.planner.assertions.PlanMatchPattern.values) OrderingScheme(io.trino.sql.planner.OrderingScheme) DEFAULT_FRAME(io.trino.sql.planner.plan.WindowNode.Frame.DEFAULT_FRAME) SortOrder(io.trino.spi.connector.SortOrder) QualifiedName(io.trino.sql.tree.QualifiedName) ImmutableList(com.google.common.collect.ImmutableList) BIGINT(io.trino.spi.type.BigintType.BIGINT) Optional(java.util.Optional) WindowNode(io.trino.sql.planner.plan.WindowNode) PlanBuilder.expression(io.trino.sql.planner.iterative.rule.test.PlanBuilder.expression) OrderingScheme(io.trino.sql.planner.OrderingScheme) WindowNode(io.trino.sql.planner.plan.WindowNode) ResolvedFunction(io.trino.metadata.ResolvedFunction) Symbol(io.trino.sql.planner.Symbol)

Example 18 with OrderingScheme

use of io.trino.sql.planner.OrderingScheme in project trino by trinodb.

the class TestPushdownLimitIntoWindow method assertZeroLimit.

private void assertZeroLimit(String rankingFunctionName) {
    ResolvedFunction ranking = tester().getMetadata().resolveFunction(tester().getSession(), QualifiedName.of(rankingFunctionName), fromTypes());
    tester().assertThat(new PushdownLimitIntoWindow()).on(p -> {
        Symbol a = p.symbol("a");
        Symbol rowNumberSymbol = p.symbol("row_number_1");
        OrderingScheme orderingScheme = new OrderingScheme(ImmutableList.of(a), ImmutableMap.of(a, SortOrder.ASC_NULLS_FIRST));
        return p.limit(0, p.window(new WindowNode.Specification(ImmutableList.of(a), Optional.of(orderingScheme)), ImmutableMap.of(rowNumberSymbol, newWindowNodeFunction(ranking, a)), p.values(a)));
    }).doesNotFire();
}
Also used : Symbol(io.trino.sql.planner.Symbol) ImmutableMap(com.google.common.collect.ImmutableMap) BaseRuleTest(io.trino.sql.planner.iterative.rule.test.BaseRuleTest) PlanMatchPattern.topNRanking(io.trino.sql.planner.assertions.PlanMatchPattern.topNRanking) ResolvedFunction(io.trino.metadata.ResolvedFunction) TypeSignatureProvider.fromTypes(io.trino.sql.analyzer.TypeSignatureProvider.fromTypes) Test(org.testng.annotations.Test) PlanMatchPattern.values(io.trino.sql.planner.assertions.PlanMatchPattern.values) OrderingScheme(io.trino.sql.planner.OrderingScheme) DEFAULT_FRAME(io.trino.sql.planner.plan.WindowNode.Frame.DEFAULT_FRAME) SortOrder(io.trino.spi.connector.SortOrder) QualifiedName(io.trino.sql.tree.QualifiedName) PlanMatchPattern.limit(io.trino.sql.planner.assertions.PlanMatchPattern.limit) ImmutableList(com.google.common.collect.ImmutableList) Optional(java.util.Optional) WindowNode(io.trino.sql.planner.plan.WindowNode) OrderingScheme(io.trino.sql.planner.OrderingScheme) WindowNode(io.trino.sql.planner.plan.WindowNode) ResolvedFunction(io.trino.metadata.ResolvedFunction) Symbol(io.trino.sql.planner.Symbol)

Aggregations

OrderingScheme (io.trino.sql.planner.OrderingScheme)18 ImmutableList (com.google.common.collect.ImmutableList)15 Symbol (io.trino.sql.planner.Symbol)15 WindowNode (io.trino.sql.planner.plan.WindowNode)13 ImmutableMap (com.google.common.collect.ImmutableMap)11 ResolvedFunction (io.trino.metadata.ResolvedFunction)10 QualifiedName (io.trino.sql.tree.QualifiedName)10 Optional (java.util.Optional)10 Test (org.testng.annotations.Test)10 SortOrder (io.trino.spi.connector.SortOrder)9 TypeSignatureProvider.fromTypes (io.trino.sql.analyzer.TypeSignatureProvider.fromTypes)9 PlanMatchPattern.values (io.trino.sql.planner.assertions.PlanMatchPattern.values)9 BaseRuleTest (io.trino.sql.planner.iterative.rule.test.BaseRuleTest)9 DEFAULT_FRAME (io.trino.sql.planner.plan.WindowNode.Frame.DEFAULT_FRAME)9 PlanMatchPattern.topNRanking (io.trino.sql.planner.assertions.PlanMatchPattern.topNRanking)7 ImmutableMap.toImmutableMap (com.google.common.collect.ImmutableMap.toImmutableMap)5 Assignments (io.trino.sql.planner.plan.Assignments)5 SymbolReference (io.trino.sql.tree.SymbolReference)5 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)4 BIGINT (io.trino.spi.type.BigintType.BIGINT)4