use of io.prestosql.spi.plan.JoinNode in project hetu-core by openlookeng.
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, node.getOutputSymbols()).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;
}
if (spillable.isPresent() && !spillable.equals(joinNode.isSpillable())) {
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<JoinNode.EquiJoinClause> actual = ImmutableSet.copyOf(joinNode.getCriteria());
Set<JoinNode.EquiJoinClause> expected = equiCriteria.stream().map(maker -> maker.getExpectedValue(symbolAliases)).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 io.prestosql.spi.plan.JoinNode in project hetu-core by openlookeng.
the class TestJoinNodeFlattener method testMoreThanJoinLimit.
@Test
public void testMoreThanJoinLimit() {
PlanBuilder p = planBuilder();
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 join1 = p.join(INNER, valuesA, valuesB, ImmutableList.of(equiJoinClause(a1, b1)), ImmutableList.of(a1, b1), Optional.empty());
JoinNode join2 = p.join(INNER, valuesD, valuesE, ImmutableList.of(equiJoinClause(d1, e1), equiJoinClause(d2, e2)), ImmutableList.of(d1, d2, e1, e2), Optional.empty());
JoinNode joinNode = p.join(INNER, p.join(INNER, join1, valuesC, ImmutableList.of(equiJoinClause(a1, c1)), ImmutableList.of(a1, b1, c1), Optional.empty()), join2, ImmutableList.of(equiJoinClause(b1, e1)), ImmutableList.of(a1, b1, c1, d1, d2, e1, e2), Optional.empty());
MultiJoinNode expected = MultiJoinNode.builder().setSources(join1, join2, valuesC).setFilter(logicalRowExpressions.and(createEqualsExpression(a1, c1, p.getTypes()), createEqualsExpression(b1, e1, p.getTypes()))).setOutputSymbols(a1, b1, c1, d1, d2, e1, e2).setLogicalRowExpressions(logicalRowExpressions).build();
assertEquals(toMultiJoinNode(joinNode, noLookup(), 2, queryRunner.getMetadata(), p.getTypes(), logicalRowExpressions), expected);
}
use of io.prestosql.spi.plan.JoinNode in project hetu-core by openlookeng.
the class TestJoinNodeFlattener method testConvertsBushyTrees.
@Test
public void testConvertsBushyTrees() {
PlanBuilder p = planBuilder();
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, b1), Optional.empty()), valuesC, ImmutableList.of(equiJoinClause(a1, c1)), ImmutableList.of(a1, b1, c1), Optional.empty()), p.join(INNER, valuesD, valuesE, ImmutableList.of(equiJoinClause(d1, e1), equiJoinClause(d2, e2)), ImmutableList.of(d1, d2, e1, e2), Optional.empty()), ImmutableList.of(equiJoinClause(b1, e1)), ImmutableList.of(a1, b1, c1, d1, d2, e1, e2), Optional.empty());
MultiJoinNode expected = MultiJoinNode.builder().setSources(valuesA, valuesB, valuesC, valuesD, valuesE).setFilter(logicalRowExpressions.and(createEqualsExpression(a1, b1, p.getTypes()), createEqualsExpression(a1, c1, p.getTypes()), createEqualsExpression(d1, e1, p.getTypes()), createEqualsExpression(d2, e2, p.getTypes()), createEqualsExpression(b1, e1, p.getTypes()))).setOutputSymbols(a1, b1, c1, d1, d2, e1, e2).setLogicalRowExpressions(logicalRowExpressions).build();
assertEquals(toMultiJoinNode(joinNode, noLookup(), 5, queryRunner.getMetadata(), p.getTypes(), logicalRowExpressions), expected);
}
use of io.prestosql.spi.plan.JoinNode in project hetu-core by openlookeng.
the class TestJoinNodeFlattener method testRetainsOutputSymbols.
@Test
public void testRetainsOutputSymbols() {
PlanBuilder p = planBuilder();
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, c1, c2), Optional.empty()), ImmutableList.of(equiJoinClause(a1, b1)), ImmutableList.of(a1, b1), Optional.empty());
MultiJoinNode expected = MultiJoinNode.builder().setSources(valuesA, valuesB, valuesC).setFilter(logicalRowExpressions.and(createEqualsExpression(b1, c1, p.getTypes()), createEqualsExpression(a1, b1, p.getTypes()))).setOutputSymbols(a1, b1).setLogicalRowExpressions(logicalRowExpressions).build();
assertEquals(toMultiJoinNode(joinNode, noLookup(), DEFAULT_JOIN_LIMIT, queryRunner.getMetadata(), p.getTypes(), logicalRowExpressions), expected);
}
use of io.prestosql.spi.plan.JoinNode in project hetu-core by openlookeng.
the class TestJoinNodeFlattener method testDoesNotAllowOuterJoin.
@Test(expectedExceptions = IllegalStateException.class)
public void testDoesNotAllowOuterJoin() {
PlanBuilder p = planBuilder();
Symbol a1 = p.symbol("A1");
Symbol b1 = p.symbol("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, queryRunner.getMetadata(), p.getTypes(), logicalRowExpressions);
}
Aggregations