Search in sources :

Example 6 with JoinNode

use of com.facebook.presto.sql.planner.plan.JoinNode in project presto by prestodb.

the class TestLocalDynamicFilter method testCreateSingleColumn.

@Test
public void testCreateSingleColumn() throws ExecutionException, InterruptedException {
    SubPlan subplan = subplan("SELECT count() FROM lineitem, orders WHERE lineitem.orderkey = orders.orderkey " + "AND orders.custkey < 10", LogicalPlanner.Stage.OPTIMIZED_AND_VALIDATED, false);
    JoinNode joinNode = searchJoins(subplan.getChildren().get(0).getFragment()).findOnlyElement();
    LocalDynamicFilter filter = LocalDynamicFilter.create(joinNode, 1).orElseThrow(NoSuchElementException::new);
    String filterId = Iterables.getOnlyElement(filter.getBuildChannels().keySet());
    VariableReferenceExpression probeVariable = Iterables.getOnlyElement(joinNode.getCriteria()).getLeft();
    filter.getTupleDomainConsumer().accept(TupleDomain.withColumnDomains(ImmutableMap.of(filterId, Domain.singleValue(BIGINT, 3L))));
    assertEquals(filter.getResultFuture().get(), TupleDomain.withColumnDomains(ImmutableMap.of(probeVariable, Domain.singleValue(BIGINT, 3L))));
}
Also used : JoinNode(com.facebook.presto.sql.planner.plan.JoinNode) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) NoSuchElementException(java.util.NoSuchElementException) BasePlanTest(com.facebook.presto.sql.planner.assertions.BasePlanTest) Test(org.testng.annotations.Test)

Example 7 with JoinNode

use of com.facebook.presto.sql.planner.plan.JoinNode in project presto by prestodb.

the class TestLocalDynamicFilter method testCreateDistributedJoin.

@Test
public void testCreateDistributedJoin() {
    Session session = Session.builder(getQueryRunner().getDefaultSession()).setSystemProperty(JOIN_DISTRIBUTION_TYPE, "PARTITIONED").build();
    SubPlan subplan = subplan("SELECT count() FROM nation, region WHERE nation.regionkey = region.regionkey " + "AND region.comment = 'abc'", LogicalPlanner.Stage.OPTIMIZED_AND_VALIDATED, false, session);
    JoinNode joinNode = searchJoins(subplan.getChildren().get(0).getFragment()).findOnlyElement();
    assertFalse(joinNode.getDynamicFilters().isEmpty());
    assertEquals(LocalDynamicFilter.create(joinNode, 1), Optional.empty());
}
Also used : JoinNode(com.facebook.presto.sql.planner.plan.JoinNode) Session(com.facebook.presto.Session) BasePlanTest(com.facebook.presto.sql.planner.assertions.BasePlanTest) Test(org.testng.annotations.Test)

Example 8 with JoinNode

use of com.facebook.presto.sql.planner.plan.JoinNode in project presto by prestodb.

the class TestEliminateCrossJoins method joinNode.

private JoinNode joinNode(PlanNode left, PlanNode right, VariableReferenceExpression... variables) {
    checkArgument(variables.length % 2 == 0);
    ImmutableList.Builder<JoinNode.EquiJoinClause> criteria = ImmutableList.builder();
    for (int i = 0; i < variables.length; i += 2) {
        criteria.add(new JoinNode.EquiJoinClause(variables[i], variables[i + 1]));
    }
    return new JoinNode(Optional.empty(), idAllocator.getNextId(), JoinNode.Type.INNER, left, right, criteria.build(), ImmutableList.<VariableReferenceExpression>builder().addAll(left.getOutputVariables()).addAll(right.getOutputVariables()).build(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), ImmutableMap.of());
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) EquiJoinClause(com.facebook.presto.sql.planner.plan.JoinNode.EquiJoinClause) JoinNode(com.facebook.presto.sql.planner.plan.JoinNode) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) EquiJoinClause(com.facebook.presto.sql.planner.plan.JoinNode.EquiJoinClause)

Example 9 with JoinNode

use of com.facebook.presto.sql.planner.plan.JoinNode in project presto by prestodb.

the class DynamicFilterMatcher method match.

private boolean match() {
    checkState(symbolAliases != null, "symbolAliases is null");
    // both nodes must be provided to do the matching
    if (filterNode == null || joinNode == null) {
        return true;
    }
    Map<String, VariableReferenceExpression> idToProbeSymbolMap = extractDynamicFilters(filterNode.getPredicate()).getDynamicConjuncts().stream().collect(toImmutableMap(DynamicFilters.DynamicFilterPlaceholder::getId, filter -> (VariableReferenceExpression) filter.getInput()));
    Map<String, VariableReferenceExpression> idToBuildSymbolMap = joinNode.getDynamicFilters();
    if (idToProbeSymbolMap == null) {
        return false;
    }
    if (idToProbeSymbolMap.size() != expectedDynamicFilters.size()) {
        return false;
    }
    Map<Symbol, Symbol> actual = new HashMap<>();
    for (Map.Entry<String, VariableReferenceExpression> idToProbeSymbol : idToProbeSymbolMap.entrySet()) {
        String id = idToProbeSymbol.getKey();
        VariableReferenceExpression probe = idToProbeSymbol.getValue();
        VariableReferenceExpression build = idToBuildSymbolMap.get(id);
        if (build == null) {
            return false;
        }
        actual.put(new Symbol(probe.getName()), new Symbol(build.getName()));
    }
    Map<Symbol, Symbol> expected = expectedDynamicFilters.entrySet().stream().collect(toImmutableMap(entry -> entry.getKey().toSymbol(symbolAliases), entry -> entry.getValue().toSymbol(symbolAliases)));
    return expected.equals(actual);
}
Also used : RowExpression(com.facebook.presto.spi.relation.RowExpression) JoinNode(com.facebook.presto.sql.planner.plan.JoinNode) Session(com.facebook.presto.Session) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) StatsProvider(com.facebook.presto.cost.StatsProvider) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) HashMap(java.util.HashMap) RowExpressionDeterminismEvaluator(com.facebook.presto.sql.relational.RowExpressionDeterminismEvaluator) Preconditions.checkState(com.google.common.base.Preconditions.checkState) FilterNode(com.facebook.presto.spi.plan.FilterNode) PlanNode(com.facebook.presto.spi.plan.PlanNode) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) Expression(com.facebook.presto.sql.tree.Expression) LogicalRowExpressions(com.facebook.presto.expressions.LogicalRowExpressions) Symbol(com.facebook.presto.sql.planner.Symbol) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) Optional(java.util.Optional) FunctionResolution(com.facebook.presto.sql.relational.FunctionResolution) DynamicFilters(com.facebook.presto.expressions.DynamicFilters) Metadata(com.facebook.presto.metadata.Metadata) Joiner(com.google.common.base.Joiner) DynamicFilters.extractDynamicFilters(com.facebook.presto.expressions.DynamicFilters.extractDynamicFilters) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) DynamicFilters(com.facebook.presto.expressions.DynamicFilters) DynamicFilters.extractDynamicFilters(com.facebook.presto.expressions.DynamicFilters.extractDynamicFilters) HashMap(java.util.HashMap) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) Symbol(com.facebook.presto.sql.planner.Symbol) HashMap(java.util.HashMap) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) Map(java.util.Map)

Example 10 with JoinNode

use of com.facebook.presto.sql.planner.plan.JoinNode in project presto by prestodb.

the class TestJoinNodeFlattener method testDoesNotAllowOuterJoin.

@Test(expectedExceptions = IllegalStateException.class)
public void testDoesNotAllowOuterJoin() {
    PlanBuilder p = planBuilder();
    VariableReferenceExpression a1 = p.variable("A1");
    VariableReferenceExpression b1 = p.variable("B1");
    JoinNode outerJoin = p.join(FULL, p.values(a1), p.values(b1), ImmutableList.of(equiJoinClause(a1, b1)), ImmutableList.of(a1, b1), Optional.empty());
    toMultiJoinNode(outerJoin, noLookup(), DEFAULT_JOIN_LIMIT, functionResolution, determinismEvaluator);
}
Also used : VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) JoinNode(com.facebook.presto.sql.planner.plan.JoinNode) MultiJoinNode.toMultiJoinNode(com.facebook.presto.sql.planner.iterative.rule.ReorderJoins.MultiJoinNode.toMultiJoinNode) MultiJoinNode(com.facebook.presto.sql.planner.iterative.rule.ReorderJoins.MultiJoinNode) PlanBuilder(com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder) Test(org.testng.annotations.Test)

Aggregations

JoinNode (com.facebook.presto.sql.planner.plan.JoinNode)49 VariableReferenceExpression (com.facebook.presto.spi.relation.VariableReferenceExpression)36 Test (org.testng.annotations.Test)24 PlanNode (com.facebook.presto.spi.plan.PlanNode)23 TableScanNode (com.facebook.presto.spi.plan.TableScanNode)15 RowExpression (com.facebook.presto.spi.relation.RowExpression)15 ImmutableList (com.google.common.collect.ImmutableList)13 FilterNode (com.facebook.presto.spi.plan.FilterNode)11 ColumnHandle (com.facebook.presto.spi.ColumnHandle)9 PlanNodeId (com.facebook.presto.spi.plan.PlanNodeId)9 SemiJoinNode (com.facebook.presto.sql.planner.plan.SemiJoinNode)9 Type (com.facebook.presto.common.type.Type)8 ProjectNode (com.facebook.presto.spi.plan.ProjectNode)8 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)8 Session (com.facebook.presto.Session)6 Metadata (com.facebook.presto.metadata.Metadata)6 Assignments (com.facebook.presto.spi.plan.Assignments)6 BasePlanTest (com.facebook.presto.sql.planner.assertions.BasePlanTest)6 MultiJoinNode (com.facebook.presto.sql.planner.iterative.rule.ReorderJoins.MultiJoinNode)6 MultiJoinNode.toMultiJoinNode (com.facebook.presto.sql.planner.iterative.rule.ReorderJoins.MultiJoinNode.toMultiJoinNode)6