Search in sources :

Example 1 with Mapping

use of io.trino.sql.planner.plan.UnnestNode.Mapping 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 2 with Mapping

use of io.trino.sql.planner.plan.UnnestNode.Mapping in project trino by trinodb.

the class UnnestedSymbolMatcher method getAssignedSymbol.

@Override
public Optional<Symbol> getAssignedSymbol(PlanNode node, Session session, Metadata metadata, SymbolAliases symbolAliases) {
    if (!(node instanceof UnnestNode)) {
        return Optional.empty();
    }
    UnnestNode unnestNode = (UnnestNode) node;
    Symbol unnestSymbol = Symbol.from(symbolAliases.get(symbol));
    List<Mapping> matches = unnestNode.getMappings().stream().filter(mapping -> mapping.getInput().equals(unnestSymbol)).collect(toImmutableList());
    checkState(matches.size() < 2, "alias matching not supported for repeated unnest symbols");
    if (matches.size() == 0) {
        return Optional.empty();
    }
    Mapping mapping = getOnlyElement(matches);
    if (index >= mapping.getOutputs().size()) {
        return Optional.empty();
    }
    return Optional.of(mapping.getOutputs().get(index));
}
Also used : Symbol(io.trino.sql.planner.Symbol) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Iterables.getOnlyElement(com.google.common.collect.Iterables.getOnlyElement) 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) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Mapping(io.trino.sql.planner.plan.UnnestNode.Mapping) Objects.requireNonNull(java.util.Objects.requireNonNull) Metadata(io.trino.metadata.Metadata) Optional(java.util.Optional) Session(io.trino.Session) UnnestNode(io.trino.sql.planner.plan.UnnestNode) Symbol(io.trino.sql.planner.Symbol) Mapping(io.trino.sql.planner.plan.UnnestNode.Mapping)

Aggregations

Preconditions.checkState (com.google.common.base.Preconditions.checkState)2 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)2 Session (io.trino.Session)2 Metadata (io.trino.metadata.Metadata)2 Symbol (io.trino.sql.planner.Symbol)2 PlanNode (io.trino.sql.planner.plan.PlanNode)2 UnnestNode (io.trino.sql.planner.plan.UnnestNode)2 Mapping (io.trino.sql.planner.plan.UnnestNode.Mapping)2 List (java.util.List)2 Objects.requireNonNull (java.util.Objects.requireNonNull)2 Optional (java.util.Optional)2 MoreObjects.toStringHelper (com.google.common.base.MoreObjects.toStringHelper)1 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Iterables.getOnlyElement (com.google.common.collect.Iterables.getOnlyElement)1 StatsProvider (io.trino.cost.StatsProvider)1 NO_MATCH (io.trino.sql.planner.assertions.MatchResult.NO_MATCH)1 JoinNode (io.trino.sql.planner.plan.JoinNode)1 Expression (io.trino.sql.tree.Expression)1 IntStream (java.util.stream.IntStream)1