use of com.facebook.presto.spi.plan.FilterNode in project presto by prestodb.
the class TestEffectivePredicateExtractor method testInnerJoin.
@Test
public void testInnerJoin() {
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.INNER, left, right, criteria, ImmutableList.<VariableReferenceExpression>builder().addAll(left.getOutputVariables()).addAll(right.getOutputVariables()).build(), Optional.of(lessThanOrEqual(BV, EV)), Optional.empty(), Optional.empty(), Optional.empty(), ImmutableMap.of());
RowExpression effectivePredicate = effectivePredicateExtractor.extract(node);
// All predicates having output symbol should be carried through
assertEquals(normalizeConjuncts(effectivePredicate), normalizeConjuncts(lessThan(BV, AV), lessThan(CV, bigintLiteral(10)), equals(DV, EV), lessThan(FV, bigintLiteral(100)), equals(AV, DV), equals(BV, EV), lessThanOrEqual(BV, EV)));
}
use of com.facebook.presto.spi.plan.FilterNode in project presto by prestodb.
the class TestHiveDistributedJoinQueriesWithDynamicFiltering method searchScanFilterAndProjectOperatorStats.
private OperatorStats searchScanFilterAndProjectOperatorStats(QueryId queryId, String tableName) {
DistributedQueryRunner runner = (DistributedQueryRunner) getQueryRunner();
Plan plan = runner.getQueryPlan(queryId);
PlanNodeId nodeId = PlanNodeSearcher.searchFrom(plan.getRoot()).where(node -> {
if (!(node instanceof ProjectNode)) {
return false;
}
ProjectNode projectNode = (ProjectNode) node;
FilterNode filterNode = (FilterNode) projectNode.getSource();
TableScanNode tableScanNode = (TableScanNode) filterNode.getSource();
return tableName.equals(((HiveTableHandle) (tableScanNode.getTable().getConnectorHandle())).getTableName());
}).findOnlyElement().getId();
return runner.getCoordinator().getQueryManager().getFullQueryInfo(queryId).getQueryStats().getOperatorSummaries().stream().filter(summary -> nodeId.equals(summary.getPlanNodeId())).collect(MoreCollectors.onlyElement());
}
use of com.facebook.presto.spi.plan.FilterNode in project presto by prestodb.
the class QueryPlanner method filter.
private PlanBuilder filter(PlanBuilder subPlan, Expression predicate, Node node) {
if (predicate == null) {
return subPlan;
}
// rewrite expressions which contain already handled subqueries
Expression rewrittenBeforeSubqueries = subPlan.rewrite(predicate);
subPlan = subqueryPlanner.handleSubqueries(subPlan, rewrittenBeforeSubqueries, node);
Expression rewrittenAfterSubqueries = subPlan.rewrite(predicate);
return subPlan.withNewRoot(new FilterNode(getSourceLocation(node), idAllocator.getNextId(), subPlan.getRoot(), castToRowExpression(rewrittenAfterSubqueries)));
}
use of com.facebook.presto.spi.plan.FilterNode in project presto by prestodb.
the class DynamicFilterMatcher method match.
private boolean match() {
checkState(symbolAliases != null, "symbolAliases is null");
// both nodes must be provided to do the matching
if (filterNode == null || joinNode == null) {
return true;
}
Map<String, VariableReferenceExpression> idToProbeSymbolMap = extractDynamicFilters(filterNode.getPredicate()).getDynamicConjuncts().stream().collect(toImmutableMap(DynamicFilters.DynamicFilterPlaceholder::getId, filter -> (VariableReferenceExpression) filter.getInput()));
Map<String, VariableReferenceExpression> idToBuildSymbolMap = joinNode.getDynamicFilters();
if (idToProbeSymbolMap == null) {
return false;
}
if (idToProbeSymbolMap.size() != expectedDynamicFilters.size()) {
return false;
}
Map<Symbol, Symbol> actual = new HashMap<>();
for (Map.Entry<String, VariableReferenceExpression> idToProbeSymbol : idToProbeSymbolMap.entrySet()) {
String id = idToProbeSymbol.getKey();
VariableReferenceExpression probe = idToProbeSymbol.getValue();
VariableReferenceExpression build = idToBuildSymbolMap.get(id);
if (build == null) {
return false;
}
actual.put(new Symbol(probe.getName()), new Symbol(build.getName()));
}
Map<Symbol, Symbol> expected = expectedDynamicFilters.entrySet().stream().collect(toImmutableMap(entry -> entry.getKey().toSymbol(symbolAliases), entry -> entry.getValue().toSymbol(symbolAliases)));
return expected.equals(actual);
}
use of com.facebook.presto.spi.plan.FilterNode in project presto by prestodb.
the class FilterMatcher 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());
FilterNode filterNode = (FilterNode) node;
if (isExpression(filterNode.getPredicate())) {
ExpressionVerifier verifier = new ExpressionVerifier(symbolAliases);
return new MatchResult(verifier.process(castToExpression(filterNode.getPredicate()), predicate));
}
RowExpressionVerifier verifier = new RowExpressionVerifier(symbolAliases, metadata, session);
return new MatchResult(verifier.process(predicate, filterNode.getPredicate()));
}
Aggregations