Search in sources :

Example 21 with JoinNode

use of io.trino.sql.planner.plan.JoinNode in project trino by trinodb.

the class TestSourcePartitionedScheduler method createFragment.

private static PlanFragment createFragment() {
    Symbol symbol = new Symbol("column");
    Symbol buildSymbol = new Symbol("buildColumn");
    // table scan with splitCount splits
    TableScanNode tableScan = TableScanNode.newInstance(TABLE_SCAN_NODE_ID, TEST_TABLE_HANDLE, ImmutableList.of(symbol), ImmutableMap.of(symbol, new TestingColumnHandle("column")), false, Optional.empty());
    FilterNode filterNode = new FilterNode(new PlanNodeId("filter_node_id"), tableScan, createDynamicFilterExpression(TEST_SESSION, createTestMetadataManager(), DYNAMIC_FILTER_ID, VARCHAR, symbol.toSymbolReference()));
    RemoteSourceNode remote = new RemoteSourceNode(new PlanNodeId("remote_id"), new PlanFragmentId("plan_fragment_id"), ImmutableList.of(buildSymbol), Optional.empty(), REPLICATE, RetryPolicy.NONE);
    return new PlanFragment(new PlanFragmentId("plan_id"), new JoinNode(new PlanNodeId("join_id"), INNER, filterNode, remote, ImmutableList.of(), tableScan.getOutputSymbols(), remote.getOutputSymbols(), false, Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), ImmutableMap.of(DYNAMIC_FILTER_ID, buildSymbol), Optional.empty()), ImmutableMap.of(symbol, VARCHAR), SOURCE_DISTRIBUTION, ImmutableList.of(TABLE_SCAN_NODE_ID), new PartitioningScheme(Partitioning.create(SINGLE_DISTRIBUTION, ImmutableList.of()), ImmutableList.of(symbol)), ungroupedExecution(), StatsAndCosts.empty(), Optional.empty());
}
Also used : PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) TestingColumnHandle(io.trino.testing.TestingMetadata.TestingColumnHandle) RemoteSourceNode(io.trino.sql.planner.plan.RemoteSourceNode) TableScanNode(io.trino.sql.planner.plan.TableScanNode) Symbol(io.trino.sql.planner.Symbol) JoinNode(io.trino.sql.planner.plan.JoinNode) PartitioningScheme(io.trino.sql.planner.PartitioningScheme) FilterNode(io.trino.sql.planner.plan.FilterNode) PlanFragmentId(io.trino.sql.planner.plan.PlanFragmentId) PlanFragment(io.trino.sql.planner.PlanFragment)

Example 22 with JoinNode

use of io.trino.sql.planner.plan.JoinNode in project trino by trinodb.

the class PlanUtils method createBroadcastAndPartitionedJoinPlanFragment.

static PlanFragment createBroadcastAndPartitionedJoinPlanFragment(String name, PlanFragment broadcastBuildFragment, PlanFragment partitionedBuildFragment, PlanFragment probeFragment) {
    RemoteSourceNode probe = new RemoteSourceNode(new PlanNodeId("probe_id"), probeFragment.getId(), ImmutableList.of(), Optional.empty(), REPARTITION, RetryPolicy.NONE);
    RemoteSourceNode broadcastBuild = new RemoteSourceNode(new PlanNodeId("broadcast_build_id"), broadcastBuildFragment.getId(), ImmutableList.of(), Optional.empty(), REPLICATE, RetryPolicy.NONE);
    RemoteSourceNode partitionedBuild = new RemoteSourceNode(new PlanNodeId("partitioned_build_id"), partitionedBuildFragment.getId(), ImmutableList.of(), Optional.empty(), REPARTITION, RetryPolicy.NONE);
    PlanNode broadcastPlanNode = new JoinNode(new PlanNodeId(name + "_broadcast_id"), INNER, probe, broadcastBuild, ImmutableList.of(), probe.getOutputSymbols(), broadcastBuild.getOutputSymbols(), false, Optional.empty(), Optional.empty(), Optional.empty(), Optional.of(REPLICATED), Optional.empty(), ImmutableMap.of(), Optional.empty());
    PlanNode partitionedPlanNode = new JoinNode(new PlanNodeId(name + "_partitioned_id"), INNER, broadcastPlanNode, partitionedBuild, ImmutableList.of(), broadcastPlanNode.getOutputSymbols(), partitionedBuild.getOutputSymbols(), false, Optional.empty(), Optional.empty(), Optional.empty(), Optional.of(PARTITIONED), Optional.empty(), ImmutableMap.of(), Optional.empty());
    return createFragment(partitionedPlanNode);
}
Also used : PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) RemoteSourceNode(io.trino.sql.planner.plan.RemoteSourceNode) PlanNode(io.trino.sql.planner.plan.PlanNode) JoinNode(io.trino.sql.planner.plan.JoinNode)

Example 23 with JoinNode

use of io.trino.sql.planner.plan.JoinNode in project trino by trinodb.

the class TestJoinNodeFlattener method testConvertsBushyTrees.

@Test
public void testConvertsBushyTrees() {
    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 joinNode = p.join(INNER, p.join(INNER, p.join(INNER, valuesA, valuesB, ImmutableList.of(equiJoinClause(a1, b1)), ImmutableList.of(a1), ImmutableList.of(b1), Optional.empty()), valuesC, ImmutableList.of(equiJoinClause(a1, c1)), ImmutableList.of(a1, b1), ImmutableList.of(c1), Optional.empty()), p.join(INNER, valuesD, valuesE, ImmutableList.of(equiJoinClause(d1, e1), equiJoinClause(d2, e2)), ImmutableList.of(d1, d2), ImmutableList.of(e1, e2), Optional.empty()), ImmutableList.of(equiJoinClause(b1, e1)), ImmutableList.of(a1, b1, c1), ImmutableList.of(d1, d2, e1, e2), Optional.empty());
    MultiJoinNode expected = MultiJoinNode.builder().setSources(valuesA, valuesB, valuesC, valuesD, valuesE).setFilter(and(createEqualsExpression(a1, b1), createEqualsExpression(a1, c1), createEqualsExpression(d1, e1), createEqualsExpression(d2, e2), createEqualsExpression(b1, e1))).setOutputSymbols(a1, b1, c1, d1, d2, e1, e2).build();
    assertEquals(toMultiJoinNode(queryRunner.getPlannerContext(), joinNode, noLookup(), planNodeIdAllocator, 5, false, testSessionBuilder().build(), createTestingTypeAnalyzer(queryRunner.getPlannerContext()), p.getTypes()), expected);
}
Also used : ValuesNode(io.trino.sql.planner.plan.ValuesNode) PlanNodeIdAllocator(io.trino.sql.planner.PlanNodeIdAllocator) Symbol(io.trino.sql.planner.Symbol) JoinNode(io.trino.sql.planner.plan.JoinNode) MultiJoinNode(io.trino.sql.planner.iterative.rule.ReorderJoins.MultiJoinNode) MultiJoinNode.toMultiJoinNode(io.trino.sql.planner.iterative.rule.ReorderJoins.MultiJoinNode.toMultiJoinNode) PlanBuilder(io.trino.sql.planner.iterative.rule.test.PlanBuilder) MultiJoinNode(io.trino.sql.planner.iterative.rule.ReorderJoins.MultiJoinNode) MultiJoinNode.toMultiJoinNode(io.trino.sql.planner.iterative.rule.ReorderJoins.MultiJoinNode.toMultiJoinNode) Test(org.testng.annotations.Test)

Example 24 with JoinNode

use of io.trino.sql.planner.plan.JoinNode in project trino by trinodb.

the class TestJoinNodeFlattener method testRetainsOutputSymbols.

@Test
public void testRetainsOutputSymbols() {
    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);
    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.empty()), ImmutableList.of(equiJoinClause(a1, b1)), ImmutableList.of(a1), ImmutableList.of(b1), Optional.empty());
    MultiJoinNode expected = MultiJoinNode.builder().setSources(valuesA, valuesB, valuesC).setFilter(and(createEqualsExpression(b1, c1), createEqualsExpression(a1, b1))).setOutputSymbols(a1, b1).build();
    assertEquals(toMultiJoinNode(queryRunner.getPlannerContext(), joinNode, noLookup(), planNodeIdAllocator, DEFAULT_JOIN_LIMIT, false, testSessionBuilder().build(), createTestingTypeAnalyzer(queryRunner.getPlannerContext()), p.getTypes()), expected);
}
Also used : ValuesNode(io.trino.sql.planner.plan.ValuesNode) PlanNodeIdAllocator(io.trino.sql.planner.PlanNodeIdAllocator) Symbol(io.trino.sql.planner.Symbol) JoinNode(io.trino.sql.planner.plan.JoinNode) MultiJoinNode(io.trino.sql.planner.iterative.rule.ReorderJoins.MultiJoinNode) MultiJoinNode.toMultiJoinNode(io.trino.sql.planner.iterative.rule.ReorderJoins.MultiJoinNode.toMultiJoinNode) PlanBuilder(io.trino.sql.planner.iterative.rule.test.PlanBuilder) MultiJoinNode(io.trino.sql.planner.iterative.rule.ReorderJoins.MultiJoinNode) MultiJoinNode.toMultiJoinNode(io.trino.sql.planner.iterative.rule.ReorderJoins.MultiJoinNode.toMultiJoinNode) Test(org.testng.annotations.Test)

Example 25 with JoinNode

use of io.trino.sql.planner.plan.JoinNode in project trino by trinodb.

the class TestJoinNodeFlattener method testDoesNotConvertNestedOuterJoins.

@Test
public void testDoesNotConvertNestedOuterJoins() {
    PlanNodeIdAllocator planNodeIdAllocator = new PlanNodeIdAllocator();
    PlanBuilder p = planBuilder(planNodeIdAllocator);
    Symbol a1 = p.symbol("A1");
    Symbol b1 = p.symbol("B1");
    Symbol c1 = p.symbol("C1");
    JoinNode leftJoin = p.join(LEFT, p.values(a1), p.values(b1), ImmutableList.of(equiJoinClause(a1, b1)), ImmutableList.of(a1), ImmutableList.of(b1), Optional.empty());
    ValuesNode valuesC = p.values(c1);
    JoinNode joinNode = p.join(INNER, leftJoin, valuesC, ImmutableList.of(equiJoinClause(a1, c1)), ImmutableList.of(a1, b1), ImmutableList.of(c1), Optional.empty());
    MultiJoinNode expected = MultiJoinNode.builder().setSources(leftJoin, valuesC).setFilter(createEqualsExpression(a1, c1)).setOutputSymbols(a1, b1, c1).build();
    assertEquals(toMultiJoinNode(queryRunner.getPlannerContext(), joinNode, noLookup(), planNodeIdAllocator, DEFAULT_JOIN_LIMIT, false, testSessionBuilder().build(), createTestingTypeAnalyzer(queryRunner.getPlannerContext()), p.getTypes()), expected);
}
Also used : ValuesNode(io.trino.sql.planner.plan.ValuesNode) PlanNodeIdAllocator(io.trino.sql.planner.PlanNodeIdAllocator) Symbol(io.trino.sql.planner.Symbol) JoinNode(io.trino.sql.planner.plan.JoinNode) MultiJoinNode(io.trino.sql.planner.iterative.rule.ReorderJoins.MultiJoinNode) MultiJoinNode.toMultiJoinNode(io.trino.sql.planner.iterative.rule.ReorderJoins.MultiJoinNode.toMultiJoinNode) PlanBuilder(io.trino.sql.planner.iterative.rule.test.PlanBuilder) MultiJoinNode(io.trino.sql.planner.iterative.rule.ReorderJoins.MultiJoinNode) MultiJoinNode.toMultiJoinNode(io.trino.sql.planner.iterative.rule.ReorderJoins.MultiJoinNode.toMultiJoinNode) Test(org.testng.annotations.Test)

Aggregations

JoinNode (io.trino.sql.planner.plan.JoinNode)56 Symbol (io.trino.sql.planner.Symbol)35 PlanNode (io.trino.sql.planner.plan.PlanNode)34 Expression (io.trino.sql.tree.Expression)22 Test (org.testng.annotations.Test)22 TableScanNode (io.trino.sql.planner.plan.TableScanNode)17 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)16 FilterNode (io.trino.sql.planner.plan.FilterNode)15 ComparisonExpression (io.trino.sql.tree.ComparisonExpression)15 ImmutableList (com.google.common.collect.ImmutableList)14 ProjectNode (io.trino.sql.planner.plan.ProjectNode)14 Assignments (io.trino.sql.planner.plan.Assignments)13 PlanNodeId (io.trino.sql.planner.plan.PlanNodeId)13 ColumnHandle (io.trino.spi.connector.ColumnHandle)10 PlanNodeIdAllocator (io.trino.sql.planner.PlanNodeIdAllocator)10 AggregationNode (io.trino.sql.planner.plan.AggregationNode)10 CorrelatedJoinNode (io.trino.sql.planner.plan.CorrelatedJoinNode)10 NotExpression (io.trino.sql.tree.NotExpression)10 Map (java.util.Map)10 Type (io.trino.spi.type.Type)9