use of io.crate.analyze.FrameBoundDefinition in project crate by crate.
the class DefaultTraversalSymbolVisitor method visitWindowFunction.
@Override
public R visitWindowFunction(WindowFunction symbol, C context) {
for (Symbol arg : symbol.arguments()) {
arg.accept(this, context);
}
Symbol filter = symbol.filter();
if (filter != null) {
filter.accept(this, context);
}
WindowDefinition windowDefinition = symbol.windowDefinition();
OrderBy orderBy = windowDefinition.orderBy();
if (orderBy != null) {
for (Symbol orderBySymbol : orderBy.orderBySymbols()) {
orderBySymbol.accept(this, context);
}
}
for (Symbol partition : windowDefinition.partitions()) {
partition.accept(this, context);
}
Symbol frameStartValueSymbol = windowDefinition.windowFrameDefinition().start().value();
if (frameStartValueSymbol != null) {
frameStartValueSymbol.accept(this, context);
}
FrameBoundDefinition end = windowDefinition.windowFrameDefinition().end();
if (end != null) {
Symbol frameEndValueSymbol = end.value();
if (frameEndValueSymbol != null) {
frameEndValueSymbol.accept(this, context);
}
}
return null;
}
use of io.crate.analyze.FrameBoundDefinition in project crate by crate.
the class ExpressionAnalyzer method convertToAnalyzedFrameBound.
private FrameBoundDefinition convertToAnalyzedFrameBound(ExpressionAnalysisContext context, FrameBound frameBound) {
Expression offsetExpression = frameBound.getValue();
Symbol offsetSymbol = offsetExpression == null ? Literal.NULL : convert(offsetExpression, context);
return new FrameBoundDefinition(frameBound.getType(), offsetSymbol);
}
use of io.crate.analyze.FrameBoundDefinition in project crate by crate.
the class ExpressionAnalyzer method getWindowDefinition.
@Nullable
private WindowDefinition getWindowDefinition(Optional<Window> maybeWindow, ExpressionAnalysisContext context) {
if (!maybeWindow.isPresent()) {
return null;
}
var unresolvedWindow = maybeWindow.get();
final Window window;
if (unresolvedWindow.windowRef() != null) {
var refWindow = resolveWindowRef(unresolvedWindow.windowRef(), context.windows());
window = unresolvedWindow.merge(refWindow);
} else {
window = unresolvedWindow;
}
List<Symbol> partitionSymbols = new ArrayList<>(window.getPartitions().size());
for (Expression partition : window.getPartitions()) {
Symbol symbol = convert(partition, context);
SemanticSortValidator.validate(symbol, "PARTITION BY");
partitionSymbols.add(symbol);
}
OrderBy orderBy = OrderyByAnalyzer.analyzeSortItems(window.getOrderBy(), sortKey -> {
Symbol symbol = convert(sortKey, context);
SemanticSortValidator.validate(symbol);
return symbol;
});
WindowFrameDefinition windowFrameDefinition = WindowDefinition.RANGE_UNBOUNDED_PRECEDING_CURRENT_ROW;
if (window.getWindowFrame().isPresent()) {
WindowFrame windowFrame = window.getWindowFrame().get();
validateFrame(window, windowFrame);
FrameBound start = windowFrame.getStart();
FrameBoundDefinition startBound = convertToAnalyzedFrameBound(context, start);
FrameBoundDefinition endBound = windowFrame.getEnd().map(end -> convertToAnalyzedFrameBound(context, end)).orElse(new FrameBoundDefinition(FrameBound.Type.CURRENT_ROW, Literal.NULL));
windowFrameDefinition = new WindowFrameDefinition(windowFrame.mode(), startBound, endBound);
}
return new WindowDefinition(partitionSymbols, orderBy, windowFrameDefinition);
}
Aggregations