use of io.trino.sql.planner.SymbolsExtractor in project trino by trinodb.
the class MergePatternRecognitionNodes method extractPrerequisites.
/**
* Extract project assignments producing symbols used by the PatternRecognitionNode's
* window functions and measures. Exclude identity assignments.
*/
private static Assignments extractPrerequisites(PatternRecognitionNode node, ProjectNode project) {
Assignments assignments = project.getAssignments();
ImmutableSet.Builder<Symbol> inputsBuilder = ImmutableSet.builder();
node.getWindowFunctions().values().stream().map(SymbolsExtractor::extractAll).forEach(inputsBuilder::addAll);
node.getMeasures().values().stream().map(Measure::getExpressionAndValuePointers).map(ExpressionAndValuePointers::getInputSymbols).forEach(inputsBuilder::addAll);
Set<Symbol> inputs = inputsBuilder.build();
return assignments.filter(symbol -> !assignments.isIdentity(symbol)).filter(inputs::contains);
}
use of io.trino.sql.planner.SymbolsExtractor in project trino by trinodb.
the class MergePatternRecognitionNodes method dependsOnSourceCreatedOutputs.
/**
* Check if parent node uses output symbols created by the child node (that is, the output symbols
* of child node's window functions and measures), with an intervening projection between the parent
* and child nodes. Only searches for dependencies in the window functions and measures of the parent
* node. Other properties of the parent node, such as specification and frame, are supposed to be
* identical to corresponding properties of the child node, as checked in the
* `patternRecognitionSpecificationsMatch` call. As such, they cannot use symbols created by the child.
*/
private static boolean dependsOnSourceCreatedOutputs(PatternRecognitionNode parent, ProjectNode project, PatternRecognitionNode child) {
Set<Symbol> sourceCreatedOutputs = child.getCreatedSymbols();
Assignments assignments = project.getAssignments();
ImmutableSet.Builder<Symbol> parentInputs = ImmutableSet.builder();
parent.getWindowFunctions().values().stream().map(SymbolsExtractor::extractAll).forEach(parentInputs::addAll);
parent.getMeasures().values().stream().map(Measure::getExpressionAndValuePointers).map(ExpressionAndValuePointers::getInputSymbols).forEach(parentInputs::addAll);
return parentInputs.build().stream().map(assignments::get).map(SymbolsExtractor::extractAll).flatMap(Collection::stream).anyMatch(sourceCreatedOutputs::contains);
}
Aggregations