use of io.trino.metadata.ResolvedFunction in project trino by trinodb.
the class TestReplaceWindowWithRowNumber method testDoNotFire.
@Test
public void testDoNotFire() {
ResolvedFunction rank = tester().getMetadata().resolveFunction(tester().getSession(), QualifiedName.of("rank"), fromTypes());
tester().assertThat(new ReplaceWindowWithRowNumber(tester().getMetadata())).on(p -> {
Symbol a = p.symbol("a");
Symbol rank1 = p.symbol("rank_1");
return p.window(new WindowNode.Specification(ImmutableList.of(a), Optional.empty()), ImmutableMap.of(rank1, newWindowNodeFunction(rank)), p.values(a));
}).doesNotFire();
ResolvedFunction rowNumber = tester().getMetadata().resolveFunction(tester().getSession(), QualifiedName.of("row_number"), fromTypes());
tester().assertThat(new ReplaceWindowWithRowNumber(tester().getMetadata())).on(p -> {
Symbol a = p.symbol("a");
Symbol rowNumber1 = p.symbol("row_number_1");
Symbol rank1 = p.symbol("rank_1");
return p.window(new WindowNode.Specification(ImmutableList.of(a), Optional.empty()), ImmutableMap.of(rowNumber1, newWindowNodeFunction(rowNumber), rank1, newWindowNodeFunction(rank)), p.values(a));
}).doesNotFire();
tester().assertThat(new ReplaceWindowWithRowNumber(tester().getMetadata())).on(p -> {
Symbol a = p.symbol("a");
OrderingScheme orderingScheme = new OrderingScheme(ImmutableList.of(a), ImmutableMap.of(a, SortOrder.ASC_NULLS_FIRST));
Symbol rowNumber1 = p.symbol("row_number_1");
return p.window(new WindowNode.Specification(ImmutableList.of(a), Optional.of(orderingScheme)), ImmutableMap.of(rowNumber1, newWindowNodeFunction(rowNumber)), p.values(a));
}).doesNotFire();
}
use of io.trino.metadata.ResolvedFunction in project trino by trinodb.
the class TestSwapAdjacentWindowsBySpecifications method subsetComesFirst.
@Test
public void subsetComesFirst() {
String columnAAlias = "ALIAS_A";
String columnBAlias = "ALIAS_B";
ExpectedValueProvider<WindowNode.Specification> specificationA = specification(ImmutableList.of(columnAAlias), ImmutableList.of(), ImmutableMap.of());
ExpectedValueProvider<WindowNode.Specification> specificationAB = specification(ImmutableList.of(columnAAlias, columnBAlias), ImmutableList.of(), ImmutableMap.of());
tester().assertThat(new GatherAndMergeWindows.SwapAdjacentWindowsBySpecifications(0)).on(p -> p.window(new WindowNode.Specification(ImmutableList.of(p.symbol("a")), Optional.empty()), ImmutableMap.of(p.symbol("avg_1", DOUBLE), new WindowNode.Function(resolvedFunction, ImmutableList.of(new SymbolReference("a")), DEFAULT_FRAME, false)), p.window(new WindowNode.Specification(ImmutableList.of(p.symbol("a"), p.symbol("b")), Optional.empty()), ImmutableMap.of(p.symbol("avg_2", DOUBLE), new WindowNode.Function(resolvedFunction, ImmutableList.of(new SymbolReference("b")), DEFAULT_FRAME, false)), p.values(p.symbol("a"), p.symbol("b"))))).matches(window(windowMatcherBuilder -> windowMatcherBuilder.specification(specificationAB).addFunction(functionCall("avg", Optional.empty(), ImmutableList.of(columnBAlias))), window(windowMatcherBuilder -> windowMatcherBuilder.specification(specificationA).addFunction(functionCall("avg", Optional.empty(), ImmutableList.of(columnAAlias))), values(ImmutableMap.of(columnAAlias, 0, columnBAlias, 1)))));
}
use of io.trino.metadata.ResolvedFunction 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.metadata.ResolvedFunction 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.metadata.ResolvedFunction 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();
}
Aggregations