use of io.trino.spi.function.WindowFunction in project trino by trinodb.
the class PatternRecognitionPartition method outputUnmatchedRow.
// the output for unmatched row refers to no pattern match and empty frame.
private void outputUnmatchedRow(PageBuilder pageBuilder) {
// copy output channels
pageBuilder.declarePosition();
int channel = 0;
while (channel < outputChannels.length) {
pagesIndex.appendTo(outputChannels[channel], currentPosition, pageBuilder.getBlockBuilder(channel));
channel++;
}
// measures are all null for no match
for (int i = 0; i < measures.size(); i++) {
pageBuilder.getBlockBuilder(channel).appendNull();
channel++;
}
// window functions have empty frame
for (WindowFunction function : windowFunctions) {
Range range = new Range(-1, -1);
function.processRow(pageBuilder.getBlockBuilder(channel), peerGroupStart - partitionStart, peerGroupEnd - partitionStart - 1, range.getStart(), range.getEnd());
channel++;
}
}
use of io.trino.spi.function.WindowFunction in project trino by trinodb.
the class PatternRecognitionPartition method outputOneRowPerMatch.
private void outputOneRowPerMatch(PageBuilder pageBuilder, MatchResult matchResult, int patternStart, int searchStart, int searchEnd) {
// copy output channels
pageBuilder.declarePosition();
int channel = 0;
while (channel < outputChannels.length) {
pagesIndex.appendTo(outputChannels[channel], currentPosition, pageBuilder.getBlockBuilder(channel));
channel++;
}
// compute measures from the position of the last row of the match
ArrayView labels = matchResult.getLabels();
for (MeasureComputation measureComputation : measures) {
Block result = measureComputation.compute(patternStart + labels.length() - 1, labels, partitionStart, searchStart, searchEnd, patternStart, matchNumber, measureComputationsIndex);
measureComputation.getType().appendTo(result, 0, pageBuilder.getBlockBuilder(channel));
channel++;
}
// window functions have frame consisting of all rows of the match
for (WindowFunction function : windowFunctions) {
function.processRow(pageBuilder.getBlockBuilder(channel), peerGroupStart - partitionStart, peerGroupEnd - partitionStart - 1, patternStart - partitionStart, patternStart + labels.length() - 1 - partitionStart);
channel++;
}
}
use of io.trino.spi.function.WindowFunction in project trino by trinodb.
the class RegularWindowPartition method processNextRow.
@Override
public void processNextRow(PageBuilder pageBuilder) {
checkState(hasNext(), "No more rows in partition");
// copy output channels
pageBuilder.declarePosition();
int channel = 0;
while (channel < outputChannels.length) {
pagesIndex.appendTo(outputChannels[channel], currentPosition, pageBuilder.getBlockBuilder(channel));
channel++;
}
// check for new peer group
if (currentPosition == peerGroupEnd) {
updatePeerGroup();
}
for (int i = 0; i < windowFunctions.size(); i++) {
WindowFunction windowFunction = windowFunctions.get(i);
Framing.Range range = framings.get(i).getRange(currentPosition, currentGroupIndex, peerGroupStart, peerGroupEnd);
windowFunction.processRow(pageBuilder.getBlockBuilder(channel), peerGroupStart - partitionStart, peerGroupEnd - partitionStart - 1, range.getStart(), range.getEnd());
channel++;
}
currentPosition++;
}
use of io.trino.spi.function.WindowFunction in project trino by trinodb.
the class WindowAnnotationsParser method parse.
private static SqlWindowFunction parse(Class<? extends WindowFunction> clazz, WindowFunctionSignature window) {
List<TypeVariableConstraint> typeVariables = ImmutableList.of();
if (!window.typeVariable().isEmpty()) {
typeVariables = ImmutableList.of(typeVariable(window.typeVariable()));
}
List<TypeSignature> argumentTypes = Stream.of(window.argumentTypes()).map(type -> parseTypeSignature(type, ImmutableSet.of())).collect(toImmutableList());
Signature signature = new Signature(window.name(), typeVariables, ImmutableList.of(), parseTypeSignature(window.returnType(), ImmutableSet.of()), argumentTypes, false);
Optional<String> description = Optional.ofNullable(clazz.getAnnotation(Description.class)).map(Description::value);
boolean deprecated = clazz.getAnnotationsByType(Deprecated.class).length > 0;
return new SqlWindowFunction(signature, description, deprecated, new ReflectionWindowFunctionSupplier(window.argumentTypes().length, clazz));
}
use of io.trino.spi.function.WindowFunction in project trino by trinodb.
the class PatternRecognitionPartition method outputEmptyMatch.
// the output for empty match refers to empty pattern match and empty frame.
private void outputEmptyMatch(PageBuilder pageBuilder) {
// copy output channels
pageBuilder.declarePosition();
int channel = 0;
while (channel < outputChannels.length) {
pagesIndex.appendTo(outputChannels[channel], currentPosition, pageBuilder.getBlockBuilder(channel));
channel++;
}
// compute measures
for (MeasureComputation measureComputation : measures) {
Block result = measureComputation.computeEmpty(matchNumber);
measureComputation.getType().appendTo(result, 0, pageBuilder.getBlockBuilder(channel));
channel++;
}
// window functions have empty frame
for (WindowFunction function : windowFunctions) {
Range range = new Range(-1, -1);
function.processRow(pageBuilder.getBlockBuilder(channel), peerGroupStart - partitionStart, peerGroupEnd - partitionStart - 1, range.getStart(), range.getEnd());
channel++;
}
}
Aggregations