use of io.trino.annotation.UsedByGeneratedCode in project trino by trinodb.
the class ArrayJoin method arrayJoin.
@UsedByGeneratedCode
public static Slice arrayJoin(MethodHandle castFunction, Object state, ConnectorSession session, Block arrayBlock, Slice delimiter, Slice nullReplacement) {
PageBuilder pageBuilder = (PageBuilder) state;
if (pageBuilder.isFull()) {
pageBuilder.reset();
}
int numElements = arrayBlock.getPositionCount();
BlockBuilder blockBuilder = pageBuilder.getBlockBuilder(0);
boolean needsDelimiter = false;
for (int i = 0; i < numElements; i++) {
Slice value = null;
if (!arrayBlock.isNull(i)) {
try {
value = (Slice) castFunction.invokeExact(session, arrayBlock, i);
} catch (Throwable throwable) {
// Restore pageBuilder into a consistent state
blockBuilder.closeEntry();
pageBuilder.declarePosition();
throw new TrinoException(GENERIC_INTERNAL_ERROR, "Error casting array element to VARCHAR", throwable);
}
}
if (value == null) {
value = nullReplacement;
if (value == null) {
continue;
}
}
if (needsDelimiter) {
blockBuilder.writeBytes(delimiter, 0, delimiter.length());
}
blockBuilder.writeBytes(value, 0, value.length());
needsDelimiter = true;
}
blockBuilder.closeEntry();
pageBuilder.declarePosition();
return VARCHAR.getSlice(blockBuilder, blockBuilder.getPositionCount() - 1);
}
use of io.trino.annotation.UsedByGeneratedCode in project trino by trinodb.
the class ArrayConcatUtils method appendElement.
@UsedByGeneratedCode
public static Block appendElement(Type elementType, Block block, long value) {
BlockBuilder blockBuilder = elementType.createBlockBuilder(null, 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 io.trino.annotation.UsedByGeneratedCode in project trino by trinodb.
the class ArrayConcatUtils method prependElement.
@UsedByGeneratedCode
public static Block prependElement(Type elementType, boolean value, Block block) {
BlockBuilder blockBuilder = elementType.createBlockBuilder(null, block.getPositionCount() + 1);
elementType.writeBoolean(blockBuilder, value);
for (int i = 0; i < block.getPositionCount(); i++) {
elementType.appendTo(block, i, blockBuilder);
}
return blockBuilder.build();
}
use of io.trino.annotation.UsedByGeneratedCode in project trino by trinodb.
the class ArrayConcatUtils method appendElement.
@UsedByGeneratedCode
public static Block appendElement(Type elementType, Block block, double value) {
BlockBuilder blockBuilder = elementType.createBlockBuilder(null, block.getPositionCount() + 1);
for (int i = 0; i < block.getPositionCount(); i++) {
elementType.appendTo(block, i, blockBuilder);
}
elementType.writeDouble(blockBuilder, value);
return blockBuilder.build();
}
use of io.trino.annotation.UsedByGeneratedCode in project trino by trinodb.
the class ArrayConcatUtils method prependElement.
@UsedByGeneratedCode
public static Block prependElement(Type elementType, long value, Block block) {
BlockBuilder blockBuilder = elementType.createBlockBuilder(null, block.getPositionCount() + 1);
elementType.writeLong(blockBuilder, value);
for (int i = 0; i < block.getPositionCount(); i++) {
elementType.appendTo(block, i, blockBuilder);
}
return blockBuilder.build();
}
Aggregations