use of com.facebook.presto.spi.block.BlockBuilderStatus in project presto by prestodb.
the class ArrayConcatUtils method appendElement.
@UsedByGeneratedCode
public static Block appendElement(Type elementType, Block block, boolean value) {
BlockBuilder blockBuilder = elementType.createBlockBuilder(new BlockBuilderStatus(), block.getPositionCount() + 1);
for (int i = 0; i < block.getPositionCount(); i++) {
elementType.appendTo(block, i, blockBuilder);
}
elementType.writeBoolean(blockBuilder, value);
return blockBuilder.build();
}
use of com.facebook.presto.spi.block.BlockBuilderStatus in project presto by prestodb.
the class JsonToArrayCast method toArray.
@UsedByGeneratedCode
public static Block toArray(Type arrayType, ConnectorSession connectorSession, Slice json) {
try {
List<?> array = (List<?>) stackRepresentationToObject(connectorSession, json, arrayType);
if (array == null) {
return null;
}
Type elementType = ((ArrayType) arrayType).getElementType();
BlockBuilder blockBuilder = elementType.createBlockBuilder(new BlockBuilderStatus(), array.size());
for (Object element : array) {
appendToBlockBuilder(elementType, element, blockBuilder);
}
return blockBuilder.build();
} catch (RuntimeException e) {
throw new PrestoException(INVALID_CAST_ARGUMENT, "Value cannot be cast to " + arrayType, e);
}
}
use of com.facebook.presto.spi.block.BlockBuilderStatus in project presto by prestodb.
the class ArrayConcatUtils method appendElement.
@UsedByGeneratedCode
public static Block appendElement(Type elementType, Block block, long value) {
BlockBuilder blockBuilder = elementType.createBlockBuilder(new BlockBuilderStatus(), block.getPositionCount() + 1);
for (int i = 0; i < block.getPositionCount(); i++) {
elementType.appendTo(block, i, blockBuilder);
}
elementType.writeLong(blockBuilder, value);
return blockBuilder.build();
}
use of com.facebook.presto.spi.block.BlockBuilderStatus in project presto by prestodb.
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);
BlockBuilder distinctElementBlockBuilder = type.createBlockBuilder(new BlockBuilderStatus(), 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();
}
use of com.facebook.presto.spi.block.BlockBuilderStatus 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();
}
Aggregations