use of io.trino.sql.tree.WindowOperation in project trino by trinodb.
the class QueryPlanner method planWindowMeasures.
private PlanBuilder planWindowMeasures(Node node, PlanBuilder subPlan, List<WindowOperation> windowMeasures) {
if (windowMeasures.isEmpty()) {
return subPlan;
}
for (WindowOperation windowMeasure : scopeAwareDistinct(subPlan, windowMeasures)) {
ResolvedWindow window = analysis.getWindow(windowMeasure);
checkState(window != null, "no resolved window for: " + windowMeasure);
// pre-project inputs
ImmutableList.Builder<Expression> inputsBuilder = ImmutableList.<Expression>builder().addAll(window.getPartitionBy()).addAll(getSortItemsFromOrderBy(window.getOrderBy()).stream().map(SortItem::getSortKey).iterator());
WindowFrame frame = window.getFrame().orElseThrow();
Optional<Expression> endValue = frame.getEnd().orElseThrow().getValue();
endValue.ifPresent(inputsBuilder::add);
List<Expression> inputs = inputsBuilder.build();
subPlan = subqueryPlanner.handleSubqueries(subPlan, inputs, analysis.getSubqueries(node));
subPlan = subPlan.appendProjections(inputs, symbolAllocator, idAllocator);
// process frame end
FrameOffsetPlanAndSymbol plan = planFrameOffset(subPlan, endValue.map(subPlan::translate));
subPlan = plan.getSubPlan();
Optional<Symbol> frameEnd = plan.getFrameOffsetSymbol();
subPlan = subqueryPlanner.handleSubqueries(subPlan, extractPatternRecognitionExpressions(frame.getVariableDefinitions(), frame.getMeasures()), analysis.getSubqueries(node));
subPlan = planPatternRecognition(subPlan, windowMeasure, window, frameEnd);
}
return subPlan;
}
Aggregations