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());
}
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();
}
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))));
}
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))));
}
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);
}
Aggregations