Search in sources :

Example 1 with WindowFunction

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++;
    }
}
Also used : WindowFunction(io.trino.spi.function.WindowFunction) Range(io.trino.operator.window.Framing.Range)

Example 2 with WindowFunction

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++;
    }
}
Also used : MeasureComputation(io.trino.operator.window.pattern.MeasureComputation) WindowFunction(io.trino.spi.function.WindowFunction) Block(io.trino.spi.block.Block) ArrayView(io.trino.operator.window.matcher.ArrayView)

Example 3 with WindowFunction

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++;
}
Also used : WindowFunction(io.trino.spi.function.WindowFunction)

Example 4 with WindowFunction

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));
}
Also used : WindowFunctionSignature(io.trino.spi.function.WindowFunctionSignature) TypeVariableConstraint(io.trino.metadata.TypeVariableConstraint) ImmutableSet(com.google.common.collect.ImmutableSet) Description(io.trino.spi.function.Description) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) TypeSignatureTranslator.parseTypeSignature(io.trino.sql.analyzer.TypeSignatureTranslator.parseTypeSignature) List(java.util.List) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Stream(java.util.stream.Stream) ImmutableList(com.google.common.collect.ImmutableList) WindowFunction(io.trino.spi.function.WindowFunction) Signature.typeVariable(io.trino.metadata.Signature.typeVariable) Optional(java.util.Optional) Signature(io.trino.metadata.Signature) TypeSignature(io.trino.spi.type.TypeSignature) TypeSignatureTranslator.parseTypeSignature(io.trino.sql.analyzer.TypeSignatureTranslator.parseTypeSignature) TypeSignature(io.trino.spi.type.TypeSignature) Description(io.trino.spi.function.Description) WindowFunctionSignature(io.trino.spi.function.WindowFunctionSignature) TypeSignatureTranslator.parseTypeSignature(io.trino.sql.analyzer.TypeSignatureTranslator.parseTypeSignature) Signature(io.trino.metadata.Signature) TypeSignature(io.trino.spi.type.TypeSignature) TypeVariableConstraint(io.trino.metadata.TypeVariableConstraint)

Example 5 with WindowFunction

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++;
    }
}
Also used : MeasureComputation(io.trino.operator.window.pattern.MeasureComputation) WindowFunction(io.trino.spi.function.WindowFunction) Block(io.trino.spi.block.Block) Range(io.trino.operator.window.Framing.Range)

Aggregations

WindowFunction (io.trino.spi.function.WindowFunction)5 Range (io.trino.operator.window.Framing.Range)2 MeasureComputation (io.trino.operator.window.pattern.MeasureComputation)2 Block (io.trino.spi.block.Block)2 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Signature (io.trino.metadata.Signature)1 Signature.typeVariable (io.trino.metadata.Signature.typeVariable)1 TypeVariableConstraint (io.trino.metadata.TypeVariableConstraint)1 ArrayView (io.trino.operator.window.matcher.ArrayView)1 Description (io.trino.spi.function.Description)1 WindowFunctionSignature (io.trino.spi.function.WindowFunctionSignature)1 TypeSignature (io.trino.spi.type.TypeSignature)1 TypeSignatureTranslator.parseTypeSignature (io.trino.sql.analyzer.TypeSignatureTranslator.parseTypeSignature)1 List (java.util.List)1 Optional (java.util.Optional)1 Stream (java.util.stream.Stream)1