Search in sources :

Example 21 with PlanBuilder

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

the class TestPruneAggregationColumns method buildProjectedAggregation.

private ProjectNode buildProjectedAggregation(PlanBuilder planBuilder, Predicate<Symbol> projectionFilter) {
    Symbol a = planBuilder.symbol("a");
    Symbol b = planBuilder.symbol("b");
    Symbol key = planBuilder.symbol("key");
    return planBuilder.project(Assignments.identity(ImmutableList.of(a, b).stream().filter(projectionFilter).collect(toImmutableSet())), planBuilder.aggregation(aggregationBuilder -> aggregationBuilder.source(planBuilder.values(key)).singleGroupingSet(key).addAggregation(a, PlanBuilder.expression("count()"), ImmutableList.of()).addAggregation(b, PlanBuilder.expression("count()"), ImmutableList.of())));
}
Also used : Symbol(io.trino.sql.planner.Symbol) PlanMatchPattern.expression(io.trino.sql.planner.assertions.PlanMatchPattern.expression) PlanMatchPattern.aggregation(io.trino.sql.planner.assertions.PlanMatchPattern.aggregation) ImmutableMap(com.google.common.collect.ImmutableMap) BaseRuleTest(io.trino.sql.planner.iterative.rule.test.BaseRuleTest) Predicate(java.util.function.Predicate) Assignments(io.trino.sql.planner.plan.Assignments) SINGLE(io.trino.sql.planner.plan.AggregationNode.Step.SINGLE) Test(org.testng.annotations.Test) PlanMatchPattern.values(io.trino.sql.planner.assertions.PlanMatchPattern.values) PlanMatchPattern.singleGroupingSet(io.trino.sql.planner.assertions.PlanMatchPattern.singleGroupingSet) PlanMatchPattern.functionCall(io.trino.sql.planner.assertions.PlanMatchPattern.functionCall) Predicates.alwaysTrue(com.google.common.base.Predicates.alwaysTrue) PlanMatchPattern.strictProject(io.trino.sql.planner.assertions.PlanMatchPattern.strictProject) ImmutableList(com.google.common.collect.ImmutableList) PlanBuilder(io.trino.sql.planner.iterative.rule.test.PlanBuilder) Optional(java.util.Optional) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) ProjectNode(io.trino.sql.planner.plan.ProjectNode) Symbol(io.trino.sql.planner.Symbol)

Example 22 with PlanBuilder

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

the class StatsCalculatorTester method assertStatsFor.

public StatsCalculatorAssertion assertStatsFor(Session session, Function<PlanBuilder, PlanNode> planProvider) {
    PlanBuilder planBuilder = new PlanBuilder(new PlanNodeIdAllocator(), metadata, session);
    PlanNode planNode = planProvider.apply(planBuilder);
    return new StatsCalculatorAssertion(statsCalculator, session, planNode, planBuilder.getTypes());
}
Also used : PlanNode(io.trino.sql.planner.plan.PlanNode) PlanNodeIdAllocator(io.trino.sql.planner.PlanNodeIdAllocator) PlanBuilder(io.trino.sql.planner.iterative.rule.test.PlanBuilder)

Example 23 with PlanBuilder

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

the class TestSchedulingOrderVisitor method testJoinOrder.

@Test
public void testJoinOrder() {
    PlanBuilder planBuilder = new PlanBuilder(new PlanNodeIdAllocator(), dummyMetadata(), TEST_SESSION);
    TableScanNode a = planBuilder.tableScan(emptyList(), emptyMap());
    TableScanNode b = planBuilder.tableScan(emptyList(), emptyMap());
    List<PlanNodeId> order = scheduleOrder(planBuilder.join(JoinNode.Type.INNER, a, b));
    assertEquals(order, ImmutableList.of(b.getId(), a.getId()));
}
Also used : PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) TableScanNode(io.trino.sql.planner.plan.TableScanNode) PlanBuilder(io.trino.sql.planner.iterative.rule.test.PlanBuilder) Test(org.testng.annotations.Test)

Example 24 with PlanBuilder

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

the class TestSchedulingOrderVisitor method testSemiJoinOrder.

@Test
public void testSemiJoinOrder() {
    PlanBuilder planBuilder = new PlanBuilder(new PlanNodeIdAllocator(), dummyMetadata(), TEST_SESSION);
    Symbol sourceJoin = planBuilder.symbol("sourceJoin");
    TableScanNode a = planBuilder.tableScan(ImmutableList.of(sourceJoin), ImmutableMap.of(sourceJoin, new TestingColumnHandle("sourceJoin")));
    Symbol filteringSource = planBuilder.symbol("filteringSource");
    TableScanNode b = planBuilder.tableScan(ImmutableList.of(filteringSource), ImmutableMap.of(filteringSource, new TestingColumnHandle("filteringSource")));
    List<PlanNodeId> order = scheduleOrder(planBuilder.semiJoin(sourceJoin, filteringSource, planBuilder.symbol("semiJoinOutput"), Optional.empty(), Optional.empty(), a, b));
    assertEquals(order, ImmutableList.of(b.getId(), a.getId()));
}
Also used : PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) TestingColumnHandle(io.trino.spi.connector.TestingColumnHandle) TableScanNode(io.trino.sql.planner.plan.TableScanNode) PlanBuilder(io.trino.sql.planner.iterative.rule.test.PlanBuilder) Test(org.testng.annotations.Test)

Example 25 with PlanBuilder

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

the class TestDynamicFiltersChecker method setup.

@BeforeClass
public void setup() {
    plannerContext = getQueryRunner().getPlannerContext();
    metadata = plannerContext.getMetadata();
    builder = new PlanBuilder(new PlanNodeIdAllocator(), metadata, TEST_SESSION);
    CatalogName catalogName = getCurrentConnectorId();
    TableHandle lineitemTableHandle = new TableHandle(catalogName, new TpchTableHandle("sf1", "lineitem", 1.0), TestingTransactionHandle.create());
    lineitemOrderKeySymbol = builder.symbol("LINEITEM_OK", BIGINT);
    lineitemTableScanNode = builder.tableScan(lineitemTableHandle, ImmutableList.of(lineitemOrderKeySymbol), ImmutableMap.of(lineitemOrderKeySymbol, new TpchColumnHandle("orderkey", BIGINT)));
    TableHandle ordersTableHandle = new TableHandle(catalogName, new TpchTableHandle("sf1", "orders", 1.0), TestingTransactionHandle.create());
    ordersOrderKeySymbol = builder.symbol("ORDERS_OK", BIGINT);
    ordersTableScanNode = builder.tableScan(ordersTableHandle, ImmutableList.of(ordersOrderKeySymbol), ImmutableMap.of(ordersOrderKeySymbol, new TpchColumnHandle("orderkey", BIGINT)));
}
Also used : PlanNodeIdAllocator(io.trino.sql.planner.PlanNodeIdAllocator) TpchColumnHandle(io.trino.plugin.tpch.TpchColumnHandle) 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)

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