Search in sources :

Example 1 with NO_MATCH

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

the class DistinctLimitMatcher 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());
    DistinctLimitNode distinctLimitNode = (DistinctLimitNode) node;
    if (distinctLimitNode.getLimit() != limit) {
        return NO_MATCH;
    }
    if (!distinctLimitNode.getHashSymbol().equals(hashSymbol.map(alias -> alias.toSymbol(symbolAliases)))) {
        return NO_MATCH;
    }
    return new MatchResult(ImmutableSet.copyOf(distinctLimitNode.getDistinctSymbols()).equals(distinctSymbols.stream().map(alias -> alias.toSymbol(symbolAliases)).collect(toImmutableSet())));
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) StatsProvider(io.trino.cost.StatsProvider) PlanNode(io.trino.sql.planner.plan.PlanNode) Preconditions.checkState(com.google.common.base.Preconditions.checkState) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Objects.requireNonNull(java.util.Objects.requireNonNull) DistinctLimitNode(io.trino.sql.planner.plan.DistinctLimitNode) Metadata(io.trino.metadata.Metadata) Optional(java.util.Optional) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) NO_MATCH(io.trino.sql.planner.assertions.MatchResult.NO_MATCH) Session(io.trino.Session) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) DistinctLimitNode(io.trino.sql.planner.plan.DistinctLimitNode)

Example 2 with NO_MATCH

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

the class IndexJoinMatcher 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());
    IndexJoinNode indexJoinNode = (IndexJoinNode) node;
    if (indexJoinNode.getCriteria().size() != criteria.size()) {
        return NO_MATCH;
    }
    Set<IndexJoinNode.EquiJoinClause> actualCriteria = ImmutableSet.copyOf(indexJoinNode.getCriteria());
    Set<IndexJoinNode.EquiJoinClause> expectedCriteria = criteria.stream().map(equiClause -> equiClause.getExpectedValue(symbolAliases)).collect(toImmutableSet());
    if (!expectedCriteria.equals(actualCriteria)) {
        return NO_MATCH;
    }
    if (!indexJoinNode.getProbeHashSymbol().equals(probeHashSymbol.map(alias -> alias.toSymbol(symbolAliases)))) {
        return NO_MATCH;
    }
    if (!indexJoinNode.getIndexHashSymbol().equals(indexHashSymbol.map(alias -> alias.toSymbol(symbolAliases)))) {
        return NO_MATCH;
    }
    return MatchResult.match();
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) IndexJoinNode(io.trino.sql.planner.plan.IndexJoinNode) Set(java.util.Set) StatsProvider(io.trino.cost.StatsProvider) PlanNode(io.trino.sql.planner.plan.PlanNode) Preconditions.checkState(com.google.common.base.Preconditions.checkState) List(java.util.List) Objects.requireNonNull(java.util.Objects.requireNonNull) Metadata(io.trino.metadata.Metadata) Optional(java.util.Optional) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) NO_MATCH(io.trino.sql.planner.assertions.MatchResult.NO_MATCH) Session(io.trino.Session) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) IndexJoinNode(io.trino.sql.planner.plan.IndexJoinNode)

Example 3 with NO_MATCH

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

the class UnnestMatcher 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());
    UnnestNode unnestNode = (UnnestNode) node;
    if (unnestNode.getReplicateSymbols().size() != replicateSymbols.size()) {
        return NO_MATCH;
    }
    if (!replicateSymbols.stream().map(symbolAliases::get).map(Symbol::from).collect(toImmutableList()).equals(unnestNode.getReplicateSymbols())) {
        return NO_MATCH;
    }
    if (unnestNode.getMappings().size() != unnestMappings.size()) {
        return NO_MATCH;
    }
    if (!IntStream.range(0, unnestMappings.size()).boxed().allMatch(index -> {
        Mapping nodeMapping = unnestNode.getMappings().get(index);
        PlanMatchPattern.UnnestMapping patternMapping = unnestMappings.get(index);
        return nodeMapping.getInput().toSymbolReference().equals(symbolAliases.get(patternMapping.getInput())) && patternMapping.getOutputs().size() == nodeMapping.getOutputs().size();
    })) {
        return NO_MATCH;
    }
    if (ordinalitySymbol.isPresent() != unnestNode.getOrdinalitySymbol().isPresent()) {
        return NO_MATCH;
    }
    if (!type.equals(unnestNode.getJoinType())) {
        return NO_MATCH;
    }
    if (filter.isPresent() != unnestNode.getFilter().isPresent()) {
        return NO_MATCH;
    }
    if (filter.isEmpty()) {
        return MatchResult.match();
    }
    if (!new ExpressionVerifier(symbolAliases).process(unnestNode.getFilter().get(), filter.get())) {
        return NO_MATCH;
    }
    return MatchResult.match();
}
Also used : IntStream(java.util.stream.IntStream) Symbol(io.trino.sql.planner.Symbol) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) StatsProvider(io.trino.cost.StatsProvider) UnnestNode(io.trino.sql.planner.plan.UnnestNode) PlanNode(io.trino.sql.planner.plan.PlanNode) Preconditions.checkState(com.google.common.base.Preconditions.checkState) List(java.util.List) Mapping(io.trino.sql.planner.plan.UnnestNode.Mapping) 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) Expression(io.trino.sql.tree.Expression) JoinNode(io.trino.sql.planner.plan.JoinNode) Session(io.trino.Session) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) UnnestNode(io.trino.sql.planner.plan.UnnestNode) Mapping(io.trino.sql.planner.plan.UnnestNode.Mapping)

Example 4 with NO_MATCH

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

the class ValuesMatcher 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());
    ValuesNode valuesNode = (ValuesNode) node;
    if (expectedRows.isPresent()) {
        if (expectedRows.get().size() != valuesNode.getRowCount()) {
            return NO_MATCH;
        }
        if (outputSymbolAliases.size() > 0) {
            if (!expectedRows.equals(valuesNode.getRows())) {
                return NO_MATCH;
            }
        }
    }
    return match(SymbolAliases.builder().putAll(Maps.transformValues(outputSymbolAliases, index -> valuesNode.getOutputSymbols().get(index).toSymbolReference())).build());
}
Also used : MatchResult.match(io.trino.sql.planner.assertions.MatchResult.match) ImmutableMap(com.google.common.collect.ImmutableMap) Maps(com.google.common.collect.Maps) StatsProvider(io.trino.cost.StatsProvider) PlanNode(io.trino.sql.planner.plan.PlanNode) Preconditions.checkState(com.google.common.base.Preconditions.checkState) List(java.util.List) Map(java.util.Map) 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) Expression(io.trino.sql.tree.Expression) ValuesNode(io.trino.sql.planner.plan.ValuesNode) Session(io.trino.Session) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) ValuesNode(io.trino.sql.planner.plan.ValuesNode)

Example 5 with NO_MATCH

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

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(), markDistinctNode.getMarkerSymbol().toSymbolReference());
}
Also used : MarkDistinctNode(io.trino.sql.planner.plan.MarkDistinctNode) ImmutableSet(com.google.common.collect.ImmutableSet) MatchResult.match(io.trino.sql.planner.assertions.MatchResult.match) StatsProvider(io.trino.cost.StatsProvider) PlanNode(io.trino.sql.planner.plan.PlanNode) Preconditions.checkState(com.google.common.base.Preconditions.checkState) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Objects.requireNonNull(java.util.Objects.requireNonNull) Metadata(io.trino.metadata.Metadata) Optional(java.util.Optional) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) NO_MATCH(io.trino.sql.planner.assertions.MatchResult.NO_MATCH) Session(io.trino.Session) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) MarkDistinctNode(io.trino.sql.planner.plan.MarkDistinctNode)

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