use of com.facebook.presto.spi.relation.RowExpression in project presto by prestodb.
the class TestEffectivePredicateExtractor method testSemiJoin.
@Test
public void testSemiJoin() {
PlanNode node = new SemiJoinNode(Optional.empty(), newId(), filter(baseTableScan, and(greaterThan(AV, bigintLiteral(10)), lessThan(AV, bigintLiteral(100)))), filter(baseTableScan, greaterThan(AV, bigintLiteral(5))), AV, BV, CV, Optional.empty(), Optional.empty(), Optional.empty(), ImmutableMap.of());
RowExpression effectivePredicate = effectivePredicateExtractor.extract(node);
// Currently, only pull predicates through the source plan
assertEquals(normalizeConjuncts(effectivePredicate), normalizeConjuncts(and(greaterThan(AV, bigintLiteral(10)), lessThan(AV, bigintLiteral(100)))));
}
use of com.facebook.presto.spi.relation.RowExpression in project presto by prestodb.
the class TestEffectivePredicateExtractor method testUnion.
@Test
public void testUnion() {
PlanNode node = new UnionNode(Optional.empty(), newId(), ImmutableList.of(filter(baseTableScan, greaterThan(AV, bigintLiteral(10))), filter(baseTableScan, and(greaterThan(AV, bigintLiteral(10)), lessThan(AV, bigintLiteral(100)))), filter(baseTableScan, and(greaterThan(AV, bigintLiteral(10)), lessThan(AV, bigintLiteral(100))))), ImmutableList.of(AV), ImmutableMap.of(AV, ImmutableList.of(BV, CV, EV)));
RowExpression effectivePredicate = effectivePredicateExtractor.extract(node);
// Only the common conjuncts can be inferred through a Union
assertEquals(normalizeConjuncts(effectivePredicate), normalizeConjuncts(greaterThan(AV, bigintLiteral(10))));
}
use of com.facebook.presto.spi.relation.RowExpression in project presto by prestodb.
the class TestEffectivePredicateExtractor method testTableScan.
@Test
public void testTableScan() {
// Effective predicate is True if there is no effective predicate
Map<VariableReferenceExpression, ColumnHandle> assignments = Maps.filterKeys(scanAssignments, Predicates.in(ImmutableList.of(AV, BV, CV, DV)));
PlanNode node = new TableScanNode(Optional.empty(), newId(), DUAL_TABLE_HANDLE, ImmutableList.copyOf(assignments.keySet()), assignments, TupleDomain.all(), TupleDomain.all());
RowExpression effectivePredicate = effectivePredicateExtractor.extract(node);
assertEquals(effectivePredicate, TRUE_CONSTANT);
node = new TableScanNode(Optional.empty(), newId(), DUAL_TABLE_HANDLE_WITH_LAYOUT, ImmutableList.copyOf(assignments.keySet()), assignments, TupleDomain.none(), TupleDomain.all());
effectivePredicate = effectivePredicateExtractor.extract(node);
assertEquals(effectivePredicate, FALSE_CONSTANT);
node = new TableScanNode(Optional.empty(), newId(), DUAL_TABLE_HANDLE_WITH_LAYOUT, ImmutableList.copyOf(assignments.keySet()), assignments, TupleDomain.withColumnDomains(ImmutableMap.of(scanAssignments.get(AV), Domain.singleValue(BIGINT, 1L))), TupleDomain.all());
effectivePredicate = effectivePredicateExtractor.extract(node);
assertEquals(normalizeConjuncts(effectivePredicate), normalizeConjuncts(equals(bigintLiteral(1L), AV)));
node = new TableScanNode(Optional.empty(), newId(), DUAL_TABLE_HANDLE_WITH_LAYOUT, ImmutableList.copyOf(assignments.keySet()), assignments, TupleDomain.withColumnDomains(ImmutableMap.of(scanAssignments.get(AV), Domain.singleValue(BIGINT, 1L), scanAssignments.get(BV), Domain.singleValue(BIGINT, 2L))), TupleDomain.all());
effectivePredicate = effectivePredicateExtractor.extract(node);
assertEquals(normalizeConjuncts(effectivePredicate), normalizeConjuncts(equals(bigintLiteral(2L), BV), equals(bigintLiteral(1L), AV)));
node = new TableScanNode(Optional.empty(), newId(), DUAL_TABLE_HANDLE, ImmutableList.copyOf(assignments.keySet()), assignments, TupleDomain.all(), TupleDomain.all());
effectivePredicate = effectivePredicateExtractor.extract(node);
assertEquals(effectivePredicate, TRUE_CONSTANT);
}
use of com.facebook.presto.spi.relation.RowExpression in project presto by prestodb.
the class TestEffectivePredicateExtractor method testProject.
@Test
public void testProject() {
PlanNode node = new ProjectNode(newId(), filter(baseTableScan, and(equals(AV, BV), equals(BV, CV), lessThan(CV, bigintLiteral(10)))), assignment(DV, AV, EV, CV));
RowExpression effectivePredicate = effectivePredicateExtractor.extract(node);
// Rewrite in terms of project output symbols
assertEquals(normalizeConjuncts(effectivePredicate), normalizeConjuncts(lessThan(DV, bigintLiteral(10)), equals(DV, EV)));
}
use of com.facebook.presto.spi.relation.RowExpression in project presto by prestodb.
the class TestEffectivePredicateExtractor method testLeftJoin.
@Test
public void testLeftJoin() {
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.LEFT, 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 right side symbols having output symbols should be checked against NULL
assertEquals(normalizeConjuncts(effectivePredicate), normalizeConjuncts(lessThan(BV, AV), lessThan(CV, bigintLiteral(10)), or(equals(DV, EV), and(isNull(DV), isNull(EV))), or(lessThan(FV, bigintLiteral(100)), isNull(FV)), or(equals(AV, DV), isNull(DV)), or(equals(BV, EV), isNull(EV))));
}
Aggregations