use of com.facebook.presto.sql.tree.Expression in project presto by prestodb.
the class OutputMatcher method detailMatches.
@Override
public MatchResult detailMatches(PlanNode node, Session session, Metadata metadata, SymbolAliases symbolAliases) {
int i = 0;
for (String alias : aliases) {
Expression expression = symbolAliases.get(alias);
boolean found = false;
while (i < node.getOutputSymbols().size()) {
Symbol outputSymbol = node.getOutputSymbols().get(i++);
if (expression.equals(outputSymbol.toSymbolReference())) {
found = true;
break;
}
}
if (!found) {
return NO_MATCH;
}
}
return match();
}
use of com.facebook.presto.sql.tree.Expression in project presto by prestodb.
the class TestEffectivePredicateExtractor method testSemiJoin.
@Test
public void testSemiJoin() throws Exception {
PlanNode node = new SemiJoinNode(newId(), filter(baseTableScan, and(greaterThan(AE, bigintLiteral(10)), lessThan(AE, bigintLiteral(100)))), filter(baseTableScan, greaterThan(AE, bigintLiteral(5))), A, B, C, Optional.empty(), Optional.empty(), Optional.empty());
Expression effectivePredicate = EffectivePredicateExtractor.extract(node, TYPES);
// Currently, only pull predicates through the source plan
assertEquals(normalizeConjuncts(effectivePredicate), normalizeConjuncts(and(greaterThan(AE, bigintLiteral(10)), lessThan(AE, bigintLiteral(100)))));
}
use of com.facebook.presto.sql.tree.Expression in project presto by prestodb.
the class TestEffectivePredicateExtractor method testWindow.
@Test
public void testWindow() throws Exception {
PlanNode node = new WindowNode(newId(), filter(baseTableScan, and(equals(AE, BE), equals(BE, CE), lessThan(CE, bigintLiteral(10)))), new WindowNode.Specification(ImmutableList.of(A), ImmutableList.of(A), ImmutableMap.of(A, SortOrder.ASC_NULLS_LAST)), ImmutableMap.of(), Optional.empty(), ImmutableSet.of(), 0);
Expression effectivePredicate = EffectivePredicateExtractor.extract(node, TYPES);
// Pass through
assertEquals(normalizeConjuncts(effectivePredicate), normalizeConjuncts(equals(AE, BE), equals(BE, CE), lessThan(CE, bigintLiteral(10))));
}
use of com.facebook.presto.sql.tree.Expression in project presto by prestodb.
the class TestEffectivePredicateExtractor method testLeftJoin.
@Test
public void testLeftJoin() throws Exception {
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 = new TableScanNode(newId(), DUAL_TABLE_HANDLE, ImmutableList.copyOf(leftAssignments.keySet()), leftAssignments, Optional.empty(), TupleDomain.all(), null);
Map<Symbol, ColumnHandle> rightAssignments = Maps.filterKeys(scanAssignments, Predicates.in(ImmutableList.of(D, E, F)));
TableScanNode rightScan = new TableScanNode(newId(), DUAL_TABLE_HANDLE, ImmutableList.copyOf(rightAssignments.keySet()), rightAssignments, Optional.empty(), TupleDomain.all(), null);
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());
Expression effectivePredicate = EffectivePredicateExtractor.extract(node, TYPES);
// All right side symbols having output symbols should be checked against NULL
assertEquals(normalizeConjuncts(effectivePredicate), normalizeConjuncts(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 com.facebook.presto.sql.tree.Expression in project presto by prestodb.
the class TestEffectivePredicateExtractor method testFilter.
@Test
public void testFilter() throws Exception {
PlanNode node = filter(baseTableScan, and(greaterThan(AE, new FunctionCall(QualifiedName.of("rand"), ImmutableList.of())), lessThan(BE, bigintLiteral(10))));
Expression effectivePredicate = EffectivePredicateExtractor.extract(node, TYPES);
// Non-deterministic functions should be purged
assertEquals(normalizeConjuncts(effectivePredicate), normalizeConjuncts(lessThan(BE, bigintLiteral(10))));
}
Aggregations