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();
}
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));
}
Aggregations