use of io.prestosql.spi.plan.JoinNode in project hetu-core by openlookeng.
the class TestEffectivePredicateExtractor method testRightJoinWithFalseInner.
@Test
public void testRightJoinWithFalseInner() {
List<JoinNode.EquiJoinClause> criteria = ImmutableList.of(new JoinNode.EquiJoinClause(A, D));
Map<Symbol, ColumnHandle> leftAssignments = Maps.filterKeys(scanAssignments, Predicates.in(ImmutableList.of(A, B, C)));
TableScanNode leftScan = tableScanNode(leftAssignments);
Map<Symbol, ColumnHandle> rightAssignments = Maps.filterKeys(scanAssignments, Predicates.in(ImmutableList.of(D, E, F)));
TableScanNode rightScan = tableScanNode(rightAssignments);
FilterNode left = filter(leftScan, FALSE_LITERAL);
FilterNode right = filter(rightScan, and(equals(DE, EE), lessThan(FE, bigintLiteral(100))));
PlanNode node = new JoinNode(newId(), JoinNode.Type.RIGHT, left, right, criteria, ImmutableList.<Symbol>builder().addAll(left.getOutputSymbols()).addAll(right.getOutputSymbols()).build(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), ImmutableMap.of());
Expression effectivePredicate = effectivePredicateExtractor.extract(SESSION, node, TypeProvider.empty(), typeAnalyzer);
// False literal on the left side should be ignored
assertEquals(normalizeConjuncts(effectivePredicate), normalizeConjunctsSet(equals(DE, EE), lessThan(FE, bigintLiteral(100)), or(equals(AE, DE), isNull(AE))));
}
use of io.prestosql.spi.plan.JoinNode in project hetu-core by openlookeng.
the class TestEffectivePredicateExtractor method testLeftJoin.
@Test
public void testLeftJoin() {
ImmutableList.Builder<JoinNode.EquiJoinClause> criteriaBuilder = ImmutableList.builder();
criteriaBuilder.add(new JoinNode.EquiJoinClause(A, D));
criteriaBuilder.add(new JoinNode.EquiJoinClause(B, E));
List<JoinNode.EquiJoinClause> criteria = criteriaBuilder.build();
Map<Symbol, ColumnHandle> leftAssignments = Maps.filterKeys(scanAssignments, Predicates.in(ImmutableList.of(A, B, C)));
TableScanNode leftScan = tableScanNode(leftAssignments);
Map<Symbol, ColumnHandle> rightAssignments = Maps.filterKeys(scanAssignments, Predicates.in(ImmutableList.of(D, E, F)));
TableScanNode rightScan = tableScanNode(rightAssignments);
FilterNode left = filter(leftScan, and(lessThan(BE, AE), lessThan(CE, bigintLiteral(10)), equals(GE, bigintLiteral(10))));
FilterNode right = filter(rightScan, and(equals(DE, EE), lessThan(FE, bigintLiteral(100))));
PlanNode node = new JoinNode(newId(), JoinNode.Type.LEFT, left, right, criteria, ImmutableList.<Symbol>builder().addAll(left.getOutputSymbols()).addAll(right.getOutputSymbols()).build(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), ImmutableMap.of());
Expression effectivePredicate = effectivePredicateExtractor.extract(SESSION, node, TypeProvider.empty(), typeAnalyzer);
// All right side symbols having output symbols should be checked against NULL
assertEquals(normalizeConjuncts(effectivePredicate), normalizeConjunctsSet(lessThan(BE, AE), lessThan(CE, bigintLiteral(10)), or(equals(DE, EE), and(isNull(DE), isNull(EE))), or(lessThan(FE, bigintLiteral(100)), isNull(FE)), or(equals(AE, DE), isNull(DE)), or(equals(BE, EE), isNull(EE))));
}
use of io.prestosql.spi.plan.JoinNode in project hetu-core by openlookeng.
the class TestEffectivePredicateExtractor method testRightJoin.
@Test
public void testRightJoin() {
ImmutableList.Builder<JoinNode.EquiJoinClause> criteriaBuilder = ImmutableList.builder();
criteriaBuilder.add(new JoinNode.EquiJoinClause(A, D));
criteriaBuilder.add(new JoinNode.EquiJoinClause(B, E));
List<JoinNode.EquiJoinClause> criteria = criteriaBuilder.build();
Map<Symbol, ColumnHandle> leftAssignments = Maps.filterKeys(scanAssignments, Predicates.in(ImmutableList.of(A, B, C)));
TableScanNode leftScan = tableScanNode(leftAssignments);
Map<Symbol, ColumnHandle> rightAssignments = Maps.filterKeys(scanAssignments, Predicates.in(ImmutableList.of(D, E, F)));
TableScanNode rightScan = tableScanNode(rightAssignments);
FilterNode left = filter(leftScan, and(lessThan(BE, AE), lessThan(CE, bigintLiteral(10)), equals(GE, bigintLiteral(10))));
FilterNode right = filter(rightScan, and(equals(DE, EE), lessThan(FE, bigintLiteral(100))));
PlanNode node = new JoinNode(newId(), JoinNode.Type.RIGHT, left, right, criteria, ImmutableList.<Symbol>builder().addAll(left.getOutputSymbols()).addAll(right.getOutputSymbols()).build(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), ImmutableMap.of());
Expression effectivePredicate = effectivePredicateExtractor.extract(SESSION, node, TypeProvider.empty(), typeAnalyzer);
// All left side symbols should be checked against NULL
assertEquals(normalizeConjuncts(effectivePredicate), normalizeConjunctsSet(or(lessThan(BE, AE), and(isNull(BE), isNull(AE))), or(lessThan(CE, bigintLiteral(10)), isNull(CE)), equals(DE, EE), lessThan(FE, bigintLiteral(100)), or(equals(AE, DE), isNull(AE)), or(equals(BE, EE), isNull(BE))));
}
use of io.prestosql.spi.plan.JoinNode in project hetu-core by openlookeng.
the class TestEffectivePredicateExtractor method testInnerJoinPropagatesPredicatesViaEquiConditions.
@Test
public void testInnerJoinPropagatesPredicatesViaEquiConditions() {
Map<Symbol, ColumnHandle> leftAssignments = Maps.filterKeys(scanAssignments, Predicates.in(ImmutableList.of(A, B, C)));
TableScanNode leftScan = tableScanNode(leftAssignments);
Map<Symbol, ColumnHandle> rightAssignments = Maps.filterKeys(scanAssignments, Predicates.in(ImmutableList.of(D, E, F)));
TableScanNode rightScan = tableScanNode(rightAssignments);
FilterNode left = filter(leftScan, equals(AE, bigintLiteral(10)));
// predicates on "a" column should be propagated to output symbols via join equi conditions
PlanNode node = new JoinNode(newId(), JoinNode.Type.INNER, left, rightScan, ImmutableList.of(new JoinNode.EquiJoinClause(A, D)), ImmutableList.<Symbol>builder().addAll(rightScan.getOutputSymbols()).build(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), ImmutableMap.of());
Expression effectivePredicate = effectivePredicateExtractor.extract(SESSION, node, TypeProvider.empty(), typeAnalyzer);
assertEquals(normalizeConjuncts(effectivePredicate), normalizeConjuncts(equals(DE, bigintLiteral(10))));
}
use of io.prestosql.spi.plan.JoinNode in project hetu-core by openlookeng.
the class JoinStatsRule method computeInnerJoinStats.
private PlanNodeStatsEstimate computeInnerJoinStats(JoinNode node, PlanNodeStatsEstimate crossJoinStats, Session session, TypeProvider types) {
List<EquiJoinClause> equiJoinCriteria = node.getCriteria();
Map<Integer, Symbol> layout = new HashMap<>();
int channel = 0;
for (Symbol symbol : node.getOutputSymbols()) {
layout.put(channel++, symbol);
}
if (equiJoinCriteria.isEmpty()) {
if (!node.getFilter().isPresent()) {
return crossJoinStats;
}
// TODO: this might explode stats
if (isExpression(node.getFilter().get())) {
return filterStatsCalculator.filterStats(crossJoinStats, castToExpression(node.getFilter().get()), session, types);
} else {
return filterStatsCalculator.filterStats(crossJoinStats, node.getFilter().get(), session, types, layout);
}
}
PlanNodeStatsEstimate equiJoinEstimate = filterByEquiJoinClauses(crossJoinStats, node.getCriteria(), session, types);
if (equiJoinEstimate.isOutputRowCountUnknown()) {
return PlanNodeStatsEstimate.unknown();
}
if (!node.getFilter().isPresent()) {
return equiJoinEstimate;
}
PlanNodeStatsEstimate filteredEquiJoinEstimate;
if (isExpression(node.getFilter().get())) {
filteredEquiJoinEstimate = filterStatsCalculator.filterStats(equiJoinEstimate, castToExpression(node.getFilter().get()), session, types);
} else {
filteredEquiJoinEstimate = filterStatsCalculator.filterStats(equiJoinEstimate, node.getFilter().get(), session, types, layout);
}
if (filteredEquiJoinEstimate.isOutputRowCountUnknown()) {
return normalizer.normalize(equiJoinEstimate.mapOutputRowCount(rowCount -> rowCount * UNKNOWN_FILTER_COEFFICIENT), types);
}
return filteredEquiJoinEstimate;
}
Aggregations