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();
}
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();
}
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();
}
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();
}
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();
}
Aggregations