Search in sources :

Example 1 with PlanBuilder

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

the class TestLocalDynamicFilterConsumer method testDynamicFilterPruning.

@Test
public void testDynamicFilterPruning() throws Exception {
    PlanBuilder planBuilder = new PlanBuilder(new PlanNodeIdAllocator(), dummyMetadata(), getQueryRunner().getDefaultSession());
    Symbol left1 = planBuilder.symbol("left1", BIGINT);
    Symbol left2 = planBuilder.symbol("left2", INTEGER);
    Symbol left3 = planBuilder.symbol("left3", SMALLINT);
    Symbol right1 = planBuilder.symbol("right1", BIGINT);
    Symbol right2 = planBuilder.symbol("right2", INTEGER);
    Symbol right3 = planBuilder.symbol("right3", SMALLINT);
    DynamicFilterId filter1 = new DynamicFilterId("filter1");
    DynamicFilterId filter2 = new DynamicFilterId("filter2");
    DynamicFilterId filter3 = new DynamicFilterId("filter3");
    JoinNode joinNode = planBuilder.join(INNER, planBuilder.values(left1, left2, left3), planBuilder.values(right1, right2, right3), ImmutableList.of(new EquiJoinClause(left1, right1), new EquiJoinClause(left2, right2), new EquiJoinClause(left3, right3)), ImmutableList.of(), ImmutableList.of(), Optional.empty(), Optional.empty(), Optional.empty(), ImmutableMap.of(filter1, right1, filter2, right2, filter3, right3));
    LocalDynamicFilterConsumer consumer = LocalDynamicFilterConsumer.create(joinNode, ImmutableList.of(BIGINT, INTEGER, SMALLINT), 1, ImmutableSet.of(filter1, filter3));
    assertEquals(consumer.getBuildChannels(), ImmutableMap.of(filter1, 0, filter3, 2));
    // make sure domain types got propagated correctly
    consumer.getTupleDomainConsumer().accept(TupleDomain.none());
    assertEquals(consumer.getDynamicFilterDomains().get(), ImmutableMap.of(filter1, Domain.none(BIGINT), filter3, Domain.none(SMALLINT)));
}
Also used : JoinNode(io.trino.sql.planner.plan.JoinNode) EquiJoinClause(io.trino.sql.planner.plan.JoinNode.EquiJoinClause) PlanBuilder(io.trino.sql.planner.iterative.rule.test.PlanBuilder) DynamicFilterId(io.trino.sql.planner.plan.DynamicFilterId) Test(org.testng.annotations.Test) BasePlanTest(io.trino.sql.planner.assertions.BasePlanTest)

Example 2 with PlanBuilder

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

the class TestSchedulingOrderVisitor method testIndexJoinOrder.

@Test
public void testIndexJoinOrder() {
    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.indexJoin(IndexJoinNode.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 3 with PlanBuilder

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

the class TestRemoveAggregationInSemiJoin method semiJoinWithDistinctAsFilteringSource.

private static PlanNode semiJoinWithDistinctAsFilteringSource(PlanBuilder p) {
    Symbol leftKey = p.symbol("leftKey");
    Symbol rightKey = p.symbol("rightKey");
    return p.semiJoin(leftKey, rightKey, p.symbol("match"), Optional.empty(), Optional.empty(), p.values(leftKey), p.aggregation(builder -> builder.singleGroupingSet(rightKey).source(p.values(rightKey))));
}
Also used : Symbol(io.trino.sql.planner.Symbol) ImmutableList(com.google.common.collect.ImmutableList) BIGINT(io.trino.spi.type.BigintType.BIGINT) BaseRuleTest(io.trino.sql.planner.iterative.rule.test.BaseRuleTest) PlanMatchPattern.semiJoin(io.trino.sql.planner.assertions.PlanMatchPattern.semiJoin) PlanBuilder(io.trino.sql.planner.iterative.rule.test.PlanBuilder) Optional(java.util.Optional) Test(org.testng.annotations.Test) PlanMatchPattern.values(io.trino.sql.planner.assertions.PlanMatchPattern.values) PlanBuilder.expression(io.trino.sql.planner.iterative.rule.test.PlanBuilder.expression) PlanNode(io.trino.sql.planner.plan.PlanNode) Symbol(io.trino.sql.planner.Symbol)

Example 4 with PlanBuilder

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

the class TestRemoveAggregationInSemiJoin method semiJoinWithAggregationAsFilteringSource.

private static PlanNode semiJoinWithAggregationAsFilteringSource(PlanBuilder p) {
    Symbol leftKey = p.symbol("leftKey");
    Symbol rightKey = p.symbol("rightKey");
    return p.semiJoin(leftKey, rightKey, p.symbol("match"), Optional.empty(), Optional.empty(), p.values(leftKey), p.aggregation(builder -> builder.globalGrouping().addAggregation(rightKey, expression("count(rightValue)"), ImmutableList.of(BIGINT)).source(p.values(p.symbol("rightValue")))));
}
Also used : Symbol(io.trino.sql.planner.Symbol) ImmutableList(com.google.common.collect.ImmutableList) BIGINT(io.trino.spi.type.BigintType.BIGINT) BaseRuleTest(io.trino.sql.planner.iterative.rule.test.BaseRuleTest) PlanMatchPattern.semiJoin(io.trino.sql.planner.assertions.PlanMatchPattern.semiJoin) PlanBuilder(io.trino.sql.planner.iterative.rule.test.PlanBuilder) Optional(java.util.Optional) Test(org.testng.annotations.Test) PlanMatchPattern.values(io.trino.sql.planner.assertions.PlanMatchPattern.values) PlanBuilder.expression(io.trino.sql.planner.iterative.rule.test.PlanBuilder.expression) PlanNode(io.trino.sql.planner.plan.PlanNode) Symbol(io.trino.sql.planner.Symbol)

Example 5 with PlanBuilder

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

the class TestDetermineJoinDistributionType method testGetSourceTablesSizeInBytes.

@Test
public void testGetSourceTablesSizeInBytes() {
    PlanBuilder planBuilder = new PlanBuilder(new PlanNodeIdAllocator(), tester.getMetadata(), tester.getSession());
    Symbol symbol = planBuilder.symbol("col");
    Symbol sourceSymbol1 = planBuilder.symbol("source1");
    Symbol sourceSymbol2 = planBuilder.symbol("soruce2");
    // missing source stats
    assertEquals(getSourceTablesSizeInBytes(planBuilder.values(symbol), noLookup(), node -> PlanNodeStatsEstimate.unknown(), planBuilder.getTypes()), NaN);
    // two source plan nodes
    PlanNodeStatsEstimate sourceStatsEstimate1 = PlanNodeStatsEstimate.builder().setOutputRowCount(10).build();
    PlanNodeStatsEstimate sourceStatsEstimate2 = PlanNodeStatsEstimate.builder().setOutputRowCount(20).build();
    assertEquals(getSourceTablesSizeInBytes(planBuilder.union(ImmutableListMultimap.<Symbol, Symbol>builder().put(symbol, sourceSymbol1).put(symbol, sourceSymbol2).build(), ImmutableList.of(planBuilder.tableScan(ImmutableList.of(sourceSymbol1), ImmutableMap.of(sourceSymbol1, new TestingColumnHandle("col"))), planBuilder.values(new PlanNodeId("valuesNode"), sourceSymbol2))), noLookup(), node -> {
        if (node instanceof TableScanNode) {
            return sourceStatsEstimate1;
        }
        if (node instanceof ValuesNode) {
            return sourceStatsEstimate2;
        }
        return PlanNodeStatsEstimate.unknown();
    }, planBuilder.getTypes()), 270.0);
    // join node
    assertEquals(getSourceTablesSizeInBytes(planBuilder.join(INNER, planBuilder.values(sourceSymbol1), planBuilder.values(sourceSymbol2)), noLookup(), node -> sourceStatsEstimate1, planBuilder.getTypes()), NaN);
}
Also used : PARTITIONED(io.trino.sql.planner.plan.JoinNode.DistributionType.PARTITIONED) INNER(io.trino.sql.planner.plan.JoinNode.Type.INNER) VarcharType.createUnboundedVarcharType(io.trino.spi.type.VarcharType.createUnboundedVarcharType) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) PlanMatchPattern.filter(io.trino.sql.planner.assertions.PlanMatchPattern.filter) REPLICATED(io.trino.sql.planner.plan.JoinNode.DistributionType.REPLICATED) Lookup.noLookup(io.trino.sql.planner.iterative.Lookup.noLookup) VarcharType(io.trino.spi.type.VarcharType) LEFT(io.trino.sql.planner.plan.JoinNode.Type.LEFT) RuleAssert(io.trino.sql.planner.iterative.rule.test.RuleAssert) Type(io.trino.sql.planner.plan.JoinNode.Type) PlanBuilder.expressions(io.trino.sql.planner.iterative.rule.test.PlanBuilder.expressions) ImmutableList(com.google.common.collect.ImmutableList) NaN(java.lang.Double.NaN) DistributionType(io.trino.sql.planner.plan.JoinNode.DistributionType) PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) PlanBuilder(io.trino.sql.planner.iterative.rule.test.PlanBuilder) PlanMatchPattern.equiJoinClause(io.trino.sql.planner.assertions.PlanMatchPattern.equiJoinClause) JoinNode(io.trino.sql.planner.plan.JoinNode) TableScanNode(io.trino.sql.planner.plan.TableScanNode) PlanMatchPattern.join(io.trino.sql.planner.assertions.PlanMatchPattern.join) PlanNodeStatsEstimate(io.trino.cost.PlanNodeStatsEstimate) JOIN_MAX_BROADCAST_TABLE_SIZE(io.trino.SystemSessionProperties.JOIN_MAX_BROADCAST_TABLE_SIZE) TaskCountEstimator(io.trino.cost.TaskCountEstimator) Symbol(io.trino.sql.planner.Symbol) AfterClass(org.testng.annotations.AfterClass) SymbolStatsEstimate(io.trino.cost.SymbolStatsEstimate) RuleTester.defaultRuleTester(io.trino.sql.planner.iterative.rule.test.RuleTester.defaultRuleTester) ImmutableMap(com.google.common.collect.ImmutableMap) BeforeClass(org.testng.annotations.BeforeClass) FULL(io.trino.sql.planner.plan.JoinNode.Type.FULL) RuleTester(io.trino.sql.planner.iterative.rule.test.RuleTester) PlanMatchPattern.values(io.trino.sql.planner.assertions.PlanMatchPattern.values) TRUE_LITERAL(io.trino.sql.tree.BooleanLiteral.TRUE_LITERAL) JoinDistributionType(io.trino.sql.planner.OptimizerConfig.JoinDistributionType) DetermineJoinDistributionType.getSourceTablesSizeInBytes(io.trino.sql.planner.iterative.rule.DetermineJoinDistributionType.getSourceTablesSizeInBytes) CostComparator(io.trino.cost.CostComparator) PlanMatchPattern.enforceSingleRow(io.trino.sql.planner.assertions.PlanMatchPattern.enforceSingleRow) BIGINT(io.trino.spi.type.BigintType.BIGINT) RIGHT(io.trino.sql.planner.plan.JoinNode.Type.RIGHT) JOIN_DISTRIBUTION_TYPE(io.trino.SystemSessionProperties.JOIN_DISTRIBUTION_TYPE) ImmutableListMultimap(com.google.common.collect.ImmutableListMultimap) Optional(java.util.Optional) ValuesNode(io.trino.sql.planner.plan.ValuesNode) TestingColumnHandle(io.trino.testing.TestingMetadata.TestingColumnHandle) PlanBuilder.expression(io.trino.sql.planner.iterative.rule.test.PlanBuilder.expression) PlanNodeIdAllocator(io.trino.sql.planner.PlanNodeIdAllocator) PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) TestingColumnHandle(io.trino.testing.TestingMetadata.TestingColumnHandle) ValuesNode(io.trino.sql.planner.plan.ValuesNode) TableScanNode(io.trino.sql.planner.plan.TableScanNode) PlanNodeIdAllocator(io.trino.sql.planner.PlanNodeIdAllocator) PlanNodeStatsEstimate(io.trino.cost.PlanNodeStatsEstimate) Symbol(io.trino.sql.planner.Symbol) PlanBuilder(io.trino.sql.planner.iterative.rule.test.PlanBuilder) 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