Search in sources :

Example 6 with SemiJoinNode

use of io.prestosql.sql.planner.plan.SemiJoinNode in project hetu-core by openlookeng.

the class DynamicFilterService method registerTasks.

/**
 * Registering tasks for global dynamic filters
 *
 * @param node the Join node from the logical plan
 * @param taskIds set of task Ids
 * @param workers set of workers
 * @param stateMachine the state machine
 */
public void registerTasks(PlanNode node, Set<TaskId> taskIds, Set<InternalNode> workers, StageStateMachine stateMachine) {
    if (taskIds.isEmpty() || stateStoreProvider.getStateStore() == null) {
        return;
    }
    if (node instanceof JoinNode) {
        JoinNode joinNode = (JoinNode) node;
        List<JoinNode.EquiJoinClause> criterias = joinNode.getCriteria();
        if (!criterias.isEmpty()) {
            registerTasksHelper(node, criterias.get(0).getRight(), joinNode.getDynamicFilters(), taskIds, workers, stateMachine);
        }
    } else if (node instanceof SemiJoinNode) {
        SemiJoinNode semiJoinNode = (SemiJoinNode) node;
        if (semiJoinNode.getDynamicFilterId().isPresent()) {
            registerTasksHelper(node, semiJoinNode.getFilteringSourceJoinSymbol(), Collections.singletonMap(semiJoinNode.getDynamicFilterId().get(), semiJoinNode.getFilteringSourceJoinSymbol()), taskIds, workers, stateMachine);
        }
    }
}
Also used : SemiJoinNode(io.prestosql.sql.planner.plan.SemiJoinNode) JoinNode(io.prestosql.spi.plan.JoinNode) SemiJoinNode(io.prestosql.sql.planner.plan.SemiJoinNode)

Example 7 with SemiJoinNode

use of io.prestosql.sql.planner.plan.SemiJoinNode in project hetu-core by openlookeng.

the class TestEffectivePredicateExtractor method testSemiJoin.

@Test
public void testSemiJoin() {
    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(), Optional.empty());
    Expression effectivePredicate = effectivePredicateExtractor.extract(SESSION, node, TypeProvider.empty(), typeAnalyzer);
    // Currently, only pull predicates through the source plan
    assertEquals(normalizeConjuncts(effectivePredicate), normalizeConjuncts(and(greaterThan(AE, bigintLiteral(10)), lessThan(AE, bigintLiteral(100)))));
}
Also used : PlanNode(io.prestosql.spi.plan.PlanNode) CallExpression(io.prestosql.spi.relation.CallExpression) OriginalExpressionUtils.castToRowExpression(io.prestosql.sql.relational.OriginalExpressionUtils.castToRowExpression) InListExpression(io.prestosql.sql.tree.InListExpression) ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) RowExpression(io.prestosql.spi.relation.RowExpression) Expression(io.prestosql.sql.tree.Expression) SemiJoinNode(io.prestosql.sql.planner.plan.SemiJoinNode) Test(org.testng.annotations.Test)

Example 8 with SemiJoinNode

use of io.prestosql.sql.planner.plan.SemiJoinNode in project hetu-core by openlookeng.

the class SimpleFilterProjectSemiJoinStatsRule method calculate.

private Optional<PlanNodeStatsEstimate> calculate(FilterNode filterNode, SemiJoinNode semiJoinNode, StatsProvider statsProvider, Session session, TypeProvider types) {
    PlanNodeStatsEstimate sourceStats = statsProvider.getStats(semiJoinNode.getSource());
    PlanNodeStatsEstimate filteringSourceStats = statsProvider.getStats(semiJoinNode.getFilteringSource());
    Symbol filteringSourceJoinSymbol = semiJoinNode.getFilteringSourceJoinSymbol();
    Symbol sourceJoinSymbol = semiJoinNode.getSourceJoinSymbol();
    Optional<SemiJoinOutputFilter> semiJoinOutputFilter;
    if (isExpression(filterNode.getPredicate())) {
        semiJoinOutputFilter = extractSemiJoinOutputFilter(castToExpression(filterNode.getPredicate()), semiJoinNode.getSemiJoinOutput());
    } else {
        VariableReferenceExpression semiJoinOutput = new VariableReferenceExpression(semiJoinNode.getSemiJoinOutput().getName(), types.get(semiJoinNode.getSemiJoinOutput()));
        semiJoinOutputFilter = extractSemiJoinOutputFilter(filterNode.getPredicate(), semiJoinOutput);
    }
    if (!semiJoinOutputFilter.isPresent()) {
        return Optional.empty();
    }
    PlanNodeStatsEstimate semiJoinStats;
    if (semiJoinOutputFilter.get().isNegated()) {
        semiJoinStats = computeAntiJoin(sourceStats, filteringSourceStats, sourceJoinSymbol, filteringSourceJoinSymbol);
    } else {
        semiJoinStats = computeSemiJoin(sourceStats, filteringSourceStats, sourceJoinSymbol, filteringSourceJoinSymbol);
    }
    if (semiJoinStats.isOutputRowCountUnknown()) {
        return Optional.of(PlanNodeStatsEstimate.unknown());
    }
    // apply remaining predicate
    PlanNodeStatsEstimate filteredStats;
    if (isExpression(filterNode.getPredicate())) {
        filteredStats = filterStatsCalculator.filterStats(semiJoinStats, castToExpression(semiJoinOutputFilter.get().getRemainingPredicate()), session, types);
    } else {
        Map<Integer, Symbol> layout = SymbolUtils.toLayOut(filterNode.getOutputSymbols());
        filteredStats = filterStatsCalculator.filterStats(semiJoinStats, semiJoinOutputFilter.get().getRemainingPredicate(), session, types, layout);
    }
    if (filteredStats.isOutputRowCountUnknown()) {
        return Optional.of(semiJoinStats.mapOutputRowCount(rowCount -> rowCount * UNKNOWN_FILTER_COEFFICIENT));
    }
    return Optional.of(filteredStats);
}
Also used : Iterables(com.google.common.collect.Iterables) Lookup(io.prestosql.sql.planner.iterative.Lookup) LogicalRowExpressions(io.prestosql.expressions.LogicalRowExpressions) TypeProvider(io.prestosql.sql.planner.TypeProvider) Pattern(io.prestosql.matching.Pattern) SemiJoinNode(io.prestosql.sql.planner.plan.SemiJoinNode) OriginalExpressionUtils.isExpression(io.prestosql.sql.relational.OriginalExpressionUtils.isExpression) CallExpression(io.prestosql.spi.relation.CallExpression) FilterNode(io.prestosql.spi.plan.FilterNode) Map(java.util.Map) OriginalExpressionUtils.castToRowExpression(io.prestosql.sql.relational.OriginalExpressionUtils.castToRowExpression) Objects.requireNonNull(java.util.Objects.requireNonNull) Session(io.prestosql.Session) OriginalExpressionUtils.castToExpression(io.prestosql.sql.relational.OriginalExpressionUtils.castToExpression) ProjectNodeUtils.isIdentity(io.prestosql.sql.relational.ProjectNodeUtils.isIdentity) Symbol(io.prestosql.spi.plan.Symbol) SymbolUtils(io.prestosql.sql.planner.SymbolUtils) NotExpression(io.prestosql.sql.tree.NotExpression) UNKNOWN_FILTER_COEFFICIENT(io.prestosql.cost.FilterStatsCalculator.UNKNOWN_FILTER_COEFFICIENT) RowExpressionDeterminismEvaluator(io.prestosql.sql.relational.RowExpressionDeterminismEvaluator) SemiJoinStatsCalculator.computeSemiJoin(io.prestosql.cost.SemiJoinStatsCalculator.computeSemiJoin) SemiJoinStatsCalculator.computeAntiJoin(io.prestosql.cost.SemiJoinStatsCalculator.computeAntiJoin) ExpressionUtils.combineConjuncts(io.prestosql.sql.ExpressionUtils.combineConjuncts) Patterns.filter(io.prestosql.sql.planner.plan.Patterns.filter) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) PlanNode(io.prestosql.spi.plan.PlanNode) VariableReferenceExpression(io.prestosql.spi.relation.VariableReferenceExpression) ProjectNode(io.prestosql.spi.plan.ProjectNode) Metadata(io.prestosql.metadata.Metadata) Preconditions.checkState(com.google.common.base.Preconditions.checkState) SymbolUtils.toSymbolReference(io.prestosql.sql.planner.SymbolUtils.toSymbolReference) List(java.util.List) FunctionResolution(io.prestosql.sql.relational.FunctionResolution) SymbolReference(io.prestosql.sql.tree.SymbolReference) RowExpression(io.prestosql.spi.relation.RowExpression) Optional(java.util.Optional) Expression(io.prestosql.sql.tree.Expression) ExpressionUtils.extractConjuncts(io.prestosql.sql.ExpressionUtils.extractConjuncts) Symbol(io.prestosql.spi.plan.Symbol) VariableReferenceExpression(io.prestosql.spi.relation.VariableReferenceExpression)

Example 9 with SemiJoinNode

use of io.prestosql.sql.planner.plan.SemiJoinNode in project hetu-core by openlookeng.

the class SimpleFilterProjectSemiJoinStatsRule method doCalculate.

@Override
protected Optional<PlanNodeStatsEstimate> doCalculate(FilterNode node, StatsProvider sourceStats, Lookup lookup, Session session, TypeProvider types) {
    PlanNode nodeSource = lookup.resolve(node.getSource());
    SemiJoinNode semiJoinNode;
    if (nodeSource instanceof ProjectNode) {
        ProjectNode projectNode = (ProjectNode) nodeSource;
        if (!isIdentity(projectNode)) {
            return Optional.empty();
        }
        PlanNode projectNodeSource = lookup.resolve(projectNode.getSource());
        if (!(projectNodeSource instanceof SemiJoinNode)) {
            return Optional.empty();
        }
        semiJoinNode = (SemiJoinNode) projectNodeSource;
    } else if (nodeSource instanceof SemiJoinNode) {
        semiJoinNode = (SemiJoinNode) nodeSource;
    } else {
        return Optional.empty();
    }
    return calculate(node, semiJoinNode, sourceStats, session, types);
}
Also used : PlanNode(io.prestosql.spi.plan.PlanNode) ProjectNode(io.prestosql.spi.plan.ProjectNode) SemiJoinNode(io.prestosql.sql.planner.plan.SemiJoinNode)

Aggregations

SemiJoinNode (io.prestosql.sql.planner.plan.SemiJoinNode)9 PlanNode (io.prestosql.spi.plan.PlanNode)7 Symbol (io.prestosql.spi.plan.Symbol)5 Session (io.prestosql.Session)4 FilterNode (io.prestosql.spi.plan.FilterNode)4 JoinNode (io.prestosql.spi.plan.JoinNode)4 RowExpression (io.prestosql.spi.relation.RowExpression)4 Preconditions.checkState (com.google.common.base.Preconditions.checkState)3 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)3 Metadata (io.prestosql.metadata.Metadata)3 ProjectNode (io.prestosql.spi.plan.ProjectNode)3 CallExpression (io.prestosql.spi.relation.CallExpression)3 VariableReferenceExpression (io.prestosql.spi.relation.VariableReferenceExpression)3 List (java.util.List)3 Optional (java.util.Optional)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 LogicalRowExpressions (io.prestosql.expressions.LogicalRowExpressions)2 Pattern (io.prestosql.matching.Pattern)2 SymbolUtils.toSymbolReference (io.prestosql.sql.planner.SymbolUtils.toSymbolReference)2 TypeProvider (io.prestosql.sql.planner.TypeProvider)2