use of io.trino.sql.planner.optimizations.SymbolMapper in project trino by trinodb.
the class PushTableWriteThroughUnion method rewriteSource.
private static TableWriterNode rewriteSource(TableWriterNode writerNode, UnionNode unionNode, int source, List<Map<Symbol, Symbol>> sourceMappings, Context context) {
Map<Symbol, Symbol> inputMappings = getInputSymbolMapping(unionNode, source);
ImmutableMap.Builder<Symbol, Symbol> mappings = ImmutableMap.builder();
mappings.putAll(inputMappings);
ImmutableMap.Builder<Symbol, Symbol> outputMappings = ImmutableMap.builder();
for (Symbol outputSymbol : writerNode.getOutputSymbols()) {
if (inputMappings.containsKey(outputSymbol)) {
outputMappings.put(outputSymbol, inputMappings.get(outputSymbol));
} else {
Symbol newSymbol = context.getSymbolAllocator().newSymbol(outputSymbol);
outputMappings.put(outputSymbol, newSymbol);
mappings.put(outputSymbol, newSymbol);
}
}
sourceMappings.add(outputMappings.buildOrThrow());
SymbolMapper symbolMapper = symbolMapper(mappings.buildOrThrow());
return symbolMapper.map(writerNode, unionNode.getSources().get(source), context.getIdAllocator().getNextId());
}
use of io.trino.sql.planner.optimizations.SymbolMapper in project trino by trinodb.
the class PushTopNThroughProject method apply.
@Override
public Result apply(TopNNode parent, Captures captures, Context context) {
ProjectNode projectNode = captures.get(PROJECT_CHILD);
// Do not push down if the projection is made up of symbol references and exclusive dereferences. This prevents
// undoing of PushDownDereferencesThroughTopN. We still push topN in the case of overlapping dereferences since
// it enables PushDownDereferencesThroughTopN rule to push optimal dereferences.
Set<Expression> projections = ImmutableSet.copyOf(projectNode.getAssignments().getExpressions());
if (!extractRowSubscripts(projections, false, context.getSession(), typeAnalyzer, context.getSymbolAllocator().getTypes()).isEmpty() && exclusiveDereferences(projections, context.getSession(), typeAnalyzer, context.getSymbolAllocator().getTypes())) {
return Result.empty();
}
// do not push topN between projection and filter(table scan) so that they can be merged into a PageProcessor
PlanNode projectSource = context.getLookup().resolve(projectNode.getSource());
if (projectSource instanceof FilterNode) {
PlanNode filterSource = context.getLookup().resolve(((FilterNode) projectSource).getSource());
if (filterSource instanceof TableScanNode) {
return Result.empty();
}
}
Optional<SymbolMapper> symbolMapper = symbolMapper(parent.getOrderingScheme().getOrderBy(), projectNode.getAssignments());
if (symbolMapper.isEmpty()) {
return Result.empty();
}
TopNNode mappedTopN = symbolMapper.get().map(parent, projectNode.getSource(), context.getIdAllocator().getNextId());
return Result.ofPlanNode(projectNode.replaceChildren(ImmutableList.of(mappedTopN)));
}
Aggregations