Search in sources :

Example 26 with PlanBuilder

use of io.trino.sql.planner.iterative.rule.test.PlanBuilder in project trino by trinodb.

the class TestValidateAggregationsWithDefaultValues method setup.

@BeforeClass
public void setup() {
    plannerContext = getQueryRunner().getPlannerContext();
    builder = new PlanBuilder(new PlanNodeIdAllocator(), plannerContext.getMetadata(), TEST_SESSION);
    CatalogName catalogName = getCurrentConnectorId();
    TableHandle nationTableHandle = new TableHandle(catalogName, new TpchTableHandle("sf1", "nation", 1.0), TestingTransactionHandle.create());
    TpchColumnHandle nationkeyColumnHandle = new TpchColumnHandle("nationkey", BIGINT);
    symbol = new Symbol("nationkey");
    tableScanNode = builder.tableScan(nationTableHandle, ImmutableList.of(symbol), ImmutableMap.of(symbol, nationkeyColumnHandle));
}
Also used : PlanNodeIdAllocator(io.trino.sql.planner.PlanNodeIdAllocator) TpchColumnHandle(io.trino.plugin.tpch.TpchColumnHandle) Symbol(io.trino.sql.planner.Symbol) CatalogName(io.trino.connector.CatalogName) TpchTableHandle(io.trino.plugin.tpch.TpchTableHandle) TableHandle(io.trino.metadata.TableHandle) PlanBuilder(io.trino.sql.planner.iterative.rule.test.PlanBuilder) TpchTableHandle(io.trino.plugin.tpch.TpchTableHandle) BeforeClass(org.testng.annotations.BeforeClass)

Example 27 with PlanBuilder

use of io.trino.sql.planner.iterative.rule.test.PlanBuilder in project trino by trinodb.

the class TestValidateStreamingAggregations method validatePlan.

private void validatePlan(Function<PlanBuilder, PlanNode> planProvider) {
    getQueryRunner().inTransaction(session -> {
        PlanBuilder builder = new PlanBuilder(idAllocator, plannerContext.getMetadata(), session);
        PlanNode planNode = planProvider.apply(builder);
        TypeProvider types = builder.getTypes();
        // metadata.getCatalogHandle() registers the catalog for the transaction
        session.getCatalog().ifPresent(catalog -> plannerContext.getMetadata().getCatalogHandle(session, catalog));
        new ValidateStreamingAggregations().validate(planNode, session, plannerContext, typeAnalyzer, types, WarningCollector.NOOP);
        return null;
    });
}
Also used : PlanNode(io.trino.sql.planner.plan.PlanNode) TypeProvider(io.trino.sql.planner.TypeProvider) PlanBuilder(io.trino.sql.planner.iterative.rule.test.PlanBuilder)

Example 28 with PlanBuilder

use of io.trino.sql.planner.iterative.rule.test.PlanBuilder in project trino by trinodb.

the class TestPushProjectionThroughJoin method testDoesNotPushStraddlingProjection.

@Test
public void testDoesNotPushStraddlingProjection() {
    PlanBuilder p = new PlanBuilder(new PlanNodeIdAllocator(), dummyMetadata(), TEST_SESSION);
    Symbol a = p.symbol("a");
    Symbol b = p.symbol("b");
    Symbol c = p.symbol("c");
    ProjectNode planNode = p.project(Assignments.of(c, new ArithmeticBinaryExpression(ADD, a.toSymbolReference(), b.toSymbolReference())), p.join(INNER, p.values(a), p.values(b)));
    Optional<PlanNode> rewritten = pushProjectionThroughJoin(PLANNER_CONTEXT, planNode, noLookup(), new PlanNodeIdAllocator(), testSessionBuilder().build(), createTestingTypeAnalyzer(PLANNER_CONTEXT), p.getTypes());
    assertThat(rewritten).isEmpty();
}
Also used : ArithmeticBinaryExpression(io.trino.sql.tree.ArithmeticBinaryExpression) PlanNode(io.trino.sql.planner.plan.PlanNode) PlanNodeIdAllocator(io.trino.sql.planner.PlanNodeIdAllocator) Symbol(io.trino.sql.planner.Symbol) ProjectNode(io.trino.sql.planner.plan.ProjectNode) PlanBuilder(io.trino.sql.planner.iterative.rule.test.PlanBuilder) Test(org.testng.annotations.Test)

Example 29 with PlanBuilder

use of io.trino.sql.planner.iterative.rule.test.PlanBuilder in project trino by trinodb.

the class TestPushProjectionThroughJoin method testDoesNotPushProjectionThroughOuterJoin.

@Test
public void testDoesNotPushProjectionThroughOuterJoin() {
    PlanBuilder p = new PlanBuilder(new PlanNodeIdAllocator(), dummyMetadata(), TEST_SESSION);
    Symbol a = p.symbol("a");
    Symbol b = p.symbol("b");
    Symbol c = p.symbol("c");
    ProjectNode planNode = p.project(Assignments.of(c, new ArithmeticUnaryExpression(MINUS, a.toSymbolReference())), p.join(LEFT, p.values(a), p.values(b)));
    Optional<PlanNode> rewritten = pushProjectionThroughJoin(PLANNER_CONTEXT, planNode, noLookup(), new PlanNodeIdAllocator(), testSessionBuilder().build(), createTestingTypeAnalyzer(PLANNER_CONTEXT), p.getTypes());
    assertThat(rewritten).isEmpty();
}
Also used : PlanNode(io.trino.sql.planner.plan.PlanNode) PlanNodeIdAllocator(io.trino.sql.planner.PlanNodeIdAllocator) Symbol(io.trino.sql.planner.Symbol) ProjectNode(io.trino.sql.planner.plan.ProjectNode) ArithmeticUnaryExpression(io.trino.sql.tree.ArithmeticUnaryExpression) PlanBuilder(io.trino.sql.planner.iterative.rule.test.PlanBuilder) Test(org.testng.annotations.Test)

Example 30 with PlanBuilder

use of io.trino.sql.planner.iterative.rule.test.PlanBuilder in project trino by trinodb.

the class TestPushProjectionThroughJoin method testPushesProjectionThroughJoin.

@Test
public void testPushesProjectionThroughJoin() {
    PlanNodeIdAllocator idAllocator = new PlanNodeIdAllocator();
    PlanBuilder p = new PlanBuilder(idAllocator, dummyMetadata(), TEST_SESSION);
    Symbol a0 = p.symbol("a0");
    Symbol a1 = p.symbol("a1");
    Symbol a2 = p.symbol("a2");
    Symbol a3 = p.symbol("a3");
    Symbol b0 = p.symbol("b0");
    Symbol b1 = p.symbol("b1");
    Symbol b2 = p.symbol("b2");
    ProjectNode planNode = p.project(Assignments.of(a3, new ArithmeticUnaryExpression(MINUS, a2.toSymbolReference()), b2, new ArithmeticUnaryExpression(PLUS, b1.toSymbolReference())), p.join(INNER, // intermediate non-identity projections should be fully inlined
    p.project(Assignments.of(a2, new ArithmeticUnaryExpression(PLUS, a0.toSymbolReference()), a1, a1.toSymbolReference()), p.project(Assignments.builder().putIdentity(a0).putIdentity(a1).build(), p.values(a0, a1))), p.values(b0, b1), new JoinNode.EquiJoinClause(a1, b1)));
    Session session = testSessionBuilder().build();
    Optional<PlanNode> rewritten = pushProjectionThroughJoin(PLANNER_CONTEXT, planNode, noLookup(), idAllocator, session, createTestingTypeAnalyzer(PLANNER_CONTEXT), p.getTypes());
    assertTrue(rewritten.isPresent());
    assertPlan(session, dummyMetadata(), createTestingFunctionManager(), node -> unknown(), new Plan(rewritten.get(), p.getTypes(), empty()), noLookup(), join(INNER, ImmutableList.of(aliases -> new JoinNode.EquiJoinClause(new Symbol("a1"), new Symbol("b1"))), strictProject(ImmutableMap.of("a3", expression("-(+a0)"), "a1", expression("a1")), strictProject(ImmutableMap.of("a0", expression("a0"), "a1", expression("a1")), PlanMatchPattern.values("a0", "a1"))), strictProject(ImmutableMap.of("b2", expression("+b1"), "b1", expression("b1")), PlanMatchPattern.values("b0", "b1"))).withExactOutputs("a3", "b2"));
}
Also used : TypeAnalyzer.createTestingTypeAnalyzer(io.trino.sql.planner.TypeAnalyzer.createTestingTypeAnalyzer) PlanAssert.assertPlan(io.trino.sql.planner.assertions.PlanAssert.assertPlan) INNER(io.trino.sql.planner.plan.JoinNode.Type.INNER) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) PlanMatchPattern(io.trino.sql.planner.assertions.PlanMatchPattern) Test(org.testng.annotations.Test) PlanNode(io.trino.sql.planner.plan.PlanNode) Lookup.noLookup(io.trino.sql.planner.iterative.Lookup.noLookup) FunctionManager.createTestingFunctionManager(io.trino.metadata.FunctionManager.createTestingFunctionManager) LEFT(io.trino.sql.planner.plan.JoinNode.Type.LEFT) ImmutableList(com.google.common.collect.ImmutableList) ArithmeticUnaryExpression(io.trino.sql.tree.ArithmeticUnaryExpression) PlanBuilder(io.trino.sql.planner.iterative.rule.test.PlanBuilder) TEST_SESSION(io.trino.SessionTestUtils.TEST_SESSION) JoinNode(io.trino.sql.planner.plan.JoinNode) ProjectNode(io.trino.sql.planner.plan.ProjectNode) ArithmeticBinaryExpression(io.trino.sql.tree.ArithmeticBinaryExpression) PlanMatchPattern.join(io.trino.sql.planner.assertions.PlanMatchPattern.join) PLUS(io.trino.sql.tree.ArithmeticUnaryExpression.Sign.PLUS) Symbol(io.trino.sql.planner.Symbol) PlanMatchPattern.expression(io.trino.sql.planner.assertions.PlanMatchPattern.expression) ImmutableMap(com.google.common.collect.ImmutableMap) Assignments(io.trino.sql.planner.plan.Assignments) AbstractMockMetadata.dummyMetadata(io.trino.metadata.AbstractMockMetadata.dummyMetadata) TestingSession.testSessionBuilder(io.trino.testing.TestingSession.testSessionBuilder) PlanMatchPattern.strictProject(io.trino.sql.planner.assertions.PlanMatchPattern.strictProject) PushProjectionThroughJoin.pushProjectionThroughJoin(io.trino.sql.planner.iterative.rule.PushProjectionThroughJoin.pushProjectionThroughJoin) ADD(io.trino.sql.tree.ArithmeticBinaryExpression.Operator.ADD) PLANNER_CONTEXT(io.trino.sql.planner.TestingPlannerContext.PLANNER_CONTEXT) PlanNodeStatsEstimate.unknown(io.trino.cost.PlanNodeStatsEstimate.unknown) StatsAndCosts.empty(io.trino.cost.StatsAndCosts.empty) Optional(java.util.Optional) Assert.assertTrue(org.testng.Assert.assertTrue) Plan(io.trino.sql.planner.Plan) MINUS(io.trino.sql.tree.ArithmeticUnaryExpression.Sign.MINUS) PlanNodeIdAllocator(io.trino.sql.planner.PlanNodeIdAllocator) Session(io.trino.Session) PlanNode(io.trino.sql.planner.plan.PlanNode) PlanNodeIdAllocator(io.trino.sql.planner.PlanNodeIdAllocator) Symbol(io.trino.sql.planner.Symbol) ProjectNode(io.trino.sql.planner.plan.ProjectNode) ArithmeticUnaryExpression(io.trino.sql.tree.ArithmeticUnaryExpression) PlanAssert.assertPlan(io.trino.sql.planner.assertions.PlanAssert.assertPlan) Plan(io.trino.sql.planner.Plan) PlanBuilder(io.trino.sql.planner.iterative.rule.test.PlanBuilder) Session(io.trino.Session) Test(org.testng.annotations.Test)

Aggregations

PlanBuilder (io.trino.sql.planner.iterative.rule.test.PlanBuilder)30 Test (org.testng.annotations.Test)22 PlanNodeIdAllocator (io.trino.sql.planner.PlanNodeIdAllocator)21 Symbol (io.trino.sql.planner.Symbol)18 JoinNode (io.trino.sql.planner.plan.JoinNode)11 PlanNode (io.trino.sql.planner.plan.PlanNode)11 MultiJoinNode (io.trino.sql.planner.iterative.rule.ReorderJoins.MultiJoinNode)9 MultiJoinNode.toMultiJoinNode (io.trino.sql.planner.iterative.rule.ReorderJoins.MultiJoinNode.toMultiJoinNode)8 ValuesNode (io.trino.sql.planner.plan.ValuesNode)8 ImmutableList (com.google.common.collect.ImmutableList)5 Optional (java.util.Optional)5 PlanNodeId (io.trino.sql.planner.plan.PlanNodeId)4 ProjectNode (io.trino.sql.planner.plan.ProjectNode)4 TableScanNode (io.trino.sql.planner.plan.TableScanNode)4 ArithmeticBinaryExpression (io.trino.sql.tree.ArithmeticBinaryExpression)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 CatalogName (io.trino.connector.CatalogName)3 TableHandle (io.trino.metadata.TableHandle)3 TpchColumnHandle (io.trino.plugin.tpch.TpchColumnHandle)3 TpchTableHandle (io.trino.plugin.tpch.TpchTableHandle)3