use of com.facebook.presto.spi.block.BlockBuilder 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.BlockBuilder 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.BlockBuilder 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();
}
use of com.facebook.presto.spi.block.BlockBuilder in project presto by prestodb.
the class StructEncoding method decodeValueInto.
@Override
public void decodeValueInto(BlockBuilder builder, Slice slice, int offset, int length) {
int fieldId = 0;
int nullByte = 0;
int elementOffset = offset;
BlockBuilder rowBuilder = builder.beginBlockEntry();
while (fieldId < structFields.size() && elementOffset < offset + length) {
BinaryColumnEncoding field = structFields.get(fieldId);
// null byte prefixes every 8 fields
if ((fieldId % 8) == 0) {
nullByte = slice.getByte(elementOffset);
elementOffset++;
}
// read field
if ((nullByte & (1 << (fieldId % 8))) != 0) {
int valueOffset = field.getValueOffset(slice, elementOffset);
int valueLength = field.getValueLength(slice, elementOffset);
field.decodeValueInto(rowBuilder, slice, elementOffset + valueOffset, valueLength);
elementOffset = elementOffset + valueOffset + valueLength;
} else {
rowBuilder.appendNull();
}
fieldId++;
}
// so we fill with nulls
while (fieldId < structFields.size()) {
rowBuilder.appendNull();
fieldId++;
}
builder.closeEntry();
}
use of com.facebook.presto.spi.block.BlockBuilder in project presto by prestodb.
the class BlockEncoding method decodeColumn.
@Override
public final Block decodeColumn(ColumnData columnData) throws RcFileCorruptionException {
int size = columnData.rowCount();
Slice slice = columnData.getSlice();
BlockBuilder builder = type.createBlockBuilder(new BlockBuilderStatus(), size);
for (int i = 0; i < size; i++) {
int length = columnData.getLength(i);
int offset = columnData.getOffset(i);
if (!isNullSequence(slice, offset, length)) {
decodeValueInto(1, builder, slice, offset, length);
} else {
builder.appendNull();
}
}
return builder.build();
}
Aggregations