Search in sources :

Example 6 with FilterNode

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)));
}
Also used : ColumnHandle(com.facebook.presto.spi.ColumnHandle) ImmutableList(com.google.common.collect.ImmutableList) JoinNode(com.facebook.presto.sql.planner.plan.JoinNode) SemiJoinNode(com.facebook.presto.sql.planner.plan.SemiJoinNode) FilterNode(com.facebook.presto.spi.plan.FilterNode) RowExpression(com.facebook.presto.spi.relation.RowExpression) PlanNode(com.facebook.presto.spi.plan.PlanNode) TableScanNode(com.facebook.presto.spi.plan.TableScanNode) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) Test(org.testng.annotations.Test)

Example 7 with FilterNode

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());
}
Also used : PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) AbstractTestJoinQueries(com.facebook.presto.tests.AbstractTestJoinQueries) Assert.assertEquals(org.testng.Assert.assertEquals) QueryRunner(com.facebook.presto.testing.QueryRunner) Test(org.testng.annotations.Test) DistributedQueryRunner(com.facebook.presto.tests.DistributedQueryRunner) OperatorStats(com.facebook.presto.operator.OperatorStats) ENABLE_DYNAMIC_FILTERING(com.facebook.presto.SystemSessionProperties.ENABLE_DYNAMIC_FILTERING) FilterNode(com.facebook.presto.spi.plan.FilterNode) ResultWithQueryId(com.facebook.presto.tests.ResultWithQueryId) Plan(com.facebook.presto.sql.planner.Plan) PUSHDOWN_SUBFIELDS_ENABLED(com.facebook.presto.SystemSessionProperties.PUSHDOWN_SUBFIELDS_ENABLED) HIVE_CATALOG(com.facebook.presto.hive.HiveQueryRunner.HIVE_CATALOG) Session(com.facebook.presto.Session) MoreCollectors(com.google.common.collect.MoreCollectors) PlanNodeSearcher(com.facebook.presto.sql.planner.optimizations.PlanNodeSearcher) JOIN_DISTRIBUTION_TYPE(com.facebook.presto.SystemSessionProperties.JOIN_DISTRIBUTION_TYPE) FeaturesConfig(com.facebook.presto.sql.analyzer.FeaturesConfig) TpchTable.getTables(io.airlift.tpch.TpchTable.getTables) MaterializedResult(com.facebook.presto.testing.MaterializedResult) ProjectNode(com.facebook.presto.spi.plan.ProjectNode) JOIN_REORDERING_STRATEGY(com.facebook.presto.SystemSessionProperties.JOIN_REORDERING_STRATEGY) PUSHDOWN_FILTER_ENABLED(com.facebook.presto.hive.HiveSessionProperties.PUSHDOWN_FILTER_ENABLED) TableScanNode(com.facebook.presto.spi.plan.TableScanNode) Assertions.assertLessThanOrEqual(com.facebook.airlift.testing.Assertions.assertLessThanOrEqual) QueryId(com.facebook.presto.spi.QueryId) Assertions.assertGreaterThan(com.facebook.airlift.testing.Assertions.assertGreaterThan) BROADCAST(com.facebook.presto.sql.analyzer.FeaturesConfig.JoinDistributionType.BROADCAST) DistributedQueryRunner(com.facebook.presto.tests.DistributedQueryRunner) TableScanNode(com.facebook.presto.spi.plan.TableScanNode) FilterNode(com.facebook.presto.spi.plan.FilterNode) ProjectNode(com.facebook.presto.spi.plan.ProjectNode) Plan(com.facebook.presto.sql.planner.Plan)

Example 8 with FilterNode

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)));
}
Also used : VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) CallExpression(com.facebook.presto.spi.relation.CallExpression) LambdaExpression(com.facebook.presto.sql.tree.LambdaExpression) RowExpression(com.facebook.presto.spi.relation.RowExpression) Expression(com.facebook.presto.sql.tree.Expression) OriginalExpressionUtils.castToRowExpression(com.facebook.presto.sql.relational.OriginalExpressionUtils.castToRowExpression) FilterNode(com.facebook.presto.spi.plan.FilterNode)

Example 9 with FilterNode

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);
}
Also used : RowExpression(com.facebook.presto.spi.relation.RowExpression) JoinNode(com.facebook.presto.sql.planner.plan.JoinNode) Session(com.facebook.presto.Session) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) StatsProvider(com.facebook.presto.cost.StatsProvider) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) HashMap(java.util.HashMap) RowExpressionDeterminismEvaluator(com.facebook.presto.sql.relational.RowExpressionDeterminismEvaluator) Preconditions.checkState(com.google.common.base.Preconditions.checkState) FilterNode(com.facebook.presto.spi.plan.FilterNode) PlanNode(com.facebook.presto.spi.plan.PlanNode) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) Expression(com.facebook.presto.sql.tree.Expression) LogicalRowExpressions(com.facebook.presto.expressions.LogicalRowExpressions) Symbol(com.facebook.presto.sql.planner.Symbol) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) Optional(java.util.Optional) FunctionResolution(com.facebook.presto.sql.relational.FunctionResolution) DynamicFilters(com.facebook.presto.expressions.DynamicFilters) Metadata(com.facebook.presto.metadata.Metadata) Joiner(com.google.common.base.Joiner) DynamicFilters.extractDynamicFilters(com.facebook.presto.expressions.DynamicFilters.extractDynamicFilters) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) DynamicFilters(com.facebook.presto.expressions.DynamicFilters) DynamicFilters.extractDynamicFilters(com.facebook.presto.expressions.DynamicFilters.extractDynamicFilters) HashMap(java.util.HashMap) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) Symbol(com.facebook.presto.sql.planner.Symbol) HashMap(java.util.HashMap) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) Map(java.util.Map)

Example 10 with FilterNode

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()));
}
Also used : FilterNode(com.facebook.presto.spi.plan.FilterNode)

Aggregations

FilterNode (com.facebook.presto.spi.plan.FilterNode)31 PlanNode (com.facebook.presto.spi.plan.PlanNode)22 VariableReferenceExpression (com.facebook.presto.spi.relation.VariableReferenceExpression)19 Test (org.testng.annotations.Test)16 RowExpression (com.facebook.presto.spi.relation.RowExpression)15 TableScanNode (com.facebook.presto.spi.plan.TableScanNode)11 ProjectNode (com.facebook.presto.spi.plan.ProjectNode)10 JoinNode (com.facebook.presto.sql.planner.plan.JoinNode)10 ImmutableList (com.google.common.collect.ImmutableList)8 ColumnHandle (com.facebook.presto.spi.ColumnHandle)7 PlanBuilder (com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder)7 SemiJoinNode (com.facebook.presto.sql.planner.plan.SemiJoinNode)7 Expression (com.facebook.presto.sql.tree.Expression)7 Session (com.facebook.presto.Session)6 OriginalExpressionUtils.castToRowExpression (com.facebook.presto.sql.relational.OriginalExpressionUtils.castToRowExpression)5 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)5 Map (java.util.Map)5 Objects.requireNonNull (java.util.Objects.requireNonNull)5 Optional (java.util.Optional)5 LogicalRowExpressions (com.facebook.presto.expressions.LogicalRowExpressions)4