use of io.trino.sql.planner.assertions.ExpressionMatcher in project trino by trinodb.
the class TestLogicalPlanner method testOffset.
@Test
public void testOffset() {
assertPlan("SELECT name FROM nation OFFSET 2 ROWS", any(strictProject(ImmutableMap.of("name", new ExpressionMatcher("name")), filter("row_num > BIGINT '2'", rowNumber(pattern -> pattern.partitionBy(ImmutableList.of()), any(tableScan("nation", ImmutableMap.of("name", "name")))).withAlias("row_num", new RowNumberSymbolMatcher())))));
assertPlan("SELECT name FROM nation ORDER BY regionkey OFFSET 2 ROWS", any(strictProject(ImmutableMap.of("name", new ExpressionMatcher("name")), filter("row_num > BIGINT '2'", rowNumber(pattern -> pattern.partitionBy(ImmutableList.of()), anyTree(sort(ImmutableList.of(sort("regionkey", ASCENDING, LAST)), any(tableScan("nation", ImmutableMap.of("name", "name", "regionkey", "regionkey")))))).withAlias("row_num", new RowNumberSymbolMatcher())))));
assertPlan("SELECT name FROM nation ORDER BY regionkey OFFSET 2 ROWS FETCH NEXT 5 ROWS ONLY", any(strictProject(ImmutableMap.of("name", new ExpressionMatcher("name")), filter("row_num > BIGINT '2'", rowNumber(pattern -> pattern.partitionBy(ImmutableList.of()), any(topN(7, ImmutableList.of(sort("regionkey", ASCENDING, LAST)), TopNNode.Step.FINAL, anyTree(tableScan("nation", ImmutableMap.of("name", "name", "regionkey", "regionkey")))))).withAlias("row_num", new RowNumberSymbolMatcher())))));
assertPlan("SELECT name FROM nation OFFSET 2 ROWS FETCH NEXT 5 ROWS ONLY", any(strictProject(ImmutableMap.of("name", new ExpressionMatcher("name")), filter("row_num > BIGINT '2'", rowNumber(pattern -> pattern.partitionBy(ImmutableList.of()), limit(7, any(tableScan("nation", ImmutableMap.of("name", "name"))))).withAlias("row_num", new RowNumberSymbolMatcher())))));
}
use of io.trino.sql.planner.assertions.ExpressionMatcher in project trino by trinodb.
the class TestPushLimitThroughProject method testLimitWithPreSortedInputs.
@Test
public void testLimitWithPreSortedInputs() {
// Do not push down order sensitive Limit if input ordering depends on symbol produced by Project
tester().assertThat(new PushLimitThroughProject(tester().getTypeAnalyzer())).on(p -> {
Symbol projectedA = p.symbol("projectedA");
Symbol a = p.symbol("a");
Symbol projectedC = p.symbol("projectedC");
Symbol b = p.symbol("b");
return p.limit(1, false, ImmutableList.of(projectedC), p.project(Assignments.of(projectedA, new SymbolReference("a"), projectedC, new ArithmeticBinaryExpression(ADD, new SymbolReference("a"), new SymbolReference("b"))), p.values(a, b)));
}).doesNotFire();
tester().assertThat(new PushLimitThroughProject(tester().getTypeAnalyzer())).on(p -> {
Symbol projectedA = p.symbol("projectedA");
Symbol a = p.symbol("a");
Symbol projectedC = p.symbol("projectedC");
Symbol b = p.symbol("b");
return p.limit(1, ImmutableList.of(), true, ImmutableList.of(projectedA), p.project(Assignments.of(projectedA, new SymbolReference("a"), projectedC, new ArithmeticBinaryExpression(ADD, new SymbolReference("a"), new SymbolReference("b"))), p.values(a, b)));
}).matches(project(ImmutableMap.of("projectedA", new ExpressionMatcher("a"), "projectedC", new ExpressionMatcher("a + b")), limit(1, ImmutableList.of(), true, ImmutableList.of("a"), values("a", "b"))));
}
use of io.trino.sql.planner.assertions.ExpressionMatcher in project trino by trinodb.
the class TestTransformUncorrelatedSubqueryToJoin method testRewriteRightCorrelatedJoin.
@Test
public void testRewriteRightCorrelatedJoin() {
tester().assertThat(new TransformUncorrelatedSubqueryToJoin()).on(p -> {
Symbol a = p.symbol("a");
Symbol b = p.symbol("b");
return p.correlatedJoin(emptyList(), p.values(a), RIGHT, TRUE_LITERAL, p.values(b));
}).matches(join(JoinNode.Type.INNER, ImmutableList.of(), Optional.empty(), values("a"), values("b")));
tester().assertThat(new TransformUncorrelatedSubqueryToJoin()).on(p -> {
Symbol a = p.symbol("a");
Symbol b = p.symbol("b");
return p.correlatedJoin(emptyList(), p.values(a), RIGHT, new ComparisonExpression(GREATER_THAN, b.toSymbolReference(), a.toSymbolReference()), p.values(b));
}).matches(project(ImmutableMap.of("a", new ExpressionMatcher("if(b > a, a, null)"), "b", new ExpressionMatcher("b")), join(JoinNode.Type.INNER, ImmutableList.of(), Optional.empty(), values("a"), values("b"))));
}
use of io.trino.sql.planner.assertions.ExpressionMatcher in project trino by trinodb.
the class TestLogicalPlanner method testWithTies.
@Test
public void testWithTies() {
assertPlan("SELECT name, regionkey FROM nation ORDER BY regionkey FETCH FIRST 6 ROWS WITH TIES", any(strictProject(ImmutableMap.of("name", new ExpressionMatcher("name"), "regionkey", new ExpressionMatcher("regionkey")), topNRanking(pattern -> pattern.specification(ImmutableList.of(), ImmutableList.of("regionkey"), ImmutableMap.of("regionkey", SortOrder.ASC_NULLS_LAST)).rankingType(RANK).maxRankingPerPartition(6).partial(false), anyTree(tableScan("nation", ImmutableMap.of("name", "name", "regionkey", "regionkey")))))));
assertPlan("SELECT name, regionkey FROM nation ORDER BY regionkey OFFSET 10 ROWS FETCH FIRST 6 ROWS WITH TIES", any(strictProject(ImmutableMap.of("name", new ExpressionMatcher("name"), "regionkey", new ExpressionMatcher("regionkey")), filter("row_num > BIGINT '10'", rowNumber(pattern -> pattern.partitionBy(ImmutableList.of()), strictProject(ImmutableMap.of("name", new ExpressionMatcher("name"), "regionkey", new ExpressionMatcher("regionkey")), topNRanking(pattern -> pattern.specification(ImmutableList.of(), ImmutableList.of("regionkey"), ImmutableMap.of("regionkey", SortOrder.ASC_NULLS_LAST)).rankingType(RANK).maxRankingPerPartition(16).partial(false), anyTree(tableScan("nation", ImmutableMap.of("name", "name", "regionkey", "regionkey")))))).withAlias("row_num", new RowNumberSymbolMatcher())))));
}
Aggregations