use of com.facebook.presto.annotation.UsedByGeneratedCode in project presto by prestodb.
the class ArrayConcatFunction method concat.
@UsedByGeneratedCode
public static Block concat(Type elementType, Object state, Block[] blocks) {
int resultPositionCount = 0;
// fast path when there is at most one non empty block
Block nonEmptyBlock = null;
for (int i = 0; i < blocks.length; i++) {
resultPositionCount += blocks[i].getPositionCount();
if (blocks[i].getPositionCount() > 0) {
nonEmptyBlock = blocks[i];
}
}
if (nonEmptyBlock == null) {
return blocks[0];
}
if (resultPositionCount == nonEmptyBlock.getPositionCount()) {
return nonEmptyBlock;
}
PageBuilder pageBuilder = (PageBuilder) state;
if (pageBuilder.isFull()) {
pageBuilder.reset();
}
BlockBuilder blockBuilder = pageBuilder.getBlockBuilder(0);
for (int blockIndex = 0; blockIndex < blocks.length; blockIndex++) {
Block block = blocks[blockIndex];
for (int i = 0; i < block.getPositionCount(); i++) {
elementType.appendTo(block, i, blockBuilder);
}
}
pageBuilder.declarePositions(resultPositionCount);
return blockBuilder.getRegion(blockBuilder.getPositionCount() - resultPositionCount, resultPositionCount);
}
use of com.facebook.presto.annotation.UsedByGeneratedCode 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.annotation.UsedByGeneratedCode 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.annotation.UsedByGeneratedCode 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.annotation.UsedByGeneratedCode in project presto by prestodb.
the class ZipFunction method zip.
@UsedByGeneratedCode
public static Block zip(List<Type> types, Block... arrays) {
int biggestCardinality = 0;
for (Block array : arrays) {
biggestCardinality = Math.max(biggestCardinality, array.getPositionCount());
}
RowType rowType = new RowType(types, Optional.empty());
BlockBuilder outputBuilder = rowType.createBlockBuilder(new BlockBuilderStatus(), biggestCardinality);
for (int outputPosition = 0; outputPosition < biggestCardinality; outputPosition++) {
BlockBuilder rowBuilder = outputBuilder.beginBlockEntry();
for (int fieldIndex = 0; fieldIndex < arrays.length; fieldIndex++) {
if (arrays[fieldIndex].getPositionCount() <= outputPosition) {
rowBuilder.appendNull();
} else {
types.get(fieldIndex).appendTo(arrays[fieldIndex], outputPosition, rowBuilder);
}
}
outputBuilder.closeEntry();
}
return outputBuilder.build();
}
Aggregations