Search in sources :

Example 6 with BlockBuilder

use of io.trino.spi.block.BlockBuilder in project trino by trinodb.

the class ArrayToArrayCast method filterBoolean.

@TypeParameter("F")
@TypeParameter("T")
@TypeParameterSpecialization(name = "T", nativeContainerType = boolean.class)
@SqlType("array(T)")
public static Block filterBoolean(@TypeParameter("T") Type resultType, @CastDependency(fromType = "F", toType = "T", convention = @Convention(arguments = BLOCK_POSITION, result = NULLABLE_RETURN, session = true)) MethodHandle cast, ConnectorSession session, @SqlType("array(F)") Block array) throws Throwable {
    int positionCount = array.getPositionCount();
    BlockBuilder resultBuilder = resultType.createBlockBuilder(null, positionCount);
    for (int position = 0; position < positionCount; position++) {
        if (!array.isNull(position)) {
            Boolean value = (Boolean) cast.invokeExact(session, array, position);
            if (value != null) {
                resultType.writeBoolean(resultBuilder, value);
                continue;
            }
        }
        resultBuilder.appendNull();
    }
    return resultBuilder.build();
}
Also used : BlockBuilder(io.trino.spi.block.BlockBuilder) TypeParameterSpecialization(io.trino.spi.function.TypeParameterSpecialization) TypeParameter(io.trino.spi.function.TypeParameter) SqlType(io.trino.spi.function.SqlType)

Example 7 with BlockBuilder

use of io.trino.spi.block.BlockBuilder in project trino by trinodb.

the class ArrayToArrayCast method filterDouble.

@TypeParameter("F")
@TypeParameter("T")
@TypeParameterSpecialization(name = "T", nativeContainerType = double.class)
@SqlType("array(T)")
public static Block filterDouble(@TypeParameter("T") Type resultType, @CastDependency(fromType = "F", toType = "T", convention = @Convention(arguments = BLOCK_POSITION, result = NULLABLE_RETURN, session = true)) MethodHandle cast, ConnectorSession session, @SqlType("array(F)") Block array) throws Throwable {
    int positionCount = array.getPositionCount();
    BlockBuilder resultBuilder = resultType.createBlockBuilder(null, positionCount);
    for (int position = 0; position < positionCount; position++) {
        if (!array.isNull(position)) {
            Double value = (Double) cast.invokeExact(session, array, position);
            if (value != null) {
                resultType.writeDouble(resultBuilder, value);
                continue;
            }
        }
        resultBuilder.appendNull();
    }
    return resultBuilder.build();
}
Also used : BlockBuilder(io.trino.spi.block.BlockBuilder) TypeParameterSpecialization(io.trino.spi.function.TypeParameterSpecialization) TypeParameter(io.trino.spi.function.TypeParameter) SqlType(io.trino.spi.function.SqlType)

Example 8 with BlockBuilder

use of io.trino.spi.block.BlockBuilder in project trino by trinodb.

the class ArrayUnionFunction method union.

@TypeParameter("E")
@SqlType("array(E)")
public static Block union(@TypeParameter("E") Type type, @OperatorDependency(operator = EQUAL, argumentTypes = { "E", "E" }, convention = @Convention(arguments = { BLOCK_POSITION, BLOCK_POSITION }, result = NULLABLE_RETURN)) BlockPositionEqual elementEqual, @OperatorDependency(operator = HASH_CODE, argumentTypes = "E", convention = @Convention(arguments = BLOCK_POSITION, result = FAIL_ON_NULL)) BlockPositionHashCode elementHashCode, @SqlType("array(E)") Block leftArray, @SqlType("array(E)") Block rightArray) {
    int leftArrayCount = leftArray.getPositionCount();
    int rightArrayCount = rightArray.getPositionCount();
    BlockBuilder distinctElementBlockBuilder = type.createBlockBuilder(null, leftArrayCount + rightArrayCount);
    TypedSet typedSet = createEqualityTypedSet(type, elementEqual, elementHashCode, distinctElementBlockBuilder, leftArrayCount + rightArrayCount, "array_union");
    for (int i = 0; i < leftArray.getPositionCount(); i++) {
        typedSet.add(leftArray, i);
    }
    for (int i = 0; i < rightArray.getPositionCount(); i++) {
        typedSet.add(rightArray, i);
    }
    return distinctElementBlockBuilder.build();
}
Also used : TypedSet.createEqualityTypedSet(io.trino.operator.aggregation.TypedSet.createEqualityTypedSet) TypedSet(io.trino.operator.aggregation.TypedSet) BlockBuilder(io.trino.spi.block.BlockBuilder) TypeParameter(io.trino.spi.function.TypeParameter) SqlType(io.trino.spi.function.SqlType)

Example 9 with BlockBuilder

use of io.trino.spi.block.BlockBuilder in project trino by trinodb.

the class ArrayConcatUtils method appendElement.

@UsedByGeneratedCode
public static Block appendElement(Type elementType, Block block, Object value) {
    BlockBuilder blockBuilder = elementType.createBlockBuilder(null, block.getPositionCount() + 1);
    for (int i = 0; i < block.getPositionCount(); i++) {
        elementType.appendTo(block, i, blockBuilder);
    }
    elementType.writeObject(blockBuilder, value);
    return blockBuilder.build();
}
Also used : BlockBuilder(io.trino.spi.block.BlockBuilder) UsedByGeneratedCode(io.trino.annotation.UsedByGeneratedCode)

Example 10 with BlockBuilder

use of io.trino.spi.block.BlockBuilder in project trino by trinodb.

the class ArrayConcatUtils method appendElement.

@UsedByGeneratedCode
public static Block appendElement(Type elementType, Block block, boolean value) {
    BlockBuilder blockBuilder = elementType.createBlockBuilder(null, block.getPositionCount() + 1);
    for (int i = 0; i < block.getPositionCount(); i++) {
        elementType.appendTo(block, i, blockBuilder);
    }
    elementType.writeBoolean(blockBuilder, value);
    return blockBuilder.build();
}
Also used : BlockBuilder(io.trino.spi.block.BlockBuilder) UsedByGeneratedCode(io.trino.annotation.UsedByGeneratedCode)

Aggregations

BlockBuilder (io.trino.spi.block.BlockBuilder)459 Block (io.trino.spi.block.Block)98 Test (org.testng.annotations.Test)89 Slice (io.airlift.slice.Slice)87 Type (io.trino.spi.type.Type)61 SqlType (io.trino.spi.function.SqlType)52 Page (io.trino.spi.Page)41 ArrayType (io.trino.spi.type.ArrayType)41 RowType (io.trino.spi.type.RowType)35 MapType (io.trino.spi.type.MapType)34 Map (java.util.Map)25 PageBuilder (io.trino.spi.PageBuilder)22 VarcharType (io.trino.spi.type.VarcharType)22 ScalarFunction (io.trino.spi.function.ScalarFunction)21 TypeParameter (io.trino.spi.function.TypeParameter)20 UsedByGeneratedCode (io.trino.annotation.UsedByGeneratedCode)19 TrinoException (io.trino.spi.TrinoException)18 RowBlockBuilder (io.trino.spi.block.RowBlockBuilder)18 VariableWidthBlockBuilder (io.trino.spi.block.VariableWidthBlockBuilder)17 Description (io.trino.spi.function.Description)16