use of com.facebook.presto.spi.block.BlockBuilderStatus in project presto by prestodb.
the class MapTransformValueFunction method transform.
public static Block transform(Type keyType, Type valueType, Type transformedValueType, Block block, MethodHandle function) {
int positionCount = block.getPositionCount();
BlockBuilder resultBuilder = new InterleavedBlockBuilder(ImmutableList.of(keyType, transformedValueType), new BlockBuilderStatus(), positionCount);
for (int position = 0; position < positionCount; position += 2) {
Object key = readNativeValue(keyType, block, position);
Object value = readNativeValue(valueType, block, position + 1);
Object transformedValue;
try {
transformedValue = function.invoke(key, value);
} catch (Throwable throwable) {
throw Throwables.propagate(throwable);
}
keyType.appendTo(block, position, resultBuilder);
writeNativeValue(transformedValueType, resultBuilder, transformedValue);
}
return resultBuilder.build();
}
use of com.facebook.presto.spi.block.BlockBuilderStatus in project presto by prestodb.
the class RowEqualOperator method equals.
public static boolean equals(Type rowType, Block leftRow, Block rightRow) {
// TODO: Fix this. It feels very inefficient and unnecessary to wrap and unwrap with Block
BlockBuilder leftBlockBuilder = rowType.createBlockBuilder(new BlockBuilderStatus(), 1);
BlockBuilder rightBlockBuilder = rowType.createBlockBuilder(new BlockBuilderStatus(), 1);
rowType.writeObject(leftBlockBuilder, leftRow);
rowType.writeObject(rightBlockBuilder, rightRow);
return rowType.equalTo(leftBlockBuilder.build(), 0, rightBlockBuilder.build(), 0);
}
use of com.facebook.presto.spi.block.BlockBuilderStatus in project presto by prestodb.
the class MapConstructor method createMap.
@UsedByGeneratedCode
public static Block createMap(MapType mapType, Block keyBlock, Block valueBlock) {
BlockBuilder blockBuilder = new InterleavedBlockBuilder(mapType.getTypeParameters(), new BlockBuilderStatus(), keyBlock.getPositionCount() * 2);
checkCondition(keyBlock.getPositionCount() == valueBlock.getPositionCount(), INVALID_FUNCTION_ARGUMENT, "Key and value arrays must be the same length");
for (int i = 0; i < keyBlock.getPositionCount(); i++) {
if (keyBlock.isNull(i)) {
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "map key cannot be null");
}
mapType.getKeyType().appendTo(keyBlock, i, blockBuilder);
mapType.getValueType().appendTo(valueBlock, i, blockBuilder);
}
return blockBuilder.build();
}
use of com.facebook.presto.spi.block.BlockBuilderStatus in project presto by prestodb.
the class ByteEncoding method decodeColumn.
@Override
public Block decodeColumn(ColumnData columnData) {
int size = columnData.rowCount();
BlockBuilder builder = type.createBlockBuilder(new BlockBuilderStatus(), size);
Slice slice = columnData.getSlice();
for (int i = 0; i < size; i++) {
int length = columnData.getLength(i);
if (length != 0) {
checkState(length == SIZE_OF_BYTE, "Bytes should be 1 byte");
type.writeLong(builder, slice.getByte(columnData.getOffset(i)));
} else {
builder.appendNull();
}
}
return builder.build();
}
use of com.facebook.presto.spi.block.BlockBuilderStatus in project presto by prestodb.
the class StringEncoding method decodeColumn.
@Override
public Block decodeColumn(ColumnData columnData) {
int size = columnData.rowCount();
BlockBuilder builder = type.createBlockBuilder(new BlockBuilderStatus(), size);
Slice slice = columnData.getSlice();
for (int i = 0; i < size; i++) {
int length = columnData.getLength(i);
if (length > 0) {
int offset = columnData.getOffset(i);
if ((length == 1) && slice.getByte(offset) == HIVE_EMPTY_STRING_BYTE) {
type.writeSlice(builder, EMPTY_SLICE);
} else {
length = calculateTruncationLength(type, slice, offset, length);
type.writeSlice(builder, slice.slice(offset, length));
}
} else {
builder.appendNull();
}
}
return builder.build();
}
Aggregations