Search in sources :

Example 6 with StatsProvider

use of io.prestosql.cost.StatsProvider in project hetu-core by openlookeng.

the class MarkDistinctMatcher 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());
    MarkDistinctNode markDistinctNode = (MarkDistinctNode) node;
    if (!markDistinctNode.getHashSymbol().equals(hashSymbol.map(alias -> alias.toSymbol(symbolAliases)))) {
        return NO_MATCH;
    }
    if (!ImmutableSet.copyOf(markDistinctNode.getDistinctSymbols()).equals(distinctSymbols.stream().map(alias -> alias.toSymbol(symbolAliases)).collect(toImmutableSet()))) {
        return NO_MATCH;
    }
    return match(markerSymbol.toString(), toSymbolReference(markDistinctNode.getMarkerSymbol()));
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) StatsProvider(io.prestosql.cost.StatsProvider) MatchResult.match(io.prestosql.sql.planner.assertions.MatchResult.match) PlanNode(io.prestosql.spi.plan.PlanNode) 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) ImmutableList(com.google.common.collect.ImmutableList) Objects.requireNonNull(java.util.Objects.requireNonNull) Session(io.prestosql.Session) Optional(java.util.Optional) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) NO_MATCH(io.prestosql.sql.planner.assertions.MatchResult.NO_MATCH) MarkDistinctNode(io.prestosql.spi.plan.MarkDistinctNode) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) MarkDistinctNode(io.prestosql.spi.plan.MarkDistinctNode)

Example 7 with StatsProvider

use of io.prestosql.cost.StatsProvider in project hetu-core by openlookeng.

the class RowNumberMatcher 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());
    RowNumberNode rowNumberNode = (RowNumberNode) node;
    if (partitionBy.isPresent()) {
        List<Symbol> expected = partitionBy.get().stream().map(alias -> alias.toSymbol(symbolAliases)).collect(toImmutableList());
        if (!expected.equals(rowNumberNode.getPartitionBy())) {
            return NO_MATCH;
        }
    }
    if (rowNumberSymbol.isPresent()) {
        Symbol expected = rowNumberSymbol.get().toSymbol(symbolAliases);
        if (!expected.equals(rowNumberNode.getRowNumberSymbol())) {
            return NO_MATCH;
        }
    }
    if (maxRowCountPerPartition.isPresent()) {
        if (!maxRowCountPerPartition.get().equals(rowNumberNode.getMaxRowCountPerPartition())) {
            return NO_MATCH;
        }
    }
    if (hashSymbol.isPresent()) {
        Optional<Symbol> expected = hashSymbol.get().map(alias -> alias.toSymbol(symbolAliases));
        if (!expected.equals(rowNumberNode.getHashSymbol())) {
            return NO_MATCH;
        }
    }
    return match();
}
Also used : Symbol(io.prestosql.spi.plan.Symbol) StatsProvider(io.prestosql.cost.StatsProvider) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) MatchResult.match(io.prestosql.sql.planner.assertions.MatchResult.match) PlanNode(io.prestosql.spi.plan.PlanNode) Metadata(io.prestosql.metadata.Metadata) RowNumberNode(io.prestosql.sql.planner.plan.RowNumberNode) Preconditions.checkState(com.google.common.base.Preconditions.checkState) List(java.util.List) Objects.requireNonNull(java.util.Objects.requireNonNull) Session(io.prestosql.Session) Optional(java.util.Optional) PlanMatchPattern.node(io.prestosql.sql.planner.assertions.PlanMatchPattern.node) NO_MATCH(io.prestosql.sql.planner.assertions.MatchResult.NO_MATCH) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) Symbol(io.prestosql.spi.plan.Symbol) RowNumberNode(io.prestosql.sql.planner.plan.RowNumberNode)

Example 8 with StatsProvider

use of io.prestosql.cost.StatsProvider in project hetu-core by openlookeng.

the class SemiJoinMatcher 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());
    SemiJoinNode semiJoinNode = (SemiJoinNode) node;
    if (!(symbolAliases.get(sourceSymbolAlias).equals(toSymbolReference(semiJoinNode.getSourceJoinSymbol())) && symbolAliases.get(filteringSymbolAlias).equals(toSymbolReference(semiJoinNode.getFilteringSourceJoinSymbol())))) {
        return NO_MATCH;
    }
    if (distributionType.isPresent() && !distributionType.equals(semiJoinNode.getDistributionType())) {
        return NO_MATCH;
    }
    if (hasDynamicFilter.isPresent()) {
        if (hasDynamicFilter.get()) {
            if (!semiJoinNode.getDynamicFilterId().isPresent()) {
                return NO_MATCH;
            }
            String dynamicFilterId = semiJoinNode.getDynamicFilterId().get();
            List<DynamicFilters.Descriptor> matchingDescriptors = searchFrom(semiJoinNode.getSource()).where(FilterNode.class::isInstance).findAll().stream().flatMap(filterNode -> extractExpressions(filterNode).stream()).flatMap(expression -> extractDynamicFilters(expression).getDynamicConjuncts().stream()).filter(descriptor -> descriptor.getId().equals(dynamicFilterId)).collect(toImmutableList());
            boolean sourceSymbolsMatch = matchingDescriptors.stream().map(descriptor -> new Symbol(((VariableReferenceExpression) descriptor.getInput()).getName())).allMatch(sourceSymbol -> symbolAliases.get(sourceSymbolAlias).equals(toSymbolReference(sourceSymbol)));
            if (!matchingDescriptors.isEmpty() && sourceSymbolsMatch) {
                return match(outputAlias, toSymbolReference(semiJoinNode.getSemiJoinOutput()));
            }
            return NO_MATCH;
        }
        if (semiJoinNode.getDynamicFilterId().isPresent()) {
            return NO_MATCH;
        }
    }
    return match(outputAlias, toSymbolReference(semiJoinNode.getSemiJoinOutput()));
}
Also used : Symbol(io.prestosql.spi.plan.Symbol) StatsProvider(io.prestosql.cost.StatsProvider) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) DynamicFilters.extractDynamicFilters(io.prestosql.sql.DynamicFilters.extractDynamicFilters) MatchResult.match(io.prestosql.sql.planner.assertions.MatchResult.match) DynamicFilters(io.prestosql.sql.DynamicFilters) PlanNode(io.prestosql.spi.plan.PlanNode) VariableReferenceExpression(io.prestosql.spi.relation.VariableReferenceExpression) Metadata(io.prestosql.metadata.Metadata) SemiJoinNode(io.prestosql.sql.planner.plan.SemiJoinNode) Preconditions.checkState(com.google.common.base.Preconditions.checkState) PlanNodeSearcher.searchFrom(io.prestosql.sql.planner.optimizations.PlanNodeSearcher.searchFrom) ExpressionExtractor.extractExpressions(io.prestosql.sql.planner.ExpressionExtractor.extractExpressions) SymbolUtils.toSymbolReference(io.prestosql.sql.planner.SymbolUtils.toSymbolReference) List(java.util.List) FilterNode(io.prestosql.spi.plan.FilterNode) Objects.requireNonNull(java.util.Objects.requireNonNull) Session(io.prestosql.Session) Optional(java.util.Optional) NO_MATCH(io.prestosql.sql.planner.assertions.MatchResult.NO_MATCH) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) Symbol(io.prestosql.spi.plan.Symbol) FilterNode(io.prestosql.spi.plan.FilterNode) SemiJoinNode(io.prestosql.sql.planner.plan.SemiJoinNode)

Example 9 with StatsProvider

use of io.prestosql.cost.StatsProvider in project hetu-core by openlookeng.

the class TableWriterMatcher 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());
    TableWriterNode tableWriterNode = (TableWriterNode) node;
    if (!tableWriterNode.getColumnNames().equals(columnNames)) {
        return NO_MATCH;
    }
    if (!columns.stream().map(s -> SymbolUtils.from(symbolAliases.get(s))).collect(toImmutableList()).equals(tableWriterNode.getColumns())) {
        return NO_MATCH;
    }
    return match();
}
Also used : SymbolUtils(io.prestosql.sql.planner.SymbolUtils) TableWriterNode(io.prestosql.sql.planner.plan.TableWriterNode) List(java.util.List) StatsProvider(io.prestosql.cost.StatsProvider) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Session(io.prestosql.Session) MatchResult.match(io.prestosql.sql.planner.assertions.MatchResult.match) PlanNode(io.prestosql.spi.plan.PlanNode) NO_MATCH(io.prestosql.sql.planner.assertions.MatchResult.NO_MATCH) Metadata(io.prestosql.metadata.Metadata) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) Preconditions.checkState(com.google.common.base.Preconditions.checkState) TableWriterNode(io.prestosql.sql.planner.plan.TableWriterNode)

Example 10 with StatsProvider

use of io.prestosql.cost.StatsProvider in project hetu-core by openlookeng.

the class PlanAssert method assertPlan.

public static void assertPlan(Session session, Metadata metadata, StatsCalculator statsCalculator, Plan actual, Lookup lookup, PlanMatchPattern pattern) {
    StatsProvider statsProvider = new CachingStatsProvider(statsCalculator, session, actual.getTypes());
    assertPlan(session, metadata, statsProvider, actual, lookup, pattern);
}
Also used : CachingStatsProvider(io.prestosql.cost.CachingStatsProvider) StatsProvider(io.prestosql.cost.StatsProvider) CachingStatsProvider(io.prestosql.cost.CachingStatsProvider)

Aggregations

StatsProvider (io.prestosql.cost.StatsProvider)17 PlanNode (io.prestosql.spi.plan.PlanNode)11 MoreObjects.toStringHelper (com.google.common.base.MoreObjects.toStringHelper)8 Preconditions.checkState (com.google.common.base.Preconditions.checkState)8 Session (io.prestosql.Session)8 Metadata (io.prestosql.metadata.Metadata)8 NO_MATCH (io.prestosql.sql.planner.assertions.MatchResult.NO_MATCH)8 List (java.util.List)8 CachingStatsProvider (io.prestosql.cost.CachingStatsProvider)7 MatchResult.match (io.prestosql.sql.planner.assertions.MatchResult.match)7 Optional (java.util.Optional)7 CachingCostProvider (io.prestosql.cost.CachingCostProvider)6 CostProvider (io.prestosql.cost.CostProvider)6 Objects.requireNonNull (java.util.Objects.requireNonNull)6 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)5 ImmutableSet.toImmutableSet (com.google.common.collect.ImmutableSet.toImmutableSet)3 Symbol (io.prestosql.spi.plan.Symbol)3 SymbolUtils.toSymbolReference (io.prestosql.sql.planner.SymbolUtils.toSymbolReference)3 TypeProvider (io.prestosql.sql.planner.TypeProvider)3 Map (java.util.Map)3