use of io.trino.sql.planner.iterative.rule.test.PlanBuilder in project trino by trinodb.
the class TestCardinalityExtractorPlanVisitor method testLimitOnTopOfValues.
@Test
public void testLimitOnTopOfValues() {
PlanBuilder planBuilder = new PlanBuilder(new PlanNodeIdAllocator(), dummyMetadata(), TEST_SESSION);
assertEquals(extractCardinality(planBuilder.limit(3, planBuilder.values(emptyList(), ImmutableList.of(emptyList())))), Range.singleton(1L));
assertEquals(extractCardinality(planBuilder.limit(3, planBuilder.values(emptyList(), ImmutableList.of(emptyList(), emptyList(), emptyList(), emptyList())))), Range.singleton(3L));
}
use of io.trino.sql.planner.iterative.rule.test.PlanBuilder in project trino by trinodb.
the class TestJoinNodeFlattener method testDoesNotAllowOuterJoin.
@Test
public void testDoesNotAllowOuterJoin() {
PlanNodeIdAllocator planNodeIdAllocator = new PlanNodeIdAllocator();
PlanBuilder p = planBuilder(planNodeIdAllocator);
Symbol a1 = p.symbol("A1");
Symbol b1 = p.symbol("B1");
JoinNode outerJoin = p.join(FULL, p.values(a1), p.values(b1), ImmutableList.of(equiJoinClause(a1, b1)), ImmutableList.of(a1), ImmutableList.of(b1), Optional.empty());
assertThatThrownBy(() -> toMultiJoinNode(queryRunner.getPlannerContext(), outerJoin, noLookup(), planNodeIdAllocator, DEFAULT_JOIN_LIMIT, false, testSessionBuilder().build(), createTestingTypeAnalyzer(queryRunner.getPlannerContext()), p.getTypes())).isInstanceOf(IllegalStateException.class).hasMessageMatching("join type must be.*");
}
use of io.trino.sql.planner.iterative.rule.test.PlanBuilder in project trino by trinodb.
the class TestJoinNodeFlattener method testCombinesCriteriaAndFilters.
@Test
public void testCombinesCriteriaAndFilters() {
PlanNodeIdAllocator planNodeIdAllocator = new PlanNodeIdAllocator();
PlanBuilder p = planBuilder(planNodeIdAllocator);
Symbol a1 = p.symbol("A1");
Symbol b1 = p.symbol("B1");
Symbol b2 = p.symbol("B2");
Symbol c1 = p.symbol("C1");
Symbol c2 = p.symbol("C2");
ValuesNode valuesA = p.values(a1);
ValuesNode valuesB = p.values(b1, b2);
ValuesNode valuesC = p.values(c1, c2);
Expression bcFilter = and(new ComparisonExpression(GREATER_THAN, c2.toSymbolReference(), new LongLiteral("0")), new ComparisonExpression(NOT_EQUAL, c2.toSymbolReference(), new LongLiteral("7")), new ComparisonExpression(GREATER_THAN, b2.toSymbolReference(), c2.toSymbolReference()));
ComparisonExpression abcFilter = new ComparisonExpression(LESS_THAN, new ArithmeticBinaryExpression(ADD, a1.toSymbolReference(), c1.toSymbolReference()), b1.toSymbolReference());
JoinNode joinNode = p.join(INNER, valuesA, p.join(INNER, valuesB, valuesC, ImmutableList.of(equiJoinClause(b1, c1)), ImmutableList.of(b1, b2), ImmutableList.of(c1, c2), Optional.of(bcFilter)), ImmutableList.of(equiJoinClause(a1, b1)), ImmutableList.of(a1), ImmutableList.of(b1, b2, c1, c2), Optional.of(abcFilter));
MultiJoinNode expected = new MultiJoinNode(new LinkedHashSet<>(ImmutableList.of(valuesA, valuesB, valuesC)), and(new ComparisonExpression(EQUAL, b1.toSymbolReference(), c1.toSymbolReference()), new ComparisonExpression(EQUAL, a1.toSymbolReference(), b1.toSymbolReference()), bcFilter, abcFilter), ImmutableList.of(a1, b1, b2, c1, c2), false);
assertEquals(toMultiJoinNode(queryRunner.getPlannerContext(), joinNode, noLookup(), planNodeIdAllocator, DEFAULT_JOIN_LIMIT, false, testSessionBuilder().build(), createTestingTypeAnalyzer(queryRunner.getPlannerContext()), p.getTypes()), expected);
}
use of io.trino.sql.planner.iterative.rule.test.PlanBuilder in project trino by trinodb.
the class TestJoinNodeFlattener method testDoesNotPushStraddlingProjection.
@Test
public void testDoesNotPushStraddlingProjection() {
PlanNodeIdAllocator planNodeIdAllocator = new PlanNodeIdAllocator();
PlanBuilder p = planBuilder(planNodeIdAllocator);
Symbol a = p.symbol("A");
Symbol b = p.symbol("B");
Symbol c = p.symbol("C");
Symbol d = p.symbol("D");
ValuesNode valuesA = p.values(a);
ValuesNode valuesB = p.values(b);
ValuesNode valuesC = p.values(c);
JoinNode joinNode = p.join(INNER, p.project(Assignments.of(d, new ArithmeticBinaryExpression(SUBTRACT, a.toSymbolReference(), b.toSymbolReference())), p.join(INNER, valuesA, valuesB, equiJoinClause(a, b))), valuesC, equiJoinClause(d, c));
MultiJoinNode actual = toMultiJoinNode(queryRunner.getPlannerContext(), joinNode, noLookup(), planNodeIdAllocator, DEFAULT_JOIN_LIMIT, true, testSessionBuilder().build(), createTestingTypeAnalyzer(queryRunner.getPlannerContext()), p.getTypes());
assertEquals(actual.getOutputSymbols(), ImmutableList.of(d, c));
assertEquals(actual.getFilter(), createEqualsExpression(d, c));
assertFalse(actual.isPushedProjectionThroughJoin());
List<PlanNode> actualSources = ImmutableList.copyOf(actual.getSources());
assertPlan(p.getTypes(), actualSources.get(0), node(ProjectNode.class, node(JoinNode.class, values("a"), values("b"))).withNumberOfOutputColumns(1));
assertPlan(p.getTypes(), actualSources.get(1), values("c"));
}
use of io.trino.sql.planner.iterative.rule.test.PlanBuilder in project trino by trinodb.
the class TestJoinNodeFlattener method testMoreThanJoinLimit.
@Test
public void testMoreThanJoinLimit() {
PlanNodeIdAllocator planNodeIdAllocator = new PlanNodeIdAllocator();
PlanBuilder p = planBuilder(planNodeIdAllocator);
Symbol a1 = p.symbol("A1");
Symbol b1 = p.symbol("B1");
Symbol c1 = p.symbol("C1");
Symbol d1 = p.symbol("D1");
Symbol d2 = p.symbol("D2");
Symbol e1 = p.symbol("E1");
Symbol e2 = p.symbol("E2");
ValuesNode valuesA = p.values(a1);
ValuesNode valuesB = p.values(b1);
ValuesNode valuesC = p.values(c1);
ValuesNode valuesD = p.values(d1, d2);
ValuesNode valuesE = p.values(e1, e2);
JoinNode join1 = p.join(INNER, valuesA, valuesB, ImmutableList.of(equiJoinClause(a1, b1)), ImmutableList.of(a1), ImmutableList.of(b1), Optional.empty());
JoinNode join2 = p.join(INNER, valuesD, valuesE, ImmutableList.of(equiJoinClause(d1, e1), equiJoinClause(d2, e2)), ImmutableList.of(d1, d2), ImmutableList.of(e1, e2), Optional.empty());
JoinNode joinNode = p.join(INNER, p.join(INNER, join1, valuesC, ImmutableList.of(equiJoinClause(a1, c1)), ImmutableList.of(a1, b1), ImmutableList.of(c1), Optional.empty()), join2, ImmutableList.of(equiJoinClause(b1, e1)), ImmutableList.of(a1, b1, c1), ImmutableList.of(d1, d2, e1, e2), Optional.empty());
MultiJoinNode expected = MultiJoinNode.builder().setSources(join1, join2, valuesC).setFilter(and(createEqualsExpression(a1, c1), createEqualsExpression(b1, e1))).setOutputSymbols(a1, b1, c1, d1, d2, e1, e2).build();
assertEquals(toMultiJoinNode(queryRunner.getPlannerContext(), joinNode, noLookup(), planNodeIdAllocator, 2, false, testSessionBuilder().build(), createTestingTypeAnalyzer(queryRunner.getPlannerContext()), p.getTypes()), expected);
}
Aggregations