Search in sources :

Example 41 with JoinNode

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

the class TestSourcePartitionedScheduler method createPlan.

private static SubPlan createPlan() {
    VariableReferenceExpression variable = new VariableReferenceExpression(Optional.empty(), "column", VARCHAR);
    // table scan with splitCount splits
    TableScanNode tableScan = new TableScanNode(Optional.empty(), TABLE_SCAN_NODE_ID, new TableHandle(CONNECTOR_ID, new TestingTableHandle(), TestingTransactionHandle.create(), Optional.empty()), ImmutableList.of(variable), ImmutableMap.of(variable, new TestingColumnHandle("column")), TupleDomain.all(), TupleDomain.all());
    RemoteSourceNode remote = new RemoteSourceNode(Optional.empty(), new PlanNodeId("remote_id"), new PlanFragmentId(0), ImmutableList.of(), false, Optional.empty(), GATHER);
    PlanFragment testFragment = new PlanFragment(new PlanFragmentId(0), new JoinNode(Optional.empty(), new PlanNodeId("join_id"), INNER, tableScan, remote, ImmutableList.of(), ImmutableList.<VariableReferenceExpression>builder().addAll(tableScan.getOutputVariables()).addAll(remote.getOutputVariables()).build(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), ImmutableMap.of()), ImmutableSet.of(variable), SOURCE_DISTRIBUTION, ImmutableList.of(TABLE_SCAN_NODE_ID), new PartitioningScheme(Partitioning.create(SINGLE_DISTRIBUTION, ImmutableList.of()), ImmutableList.of(variable)), StageExecutionDescriptor.ungroupedExecution(), false, StatsAndCosts.empty(), Optional.empty());
    return new SubPlan(testFragment, ImmutableList.of());
}
Also used : PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) TestingColumnHandle(com.facebook.presto.testing.TestingMetadata.TestingColumnHandle) RemoteSourceNode(com.facebook.presto.sql.planner.plan.RemoteSourceNode) TableScanNode(com.facebook.presto.spi.plan.TableScanNode) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) TestingTableHandle(com.facebook.presto.testing.TestingMetadata.TestingTableHandle) JoinNode(com.facebook.presto.sql.planner.plan.JoinNode) PartitioningScheme(com.facebook.presto.sql.planner.PartitioningScheme) TableHandle(com.facebook.presto.spi.TableHandle) TestingTableHandle(com.facebook.presto.testing.TestingMetadata.TestingTableHandle) PlanFragmentId(com.facebook.presto.sql.planner.plan.PlanFragmentId) PlanFragment(com.facebook.presto.sql.planner.PlanFragment) SubPlan(com.facebook.presto.sql.planner.SubPlan)

Example 42 with JoinNode

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

the class JoinMatcher method detailMatches.

@Override
public MatchResult detailMatches(PlanNode node, StatsProvider stats, Session session, Metadata metadata, SymbolAliases symbolAliases) {
    checkState(shapeMatches(node), "Plan testing framework error: shapeMatches returned false in detailMatches in %s", this.getClass().getName());
    JoinNode joinNode = (JoinNode) node;
    if (joinNode.getCriteria().size() != equiCriteria.size()) {
        return NO_MATCH;
    }
    if (filter.isPresent()) {
        if (!joinNode.getFilter().isPresent()) {
            return NO_MATCH;
        }
        RowExpression expression = joinNode.getFilter().get();
        if (isExpression(expression)) {
            if (!new ExpressionVerifier(symbolAliases).process(castToExpression(expression), filter.get())) {
                return NO_MATCH;
            }
        } else {
            if (!new RowExpressionVerifier(symbolAliases, metadata, session).process(filter.get(), expression)) {
                return NO_MATCH;
            }
        }
    } else {
        if (joinNode.getFilter().isPresent()) {
            return NO_MATCH;
        }
    }
    if (distributionType.isPresent() && !distributionType.equals(joinNode.getDistributionType())) {
        return NO_MATCH;
    }
    /*
         * Have to use order-independent comparison; there are no guarantees what order
         * the equi criteria will have after planning and optimizing.
         */
    Set<List<String>> actual = joinNode.getCriteria().stream().map(criteria -> ImmutableList.of(criteria.getLeft().getName(), criteria.getRight().getName())).collect(toImmutableSet());
    Set<List<String>> expected = equiCriteria.stream().map(maker -> maker.getExpectedValue(symbolAliases)).map(criteria -> ImmutableList.of(criteria.getLeft().getName(), criteria.getRight().getName())).collect(toImmutableSet());
    if (!expected.equals(actual)) {
        return NO_MATCH;
    }
    if (dynamicFilter.isPresent() && !dynamicFilter.get().match(joinNode, symbolAliases).isMatch()) {
        return NO_MATCH;
    }
    return MatchResult.match();
}
Also used : RowExpression(com.facebook.presto.spi.relation.RowExpression) JoinNode(com.facebook.presto.sql.planner.plan.JoinNode) OriginalExpressionUtils.isExpression(com.facebook.presto.sql.relational.OriginalExpressionUtils.isExpression) Session(com.facebook.presto.Session) StatsProvider(com.facebook.presto.cost.StatsProvider) Set(java.util.Set) Preconditions.checkState(com.google.common.base.Preconditions.checkState) PlanNode(com.facebook.presto.spi.plan.PlanNode) List(java.util.List) OriginalExpressionUtils.castToExpression(com.facebook.presto.sql.relational.OriginalExpressionUtils.castToExpression) Expression(com.facebook.presto.sql.tree.Expression) ImmutableList(com.google.common.collect.ImmutableList) Objects.requireNonNull(java.util.Objects.requireNonNull) Optional(java.util.Optional) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) NO_MATCH(com.facebook.presto.sql.planner.assertions.MatchResult.NO_MATCH) Metadata(com.facebook.presto.metadata.Metadata) DistributionType(com.facebook.presto.sql.planner.plan.JoinNode.DistributionType) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) JoinNode(com.facebook.presto.sql.planner.plan.JoinNode) RowExpression(com.facebook.presto.spi.relation.RowExpression) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList)

Example 43 with JoinNode

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

the class TestEffectivePredicateExtractor method testInnerJoinPropagatesPredicatesViaEquiConditions.

@Test
public void testInnerJoinPropagatesPredicatesViaEquiConditions() {
    Map<VariableReferenceExpression, ColumnHandle> leftAssignments = Maps.filterKeys(scanAssignments, Predicates.in(ImmutableList.of(AV, BV, CV)));
    TableScanNode leftScan = tableScanNode(leftAssignments);
    Map<VariableReferenceExpression, ColumnHandle> rightAssignments = Maps.filterKeys(scanAssignments, Predicates.in(ImmutableList.of(DV, EV, FV)));
    TableScanNode rightScan = tableScanNode(rightAssignments);
    FilterNode left = filter(leftScan, equals(AV, bigintLiteral(10)));
    // predicates on "a" column should be propagated to output symbols via join equi conditions
    PlanNode node = new JoinNode(Optional.empty(), newId(), JoinNode.Type.INNER, left, rightScan, ImmutableList.of(new JoinNode.EquiJoinClause(AV, DV)), ImmutableList.<VariableReferenceExpression>builder().addAll(rightScan.getOutputVariables()).build(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), ImmutableMap.of());
    RowExpression effectivePredicate = effectivePredicateExtractor.extract(node);
    assertEquals(normalizeConjuncts(effectivePredicate), normalizeConjuncts(equals(DV, bigintLiteral(10))));
}
Also used : ColumnHandle(com.facebook.presto.spi.ColumnHandle) PlanNode(com.facebook.presto.spi.plan.PlanNode) TableScanNode(com.facebook.presto.spi.plan.TableScanNode) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) JoinNode(com.facebook.presto.sql.planner.plan.JoinNode) SemiJoinNode(com.facebook.presto.sql.planner.plan.SemiJoinNode) FilterNode(com.facebook.presto.spi.plan.FilterNode) RowExpression(com.facebook.presto.spi.relation.RowExpression) Test(org.testng.annotations.Test)

Example 44 with JoinNode

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

the class TestEffectivePredicateExtractor method testRightJoin.

@Test
public void testRightJoin() {
    ImmutableList.Builder<JoinNode.EquiJoinClause> criteriaBuilder = ImmutableList.builder();
    criteriaBuilder.add(new JoinNode.EquiJoinClause(AV, DV));
    criteriaBuilder.add(new JoinNode.EquiJoinClause(BV, EV));
    List<JoinNode.EquiJoinClause> criteria = criteriaBuilder.build();
    Map<VariableReferenceExpression, ColumnHandle> leftAssignments = Maps.filterKeys(scanAssignments, Predicates.in(ImmutableList.of(AV, BV, CV)));
    TableScanNode leftScan = tableScanNode(leftAssignments);
    Map<VariableReferenceExpression, ColumnHandle> rightAssignments = Maps.filterKeys(scanAssignments, Predicates.in(ImmutableList.of(DV, EV, FV)));
    TableScanNode rightScan = tableScanNode(rightAssignments);
    FilterNode left = filter(leftScan, and(lessThan(BV, AV), lessThan(CV, bigintLiteral(10)), equals(GV, bigintLiteral(10))));
    FilterNode right = filter(rightScan, and(equals(DV, EV), lessThan(FV, bigintLiteral(100))));
    PlanNode node = new JoinNode(Optional.empty(), newId(), JoinNode.Type.RIGHT, left, right, criteria, ImmutableList.<VariableReferenceExpression>builder().addAll(left.getOutputVariables()).addAll(right.getOutputVariables()).build(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), ImmutableMap.of());
    RowExpression effectivePredicate = effectivePredicateExtractor.extract(node);
    // All left side symbols should be checked against NULL
    assertEquals(normalizeConjuncts(effectivePredicate), normalizeConjuncts(or(lessThan(BV, AV), and(isNull(BV), isNull(AV))), or(lessThan(CV, bigintLiteral(10)), isNull(CV)), equals(DV, EV), lessThan(FV, bigintLiteral(100)), or(equals(AV, DV), isNull(AV)), or(equals(BV, EV), isNull(BV))));
}
Also used : ColumnHandle(com.facebook.presto.spi.ColumnHandle) ImmutableList(com.google.common.collect.ImmutableList) JoinNode(com.facebook.presto.sql.planner.plan.JoinNode) SemiJoinNode(com.facebook.presto.sql.planner.plan.SemiJoinNode) FilterNode(com.facebook.presto.spi.plan.FilterNode) RowExpression(com.facebook.presto.spi.relation.RowExpression) PlanNode(com.facebook.presto.spi.plan.PlanNode) TableScanNode(com.facebook.presto.spi.plan.TableScanNode) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) Test(org.testng.annotations.Test)

Example 45 with JoinNode

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

the class TestEffectivePredicateExtractor method testInnerJoinWithFalseFilter.

@Test
public void testInnerJoinWithFalseFilter() {
    Map<VariableReferenceExpression, ColumnHandle> leftAssignments = Maps.filterKeys(scanAssignments, Predicates.in(ImmutableList.of(AV, BV, CV)));
    TableScanNode leftScan = tableScanNode(leftAssignments);
    Map<VariableReferenceExpression, ColumnHandle> rightAssignments = Maps.filterKeys(scanAssignments, Predicates.in(ImmutableList.of(DV, EV, FV)));
    TableScanNode rightScan = tableScanNode(rightAssignments);
    PlanNode node = new JoinNode(Optional.empty(), newId(), JoinNode.Type.INNER, leftScan, rightScan, ImmutableList.of(new JoinNode.EquiJoinClause(AV, DV)), ImmutableList.<VariableReferenceExpression>builder().addAll(leftScan.getOutputVariables()).addAll(rightScan.getOutputVariables()).build(), Optional.of(FALSE_CONSTANT), Optional.empty(), Optional.empty(), Optional.empty(), ImmutableMap.of());
    RowExpression effectivePredicate = effectivePredicateExtractor.extract(node);
    assertEquals(effectivePredicate, FALSE_CONSTANT);
}
Also used : ColumnHandle(com.facebook.presto.spi.ColumnHandle) PlanNode(com.facebook.presto.spi.plan.PlanNode) TableScanNode(com.facebook.presto.spi.plan.TableScanNode) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) JoinNode(com.facebook.presto.sql.planner.plan.JoinNode) SemiJoinNode(com.facebook.presto.sql.planner.plan.SemiJoinNode) RowExpression(com.facebook.presto.spi.relation.RowExpression) 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