Search in sources :

Example 26 with TypeProvider

use of io.prestosql.sql.planner.TypeProvider 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)

Aggregations

TypeProvider (io.prestosql.sql.planner.TypeProvider)26 Symbol (io.prestosql.spi.plan.Symbol)19 Optional (java.util.Optional)12 Session (io.prestosql.Session)11 PlanNode (io.prestosql.spi.plan.PlanNode)9 RowExpression (io.prestosql.spi.relation.RowExpression)9 Expression (io.prestosql.sql.tree.Expression)9 Map (java.util.Map)9 Metadata (io.prestosql.metadata.Metadata)8 List (java.util.List)8 Objects.requireNonNull (java.util.Objects.requireNonNull)8 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)7 OriginalExpressionUtils.castToExpression (io.prestosql.sql.relational.OriginalExpressionUtils.castToExpression)7 HashMap (java.util.HashMap)7 ImmutableList (com.google.common.collect.ImmutableList)6 Pattern (io.prestosql.matching.Pattern)6 FilterNode (io.prestosql.spi.plan.FilterNode)6 OriginalExpressionUtils.isExpression (io.prestosql.sql.relational.OriginalExpressionUtils.isExpression)6 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)5 ImmutableMap (com.google.common.collect.ImmutableMap)5