use of io.trino.sql.planner.Symbol in project trino by trinodb.
the class TestPushdownLimitIntoWindow method testConvertToTopNRowNumber.
@Test
public void testConvertToTopNRowNumber() {
ResolvedFunction ranking = tester().getMetadata().resolveFunction(tester().getSession(), QualifiedName.of("row_number"), 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(3, p.window(new WindowNode.Specification(ImmutableList.of(), Optional.of(orderingScheme)), ImmutableMap.of(rowNumberSymbol, newWindowNodeFunction(ranking, a)), p.values(a)));
}).matches(topNRanking(pattern -> pattern.specification(ImmutableList.of(), ImmutableList.of("a"), ImmutableMap.of("a", SortOrder.ASC_NULLS_FIRST)).maxRankingPerPartition(3).partial(false), values("a")));
}
use of io.trino.sql.planner.Symbol in project trino by trinodb.
the class TestPushdownLimitIntoWindow method assertLimitAboveWindow.
private void assertLimitAboveWindow(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(3, p.window(new WindowNode.Specification(ImmutableList.of(a), Optional.of(orderingScheme)), ImmutableMap.of(rowNumberSymbol, newWindowNodeFunction(ranking, a)), p.values(a)));
}).matches(limit(3, topNRanking(pattern -> pattern.specification(ImmutableList.of("a"), ImmutableList.of("a"), ImmutableMap.of("a", SortOrder.ASC_NULLS_FIRST)).maxRankingPerPartition(3).partial(false), values("a"))));
}
use of io.trino.sql.planner.Symbol in project trino by trinodb.
the class TestPushdownLimitIntoWindow method testLimitWithPreSortedInputs.
@Test
public void testLimitWithPreSortedInputs() {
// We can push Limit with pre-sorted inputs into WindowNode if ordering scheme is satisfied
// We don't do it currently to avoid relying on LocalProperties outside of AddExchanges/AddLocalExchanges
ResolvedFunction ranking = tester().getMetadata().resolveFunction(tester().getSession(), QualifiedName.of("row_number"), 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(3, false, ImmutableList.of(a), p.window(new WindowNode.Specification(ImmutableList.of(), Optional.of(orderingScheme)), ImmutableMap.of(rowNumberSymbol, newWindowNodeFunction(ranking, a)), p.values(a)));
}).doesNotFire();
}
use of io.trino.sql.planner.Symbol in project trino by trinodb.
the class TestPushdownLimitIntoWindow method assertWindowNotOrdered.
private void assertWindowNotOrdered(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");
return p.limit(3, p.window(new WindowNode.Specification(ImmutableList.of(a), Optional.empty()), ImmutableMap.of(rowNumberSymbol, newWindowNodeFunction(ranking, a)), p.values(a)));
}).doesNotFire();
}
use of io.trino.sql.planner.Symbol in project trino by trinodb.
the class TestRemoveAggregationInSemiJoin method semiJoinWithDistinctAsFilteringSource.
private static PlanNode semiJoinWithDistinctAsFilteringSource(PlanBuilder p) {
Symbol leftKey = p.symbol("leftKey");
Symbol rightKey = p.symbol("rightKey");
return p.semiJoin(leftKey, rightKey, p.symbol("match"), Optional.empty(), Optional.empty(), p.values(leftKey), p.aggregation(builder -> builder.singleGroupingSet(rightKey).source(p.values(rightKey))));
}
Aggregations