Search in sources :

Example 11 with NO_MATCH

use of io.trino.sql.planner.assertions.MatchResult.NO_MATCH in project trino by trinodb.

the class JoinMatcher 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());
    JoinNode joinNode = (JoinNode) node;
    if (joinNode.getCriteria().size() != equiCriteria.size()) {
        return NO_MATCH;
    }
    if (filter.isPresent()) {
        if (joinNode.getFilter().isEmpty()) {
            return NO_MATCH;
        }
        if (!new ExpressionVerifier(symbolAliases).process(joinNode.getFilter().get(), filter.get())) {
            return NO_MATCH;
        }
    } else {
        if (joinNode.getFilter().isPresent()) {
            return NO_MATCH;
        }
    }
    if (distributionType.isPresent() && !distributionType.equals(joinNode.getDistributionType())) {
        return NO_MATCH;
    }
    if (spillable.isPresent() && !spillable.equals(joinNode.isSpillable())) {
        return NO_MATCH;
    }
    /*
         * Have to use order-independent comparison; there are no guarantees what order
         * the equi criteria will have after planning and optimizing.
         */
    Set<JoinNode.EquiJoinClause> actual = ImmutableSet.copyOf(joinNode.getCriteria());
    Set<JoinNode.EquiJoinClause> expected = equiCriteria.stream().map(maker -> maker.getExpectedValue(symbolAliases)).collect(toImmutableSet());
    if (!expected.equals(actual)) {
        return NO_MATCH;
    }
    return new MatchResult(matchDynamicFilters(joinNode, symbolAliases));
}
Also used : PlanNodeSearcher.searchFrom(io.trino.sql.planner.optimizations.PlanNodeSearcher.searchFrom) DynamicFilters.extractDynamicFilters(io.trino.sql.DynamicFilters.extractDynamicFilters) FilterNode(io.trino.sql.planner.plan.FilterNode) DynamicFilterId(io.trino.sql.planner.plan.DynamicFilterId) PlanNode(io.trino.sql.planner.plan.PlanNode) HashSet(java.util.HashSet) DynamicFilters(io.trino.sql.DynamicFilters) DistributionType(io.trino.sql.planner.plan.JoinNode.DistributionType) IS_DISTINCT_FROM(io.trino.sql.tree.ComparisonExpression.Operator.IS_DISTINCT_FROM) NotExpression(io.trino.sql.tree.NotExpression) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) ExpressionExtractor.extractExpressions(io.trino.sql.planner.ExpressionExtractor.extractExpressions) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) DynamicFilterPattern(io.trino.sql.planner.assertions.PlanMatchPattern.DynamicFilterPattern) JoinNode(io.trino.sql.planner.plan.JoinNode) Symbol(io.trino.sql.planner.Symbol) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Set(java.util.Set) StatsProvider(io.trino.cost.StatsProvider) ComparisonExpression(io.trino.sql.tree.ComparisonExpression) Preconditions.checkState(com.google.common.base.Preconditions.checkState) List(java.util.List) Metadata(io.trino.metadata.Metadata) Optional(java.util.Optional) NO_MATCH(io.trino.sql.planner.assertions.MatchResult.NO_MATCH) Expression(io.trino.sql.tree.Expression) Session(io.trino.Session) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) JoinNode(io.trino.sql.planner.plan.JoinNode)

Example 12 with NO_MATCH

use of io.trino.sql.planner.assertions.MatchResult.NO_MATCH in project trino by trinodb.

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

Example 13 with NO_MATCH

use of io.trino.sql.planner.assertions.MatchResult.NO_MATCH in project trino by trinodb.

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;
        }
    }
    if (orderSensitive.isPresent()) {
        if (!orderSensitive.get().equals(rowNumberNode.isOrderSensitive())) {
            return NO_MATCH;
        }
    }
    return match();
}
Also used : Symbol(io.trino.sql.planner.Symbol) MatchResult.match(io.trino.sql.planner.assertions.MatchResult.match) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) StatsProvider(io.trino.cost.StatsProvider) PlanNode(io.trino.sql.planner.plan.PlanNode) Preconditions.checkState(com.google.common.base.Preconditions.checkState) PlanMatchPattern.node(io.trino.sql.planner.assertions.PlanMatchPattern.node) List(java.util.List) RowNumberNode(io.trino.sql.planner.plan.RowNumberNode) Objects.requireNonNull(java.util.Objects.requireNonNull) Metadata(io.trino.metadata.Metadata) Optional(java.util.Optional) NO_MATCH(io.trino.sql.planner.assertions.MatchResult.NO_MATCH) Session(io.trino.Session) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) Symbol(io.trino.sql.planner.Symbol) RowNumberNode(io.trino.sql.planner.plan.RowNumberNode)

Aggregations

MoreObjects.toStringHelper (com.google.common.base.MoreObjects.toStringHelper)13 Preconditions.checkState (com.google.common.base.Preconditions.checkState)13 Session (io.trino.Session)13 StatsProvider (io.trino.cost.StatsProvider)13 Metadata (io.trino.metadata.Metadata)13 NO_MATCH (io.trino.sql.planner.assertions.MatchResult.NO_MATCH)13 PlanNode (io.trino.sql.planner.plan.PlanNode)13 List (java.util.List)13 Optional (java.util.Optional)11 Objects.requireNonNull (java.util.Objects.requireNonNull)10 MatchResult.match (io.trino.sql.planner.assertions.MatchResult.match)9 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)7 Symbol (io.trino.sql.planner.Symbol)7 ImmutableSet.toImmutableSet (com.google.common.collect.ImmutableSet.toImmutableSet)6 Set (java.util.Set)5 ImmutableSet (com.google.common.collect.ImmutableSet)4 Expression (io.trino.sql.tree.Expression)4 Map (java.util.Map)4 PlanMatchPattern.node (io.trino.sql.planner.assertions.PlanMatchPattern.node)3 ImmutableList (com.google.common.collect.ImmutableList)2