Search in sources :

Example 1 with TypeParameterSpecialization

use of com.facebook.presto.spi.function.TypeParameterSpecialization in project presto by prestodb.

the class ArrayLessThanOrEqualOperator method lessThanOrEqualLong.

@TypeParameter("E")
@TypeParameterSpecialization(name = "E", nativeContainerType = long.class)
@SqlType(StandardTypes.BOOLEAN)
public static boolean lessThanOrEqualLong(@OperatorDependency(operator = LESS_THAN, returnType = StandardTypes.BOOLEAN, argumentTypes = { "E", "E" }) MethodHandle lessThanFunction, @TypeParameter("E") Type type, @SqlType("array(E)") Block leftArray, @SqlType("array(E)") Block rightArray) {
    int len = Math.min(leftArray.getPositionCount(), rightArray.getPositionCount());
    int index = 0;
    while (index < len) {
        checkElementNotNull(leftArray.isNull(index), ARRAY_NULL_ELEMENT_MSG);
        checkElementNotNull(rightArray.isNull(index), ARRAY_NULL_ELEMENT_MSG);
        long leftElement = type.getLong(leftArray, index);
        long rightElement = type.getLong(rightArray, index);
        try {
            if ((boolean) lessThanFunction.invokeExact(leftElement, rightElement)) {
                return true;
            }
            if ((boolean) lessThanFunction.invokeExact(rightElement, leftElement)) {
                return false;
            }
        } catch (Throwable t) {
            Throwables.propagateIfInstanceOf(t, Error.class);
            Throwables.propagateIfInstanceOf(t, PrestoException.class);
            throw new PrestoException(GENERIC_INTERNAL_ERROR, t);
        }
        index++;
    }
    return leftArray.getPositionCount() <= rightArray.getPositionCount();
}
Also used : PrestoException(com.facebook.presto.spi.PrestoException) TypeParameterSpecialization(com.facebook.presto.spi.function.TypeParameterSpecialization) TypeParameter(com.facebook.presto.spi.function.TypeParameter) SqlType(com.facebook.presto.spi.function.SqlType)

Example 2 with TypeParameterSpecialization

use of com.facebook.presto.spi.function.TypeParameterSpecialization in project presto by prestodb.

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)") MethodHandle function) {
    int positionCount = arrayBlock.getPositionCount();
    BlockBuilder resultBuilder = elementType.createBlockBuilder(new BlockBuilderStatus(), positionCount);
    for (int position = 0; position < positionCount; position++) {
        Long input = null;
        if (!arrayBlock.isNull(position)) {
            input = elementType.getLong(arrayBlock, position);
        }
        Boolean keep;
        try {
            keep = (Boolean) function.invokeExact(input);
        } catch (Throwable throwable) {
            throw Throwables.propagate(throwable);
        }
        if (TRUE.equals(keep)) {
            elementType.appendTo(arrayBlock, position, resultBuilder);
        }
    }
    return resultBuilder.build();
}
Also used : BlockBuilder(com.facebook.presto.spi.block.BlockBuilder) BlockBuilderStatus(com.facebook.presto.spi.block.BlockBuilderStatus) TypeParameterSpecialization(com.facebook.presto.spi.function.TypeParameterSpecialization) TypeParameter(com.facebook.presto.spi.function.TypeParameter) SqlType(com.facebook.presto.spi.function.SqlType)

Example 3 with TypeParameterSpecialization

use of com.facebook.presto.spi.function.TypeParameterSpecialization in project presto by prestodb.

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)") MethodHandle function) {
    int positionCount = arrayBlock.getPositionCount();
    BlockBuilder resultBuilder = elementType.createBlockBuilder(new BlockBuilderStatus(), positionCount);
    for (int position = 0; position < positionCount; position++) {
        Boolean input = null;
        if (!arrayBlock.isNull(position)) {
            input = elementType.getBoolean(arrayBlock, position);
        }
        Boolean keep;
        try {
            keep = (Boolean) function.invokeExact(input);
        } catch (Throwable throwable) {
            throw Throwables.propagate(throwable);
        }
        if (TRUE.equals(keep)) {
            elementType.appendTo(arrayBlock, position, resultBuilder);
        }
    }
    return resultBuilder.build();
}
Also used : BlockBuilder(com.facebook.presto.spi.block.BlockBuilder) BlockBuilderStatus(com.facebook.presto.spi.block.BlockBuilderStatus) TypeParameterSpecialization(com.facebook.presto.spi.function.TypeParameterSpecialization) TypeParameter(com.facebook.presto.spi.function.TypeParameter) SqlType(com.facebook.presto.spi.function.SqlType)

Example 4 with TypeParameterSpecialization

use of com.facebook.presto.spi.function.TypeParameterSpecialization in project presto by prestodb.

the class ArrayFilterFunction method filterVoid.

@TypeParameter("T")
@TypeParameterSpecialization(name = "T", nativeContainerType = void.class)
@SqlType("array(T)")
public static Block filterVoid(@TypeParameter("T") Type elementType, @SqlType("array(T)") Block arrayBlock, @SqlType("function(T, boolean)") MethodHandle function) {
    int positionCount = arrayBlock.getPositionCount();
    BlockBuilder resultBuilder = elementType.createBlockBuilder(new BlockBuilderStatus(), positionCount);
    for (int position = 0; position < positionCount; position++) {
        Boolean keep;
        try {
            keep = (Boolean) function.invokeExact(null);
        } catch (Throwable throwable) {
            throw Throwables.propagate(throwable);
        }
        if (TRUE.equals(keep)) {
            resultBuilder.appendNull();
        }
    }
    return resultBuilder.build();
}
Also used : BlockBuilder(com.facebook.presto.spi.block.BlockBuilder) BlockBuilderStatus(com.facebook.presto.spi.block.BlockBuilderStatus) TypeParameterSpecialization(com.facebook.presto.spi.function.TypeParameterSpecialization) TypeParameter(com.facebook.presto.spi.function.TypeParameter) SqlType(com.facebook.presto.spi.function.SqlType)

Example 5 with TypeParameterSpecialization

use of com.facebook.presto.spi.function.TypeParameterSpecialization in project presto by prestodb.

the class ArrayFilterFunction method filterDouble.

@TypeParameter("T")
@TypeParameterSpecialization(name = "T", nativeContainerType = double.class)
@SqlType("array(T)")
public static Block filterDouble(@TypeParameter("T") Type elementType, @SqlType("array(T)") Block arrayBlock, @SqlType("function(T, boolean)") MethodHandle function) {
    int positionCount = arrayBlock.getPositionCount();
    BlockBuilder resultBuilder = elementType.createBlockBuilder(new BlockBuilderStatus(), positionCount);
    for (int position = 0; position < positionCount; position++) {
        Double input = null;
        if (!arrayBlock.isNull(position)) {
            input = elementType.getDouble(arrayBlock, position);
        }
        Boolean keep;
        try {
            keep = (Boolean) function.invokeExact(input);
        } catch (Throwable throwable) {
            throw Throwables.propagate(throwable);
        }
        if (TRUE.equals(keep)) {
            elementType.appendTo(arrayBlock, position, resultBuilder);
        }
    }
    return resultBuilder.build();
}
Also used : BlockBuilder(com.facebook.presto.spi.block.BlockBuilder) BlockBuilderStatus(com.facebook.presto.spi.block.BlockBuilderStatus) TypeParameterSpecialization(com.facebook.presto.spi.function.TypeParameterSpecialization) TypeParameter(com.facebook.presto.spi.function.TypeParameter) SqlType(com.facebook.presto.spi.function.SqlType)

Aggregations

SqlType (com.facebook.presto.spi.function.SqlType)9 TypeParameter (com.facebook.presto.spi.function.TypeParameter)9 TypeParameterSpecialization (com.facebook.presto.spi.function.TypeParameterSpecialization)9 BlockBuilder (com.facebook.presto.spi.block.BlockBuilder)6 BlockBuilderStatus (com.facebook.presto.spi.block.BlockBuilderStatus)6 PrestoException (com.facebook.presto.spi.PrestoException)3 Block (com.facebook.presto.spi.block.Block)1 Slice (io.airlift.slice.Slice)1