Search in sources :

Example 1 with NO_MATCH

use of com.facebook.presto.sql.planner.assertions.MatchResult.NO_MATCH in project presto by prestodb.

the class AggregationMatcher method detailMatches.

@Override
public MatchResult detailMatches(PlanNode node, Session session, Metadata metadata, SymbolAliases symbolAliases) {
    checkState(shapeMatches(node), "Plan testing framework error: shapeMatches returned false in detailMatches in %s", this.getClass().getName());
    AggregationNode aggregationNode = (AggregationNode) node;
    if (groupId.isPresent() != aggregationNode.getGroupIdSymbol().isPresent()) {
        return NO_MATCH;
    }
    if (groupingSets.size() != aggregationNode.getGroupingSets().size()) {
        return NO_MATCH;
    }
    List<Symbol> aggregationsWithMask = aggregationNode.getAggregations().entrySet().stream().filter(entry -> entry.getValue().isDistinct()).map(entry -> entry.getKey()).collect(Collectors.toList());
    if (aggregationsWithMask.size() != masks.keySet().size()) {
        return NO_MATCH;
    }
    for (Symbol symbol : aggregationsWithMask) {
        if (!masks.keySet().contains(symbol)) {
            return NO_MATCH;
        }
    }
    for (int i = 0; i < groupingSets.size(); i++) {
        if (!matches(groupingSets.get(i), aggregationNode.getGroupingSets().get(i), symbolAliases)) {
            return NO_MATCH;
        }
    }
    return match();
}
Also used : Session(com.facebook.presto.Session) Collection(java.util.Collection) Collectors(java.util.stream.Collectors) Preconditions.checkState(com.google.common.base.Preconditions.checkState) List(java.util.List) Symbol(com.facebook.presto.sql.planner.Symbol) PlanNode(com.facebook.presto.sql.planner.plan.PlanNode) Map(java.util.Map) MatchResult.match(com.facebook.presto.sql.planner.assertions.MatchResult.match) Optional(java.util.Optional) NO_MATCH(com.facebook.presto.sql.planner.assertions.MatchResult.NO_MATCH) ImmutableCollectors.toImmutableList(com.facebook.presto.util.ImmutableCollectors.toImmutableList) AggregationNode(com.facebook.presto.sql.planner.plan.AggregationNode) Metadata(com.facebook.presto.metadata.Metadata) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) Symbol(com.facebook.presto.sql.planner.Symbol) AggregationNode(com.facebook.presto.sql.planner.plan.AggregationNode)

Example 2 with NO_MATCH

use of com.facebook.presto.sql.planner.assertions.MatchResult.NO_MATCH in project presto by prestodb.

the class JoinMatcher method detailMatches.

@Override
public MatchResult detailMatches(PlanNode node, 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().isPresent()) {
            return NO_MATCH;
        }
        if (!new ExpressionVerifier(symbolAliases).process(joinNode.getFilter().get(), filter.get())) {
            return NO_MATCH;
        }
    } else {
        if (joinNode.getFilter().isPresent()) {
            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());
    return new MatchResult(expected.equals(actual));
}
Also used : JoinNode(com.facebook.presto.sql.planner.plan.JoinNode) ImmutableSet(com.google.common.collect.ImmutableSet) Session(com.facebook.presto.Session) Set(java.util.Set) Preconditions.checkState(com.google.common.base.Preconditions.checkState) List(java.util.List) Expression(com.facebook.presto.sql.tree.Expression) PlanNode(com.facebook.presto.sql.planner.plan.PlanNode) Objects.requireNonNull(java.util.Objects.requireNonNull) Optional(java.util.Optional) NO_MATCH(com.facebook.presto.sql.planner.assertions.MatchResult.NO_MATCH) ImmutableCollectors.toImmutableSet(com.facebook.presto.util.ImmutableCollectors.toImmutableSet) Metadata(com.facebook.presto.metadata.Metadata) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) JoinNode(com.facebook.presto.sql.planner.plan.JoinNode)

Aggregations

Session (com.facebook.presto.Session)2 Metadata (com.facebook.presto.metadata.Metadata)2 NO_MATCH (com.facebook.presto.sql.planner.assertions.MatchResult.NO_MATCH)2 PlanNode (com.facebook.presto.sql.planner.plan.PlanNode)2 MoreObjects.toStringHelper (com.google.common.base.MoreObjects.toStringHelper)2 Preconditions.checkState (com.google.common.base.Preconditions.checkState)2 List (java.util.List)2 Optional (java.util.Optional)2 Symbol (com.facebook.presto.sql.planner.Symbol)1 MatchResult.match (com.facebook.presto.sql.planner.assertions.MatchResult.match)1 AggregationNode (com.facebook.presto.sql.planner.plan.AggregationNode)1 JoinNode (com.facebook.presto.sql.planner.plan.JoinNode)1 Expression (com.facebook.presto.sql.tree.Expression)1 ImmutableCollectors.toImmutableList (com.facebook.presto.util.ImmutableCollectors.toImmutableList)1 ImmutableCollectors.toImmutableSet (com.facebook.presto.util.ImmutableCollectors.toImmutableSet)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Collection (java.util.Collection)1 Map (java.util.Map)1 Objects.requireNonNull (java.util.Objects.requireNonNull)1 Set (java.util.Set)1