Search in sources :

Example 1 with TypeParameterSpecialization

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

the class FunctionsParserHelper method getDeclaredSpecializedTypeParameters.

public static Map<String, Class<?>> getDeclaredSpecializedTypeParameters(Method method, Set<TypeParameter> typeParameters) {
    Map<String, Class<?>> specializedTypeParameters = new HashMap<>();
    TypeParameterSpecialization[] typeParameterSpecializations = method.getAnnotationsByType(TypeParameterSpecialization.class);
    ImmutableSet<String> typeParameterNames = typeParameters.stream().map(TypeParameter::value).collect(toImmutableSet());
    for (TypeParameterSpecialization specialization : typeParameterSpecializations) {
        checkArgument(typeParameterNames.contains(specialization.name()), "%s does not match any declared type parameters (%s) [%s]", specialization.name(), typeParameters, method);
        Class<?> existingSpecialization = specializedTypeParameters.get(specialization.name());
        checkArgument(existingSpecialization == null || existingSpecialization.equals(specialization.nativeContainerType()), "%s has conflicting specializations %s and %s [%s]", specialization.name(), existingSpecialization, specialization.nativeContainerType(), method);
        specializedTypeParameters.put(specialization.name(), specialization.nativeContainerType());
    }
    return specializedTypeParameters;
}
Also used : TypeParameterSpecialization(io.prestosql.spi.function.TypeParameterSpecialization) HashMap(java.util.HashMap)

Example 2 with TypeParameterSpecialization

use of io.prestosql.spi.function.TypeParameterSpecialization 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 3 with TypeParameterSpecialization

use of io.prestosql.spi.function.TypeParameterSpecialization 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 4 with TypeParameterSpecialization

use of io.prestosql.spi.function.TypeParameterSpecialization 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 5 with TypeParameterSpecialization

use of io.prestosql.spi.function.TypeParameterSpecialization 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

TypeParameterSpecialization (io.prestosql.spi.function.TypeParameterSpecialization)6 BlockBuilder (io.prestosql.spi.block.BlockBuilder)5 SqlType (io.prestosql.spi.function.SqlType)5 TypeParameter (io.prestosql.spi.function.TypeParameter)5 Slice (io.airlift.slice.Slice)1 Block (io.prestosql.spi.block.Block)1 HashMap (java.util.HashMap)1