use of io.trino.spi.type.BigintType.BIGINT in project trino by trinodb.
the class TestPushAggregationThroughOuterJoin method testDoesNotFireWhenNotDistinct.
@Test
public void testDoesNotFireWhenNotDistinct() {
tester().assertThat(new PushAggregationThroughOuterJoin()).on(p -> p.aggregation(ab -> ab.source(p.join(LEFT, p.values(ImmutableList.of(p.symbol("COL1")), ImmutableList.of(expressions("10"), expressions("11"))), p.values(new Symbol("COL2")), ImmutableList.of(new EquiJoinClause(new Symbol("COL1"), new Symbol("COL2"))), ImmutableList.of(p.symbol("COL1")), ImmutableList.of(p.symbol("COL2")), Optional.empty(), Optional.empty(), Optional.empty())).addAggregation(new Symbol("AVG"), PlanBuilder.expression("avg(COL2)"), ImmutableList.of(DOUBLE)).singleGroupingSet(new Symbol("COL1")))).doesNotFire();
// https://github.com/prestodb/presto/issues/10592
tester().assertThat(new PushAggregationThroughOuterJoin()).on(p -> p.aggregation(ab -> ab.source(p.join(LEFT, p.project(Assignments.builder().putIdentity(p.symbol("COL1", BIGINT)).build(), p.aggregation(builder -> builder.singleGroupingSet(p.symbol("COL1"), p.symbol("unused")).source(p.values(ImmutableList.of(p.symbol("COL1"), p.symbol("unused")), ImmutableList.of(expressions("10", "1"), expressions("10", "2")))))), p.values(p.symbol("COL2")), ImmutableList.of(new EquiJoinClause(p.symbol("COL1"), p.symbol("COL2"))), ImmutableList.of(p.symbol("COL1")), ImmutableList.of(p.symbol("COL2")), Optional.empty(), Optional.empty(), Optional.empty())).addAggregation(p.symbol("AVG", DOUBLE), PlanBuilder.expression("avg(COL2)"), ImmutableList.of(DOUBLE)).singleGroupingSet(p.symbol("COL1")))).doesNotFire();
}
use of io.trino.spi.type.BigintType.BIGINT in project trino by trinodb.
the class TestPushDistinctLimitIntoTableScan method testPushDistinct.
@Test
public void testPushDistinct() {
AtomicInteger applyCallCounter = new AtomicInteger();
AtomicReference<List<AggregateFunction>> applyAggregates = new AtomicReference<>();
AtomicReference<Map<String, ColumnHandle>> applyAssignments = new AtomicReference<>();
AtomicReference<List<List<ColumnHandle>>> applyGroupingSets = new AtomicReference<>();
testApplyAggregation = (session, handle, aggregates, assignments, groupingSets) -> {
applyCallCounter.incrementAndGet();
applyAggregates.set(List.copyOf(aggregates));
applyAssignments.set(Map.copyOf(assignments));
applyGroupingSets.set(groupingSets.stream().map(List::copyOf).collect(toUnmodifiableList()));
return Optional.of(new AggregationApplicationResult<>(new MockConnectorTableHandle(new SchemaTableName("mock_schema", "mock_nation_aggregated")), List.of(), List.of(), Map.of(), false));
};
MockConnectorColumnHandle regionkeyHandle = new MockConnectorColumnHandle("regionkey", BIGINT);
tester().assertThat(rule).on(p -> {
Symbol regionkeySymbol = p.symbol("regionkey_symbol");
return p.distinctLimit(43, List.of(regionkeySymbol), p.tableScan(tableHandle, ImmutableList.of(regionkeySymbol), ImmutableMap.of(regionkeySymbol, regionkeyHandle)));
}).matches(limit(43, project(tableScan("mock_nation_aggregated"))));
assertThat(applyCallCounter).as("applyCallCounter").hasValue(1);
assertThat(applyAggregates).as("applyAggregates").hasValue(List.of());
assertThat(applyAssignments).as("applyAssignments").hasValue(Map.of("regionkey_symbol", regionkeyHandle));
assertThat(applyGroupingSets).as("applyGroupingSets").hasValue(List.of(List.of(regionkeyHandle)));
}
use of io.trino.spi.type.BigintType.BIGINT in project trino by trinodb.
the class TestPushdownFilterIntoWindow method assertKeepFilter.
private void assertKeepFilter(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", BIGINT);
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 and row_number_1 < cast(100 as bigint)"), p.window(new WindowNode.Specification(ImmutableList.of(a), Optional.of(orderingScheme)), ImmutableMap.of(rowNumberSymbol, newWindowNodeFunction(ranking, a)), p.values(p.symbol("a"))));
}).matches(filter("cast(3 as bigint) < row_number_1 and row_number_1 < cast(100 as bigint)", topNRanking(pattern -> pattern.partial(false).maxRankingPerPartition(99).specification(ImmutableList.of("a"), ImmutableList.of("a"), ImmutableMap.of("a", SortOrder.ASC_NULLS_FIRST)), values("a")).withAlias("row_number_1", new TopNRankingSymbolMatcher())));
tester().assertThat(new PushdownFilterIntoWindow(tester().getPlannerContext())).on(p -> {
Symbol rowNumberSymbol = p.symbol("row_number_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("row_number_1 < cast(100 as bigint) and a = 1"), p.window(new WindowNode.Specification(ImmutableList.of(a), Optional.of(orderingScheme)), ImmutableMap.of(rowNumberSymbol, newWindowNodeFunction(ranking, a)), p.values(p.symbol("a"))));
}).matches(filter("a = 1", topNRanking(pattern -> pattern.partial(false).maxRankingPerPartition(99).specification(ImmutableList.of("a"), ImmutableList.of("a"), ImmutableMap.of("a", SortOrder.ASC_NULLS_FIRST)), values("a")).withAlias("row_number_1", new TopNRankingSymbolMatcher())));
}
use of io.trino.spi.type.BigintType.BIGINT 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();
}
use of io.trino.spi.type.BigintType.BIGINT 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")));
}
Aggregations