Search in sources :

Example 1 with Step

use of io.trino.sql.planner.plan.AggregationNode.Step in project trino by trinodb.

the class AggregationMatcher 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());
    AggregationNode aggregationNode = (AggregationNode) node;
    if (groupId.isPresent() != aggregationNode.getGroupIdSymbol().isPresent()) {
        return NO_MATCH;
    }
    if (!matches(groupingSets.getGroupingKeys(), aggregationNode.getGroupingKeys(), symbolAliases)) {
        return NO_MATCH;
    }
    if (groupingSets.getGroupingSetCount() != aggregationNode.getGroupingSetCount()) {
        return NO_MATCH;
    }
    if (!groupingSets.getGlobalGroupingSets().equals(aggregationNode.getGlobalGroupingSets())) {
        return NO_MATCH;
    }
    Set<Symbol> actualMasks = aggregationNode.getAggregations().values().stream().filter(aggregation -> aggregation.getMask().isPresent()).map(aggregation -> aggregation.getMask().get()).collect(toImmutableSet());
    Set<Symbol> expectedMasks = masks.stream().map(name -> new Symbol(symbolAliases.get(name).getName())).collect(toImmutableSet());
    if (!actualMasks.equals(expectedMasks)) {
        return NO_MATCH;
    }
    if (step != aggregationNode.getStep()) {
        return NO_MATCH;
    }
    if (!matches(preGroupedSymbols, aggregationNode.getPreGroupedSymbols(), symbolAliases)) {
        return NO_MATCH;
    }
    if (!preGroupedSymbols.isEmpty() && !aggregationNode.isStreamable()) {
        return NO_MATCH;
    }
    return match();
}
Also used : Symbol(io.trino.sql.planner.Symbol) MatchResult.match(io.trino.sql.planner.assertions.MatchResult.match) Step(io.trino.sql.planner.plan.AggregationNode.Step) Collection(java.util.Collection) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) 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) Metadata(io.trino.metadata.Metadata) AggregationNode(io.trino.sql.planner.plan.AggregationNode) 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) Symbol(io.trino.sql.planner.Symbol) AggregationNode(io.trino.sql.planner.plan.AggregationNode)

Aggregations

MoreObjects.toStringHelper (com.google.common.base.MoreObjects.toStringHelper)1 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 ImmutableSet.toImmutableSet (com.google.common.collect.ImmutableSet.toImmutableSet)1 Session (io.trino.Session)1 StatsProvider (io.trino.cost.StatsProvider)1 Metadata (io.trino.metadata.Metadata)1 Symbol (io.trino.sql.planner.Symbol)1 NO_MATCH (io.trino.sql.planner.assertions.MatchResult.NO_MATCH)1 MatchResult.match (io.trino.sql.planner.assertions.MatchResult.match)1 AggregationNode (io.trino.sql.planner.plan.AggregationNode)1 Step (io.trino.sql.planner.plan.AggregationNode.Step)1 PlanNode (io.trino.sql.planner.plan.PlanNode)1 Collection (java.util.Collection)1 List (java.util.List)1 Optional (java.util.Optional)1 Set (java.util.Set)1