Search in sources :

Example 16 with TypeParameter

use of io.prestosql.spi.function.TypeParameter in project hetu-core by openlookeng.

the class ArrayExceptFunction method except.

@TypeParameter("E")
@SqlType("array(E)")
public static Block except(@TypeParameter("E") Type type, @SqlType("array(E)") Block leftArray, @SqlType("array(E)") Block rightArray) {
    int leftPositionCount = leftArray.getPositionCount();
    int rightPositionCount = rightArray.getPositionCount();
    if (leftPositionCount == 0) {
        return leftArray;
    }
    TypedSet typedSet = new TypedSet(type, leftPositionCount + rightPositionCount, "array_except");
    BlockBuilder distinctElementBlockBuilder = type.createBlockBuilder(null, leftPositionCount);
    for (int i = 0; i < rightPositionCount; i++) {
        typedSet.add(rightArray, i);
    }
    for (int i = 0; i < leftPositionCount; i++) {
        if (!typedSet.contains(leftArray, i)) {
            typedSet.add(leftArray, i);
            type.appendTo(leftArray, i, distinctElementBlockBuilder);
        }
    }
    return distinctElementBlockBuilder.build();
}
Also used : TypedSet(io.prestosql.operator.aggregation.TypedSet) BlockBuilder(io.prestosql.spi.block.BlockBuilder) TypeParameter(io.prestosql.spi.function.TypeParameter) SqlType(io.prestosql.spi.function.SqlType)

Example 17 with TypeParameter

use of io.prestosql.spi.function.TypeParameter in project hetu-core by openlookeng.

the class ArrayFilterFunction method filterLong.

@TypeParameter("T")
@TypeParameterSpecialization(name = "T", nativeContainerType = long.class)
@SqlType("array(T)")
public static Block filterLong(@TypeParameter("T") Type elementType, @SqlType("array(T)") Block arrayBlock, @SqlType("function(T, boolean)") FilterLongLambda function) {
    int positionCount = arrayBlock.getPositionCount();
    BlockBuilder resultBuilder = elementType.createBlockBuilder(null, positionCount);
    for (int position = 0; position < positionCount; position++) {
        Long input = null;
        if (!arrayBlock.isNull(position)) {
            input = elementType.getLong(arrayBlock, position);
        }
        Boolean keep = function.apply(input);
        if (TRUE.equals(keep)) {
            elementType.appendTo(arrayBlock, position, resultBuilder);
        }
    }
    return resultBuilder.build();
}
Also used : BlockBuilder(io.prestosql.spi.block.BlockBuilder) TypeParameterSpecialization(io.prestosql.spi.function.TypeParameterSpecialization) TypeParameter(io.prestosql.spi.function.TypeParameter) SqlType(io.prestosql.spi.function.SqlType)

Example 18 with TypeParameter

use of io.prestosql.spi.function.TypeParameter in project hetu-core by openlookeng.

the class ArrayFilterFunction method filterBlock.

@TypeParameter("T")
@TypeParameterSpecialization(name = "T", nativeContainerType = Block.class)
@SqlType("array(T)")
public static Block filterBlock(@TypeParameter("T") Type elementType, @SqlType("array(T)") Block arrayBlock, @SqlType("function(T, boolean)") FilterBlockLambda function) {
    int positionCount = arrayBlock.getPositionCount();
    BlockBuilder resultBuilder = elementType.createBlockBuilder(null, positionCount);
    for (int position = 0; position < positionCount; position++) {
        Block input = null;
        if (!arrayBlock.isNull(position)) {
            input = (Block) elementType.getObject(arrayBlock, position);
        }
        Boolean keep = function.apply(input);
        if (TRUE.equals(keep)) {
            elementType.appendTo(arrayBlock, position, resultBuilder);
        }
    }
    return resultBuilder.build();
}
Also used : Block(io.prestosql.spi.block.Block) BlockBuilder(io.prestosql.spi.block.BlockBuilder) TypeParameterSpecialization(io.prestosql.spi.function.TypeParameterSpecialization) TypeParameter(io.prestosql.spi.function.TypeParameter) SqlType(io.prestosql.spi.function.SqlType)

Example 19 with TypeParameter

use of io.prestosql.spi.function.TypeParameter in project hetu-core by openlookeng.

the class ArrayFilterFunction method filterSlice.

@TypeParameter("T")
@TypeParameterSpecialization(name = "T", nativeContainerType = Slice.class)
@SqlType("array(T)")
public static Block filterSlice(@TypeParameter("T") Type elementType, @SqlType("array(T)") Block arrayBlock, @SqlType("function(T, boolean)") FilterSliceLambda function) {
    int positionCount = arrayBlock.getPositionCount();
    BlockBuilder resultBuilder = elementType.createBlockBuilder(null, positionCount);
    for (int position = 0; position < positionCount; position++) {
        Slice input = null;
        if (!arrayBlock.isNull(position)) {
            input = elementType.getSlice(arrayBlock, position);
        }
        Boolean keep = function.apply(input);
        if (TRUE.equals(keep)) {
            elementType.appendTo(arrayBlock, position, resultBuilder);
        }
    }
    return resultBuilder.build();
}
Also used : Slice(io.airlift.slice.Slice) BlockBuilder(io.prestosql.spi.block.BlockBuilder) TypeParameterSpecialization(io.prestosql.spi.function.TypeParameterSpecialization) TypeParameter(io.prestosql.spi.function.TypeParameter) SqlType(io.prestosql.spi.function.SqlType)

Example 20 with TypeParameter

use of io.prestosql.spi.function.TypeParameter in project hetu-core by openlookeng.

the class ArrayFilterFunction method filterBoolean.

@TypeParameter("T")
@TypeParameterSpecialization(name = "T", nativeContainerType = boolean.class)
@SqlType("array(T)")
public static Block filterBoolean(@TypeParameter("T") Type elementType, @SqlType("array(T)") Block arrayBlock, @SqlType("function(T, boolean)") FilterBooleanLambda function) {
    int positionCount = arrayBlock.getPositionCount();
    BlockBuilder resultBuilder = elementType.createBlockBuilder(null, positionCount);
    for (int position = 0; position < positionCount; position++) {
        Boolean input = null;
        if (!arrayBlock.isNull(position)) {
            input = elementType.getBoolean(arrayBlock, position);
        }
        Boolean keep = function.apply(input);
        if (TRUE.equals(keep)) {
            elementType.appendTo(arrayBlock, position, resultBuilder);
        }
    }
    return resultBuilder.build();
}
Also used : BlockBuilder(io.prestosql.spi.block.BlockBuilder) TypeParameterSpecialization(io.prestosql.spi.function.TypeParameterSpecialization) TypeParameter(io.prestosql.spi.function.TypeParameter) SqlType(io.prestosql.spi.function.SqlType)

Aggregations

TypeParameter (io.prestosql.spi.function.TypeParameter)24 SqlType (io.prestosql.spi.function.SqlType)20 BlockBuilder (io.prestosql.spi.block.BlockBuilder)18 TypedSet (io.prestosql.operator.aggregation.TypedSet)6 TypeParameterSpecialization (io.prestosql.spi.function.TypeParameterSpecialization)5 Block (io.prestosql.spi.block.Block)4 HyperLogLog (io.airlift.stats.cardinality.HyperLogLog)3 PrestoException (io.prestosql.spi.PrestoException)3 InputFunction (io.prestosql.spi.function.InputFunction)3 ArrayType (io.prestosql.spi.type.ArrayType)3 RowType (io.prestosql.spi.type.RowType)3 Type (io.prestosql.spi.type.Type)3 Slice (io.airlift.slice.Slice)2 SqlNullable (io.prestosql.spi.function.SqlNullable)2 MapType (io.prestosql.spi.type.MapType)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 DictionaryBlock (io.prestosql.spi.block.DictionaryBlock)1 PageBuilderStatus (io.prestosql.spi.block.PageBuilderStatus)1 OperatorType (io.prestosql.spi.function.OperatorType)1