use of com.facebook.presto.common.block.BlockBuilder in project presto by prestodb.
the class ShortEncoding method decodeColumn.
@Override
public Block decodeColumn(ColumnData columnData) {
int size = columnData.rowCount();
BlockBuilder builder = type.createBlockBuilder(null, size);
Slice slice = columnData.getSlice();
for (int i = 0; i < size; i++) {
int length = columnData.getLength(i);
if (length != 0) {
checkState(length == SIZE_OF_SHORT, "Short should be 2 bytes");
type.writeLong(builder, (long) Short.reverseBytes(slice.getShort(columnData.getOffset(i))));
} else {
builder.appendNull();
}
}
return builder.build();
}
use of com.facebook.presto.common.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.common.block.BlockBuilder in project presto by prestodb.
the class DateEncoding method decodeColumn.
@Override
public Block decodeColumn(ColumnData columnData) {
int size = columnData.rowCount();
BlockBuilder builder = type.createBlockBuilder(null, size);
Slice slice = columnData.getSlice();
for (int i = 0; i < size; i++) {
int offset = columnData.getOffset(i);
int length = columnData.getLength(i);
if (length == 0) {
builder.appendNull();
} else {
long daysSinceEpoch = readVInt(slice, offset, length);
type.writeLong(builder, toIntExact(daysSinceEpoch));
}
}
return builder.build();
}
use of com.facebook.presto.common.block.BlockBuilder in project presto by prestodb.
the class MapEncoding method decodeValueInto.
@Override
public void decodeValueInto(BlockBuilder builder, Slice slice, int offset, int length) {
// entries in list
int entries = toIntExact(readVInt(slice, offset));
offset += decodeVIntSize(slice.getByte(offset));
// null bytes
int nullByteCur = offset;
int nullByteEnd = offset + (entries * 2 + 7) / 8;
// read elements starting after null bytes
int elementOffset = nullByteEnd;
BlockBuilder mapBuilder = builder.beginBlockEntry();
for (int i = 0; i < entries; i++) {
// read key
boolean nullKey;
if ((slice.getByte(nullByteCur) & (1 << ((i * 2) % 8))) != 0) {
int keyOffset = keyReader.getValueOffset(slice, elementOffset);
int keyLength = keyReader.getValueLength(slice, elementOffset);
keyReader.decodeValueInto(mapBuilder, slice, elementOffset + keyOffset, keyLength);
nullKey = false;
elementOffset = elementOffset + keyOffset + keyLength;
} else {
nullKey = true;
}
// read value
if ((slice.getByte(nullByteCur) & (1 << ((i * 2 + 1) % 8))) != 0) {
int valueOffset = valueReader.getValueOffset(slice, elementOffset);
int valueLength = valueReader.getValueLength(slice, elementOffset);
// ignore entries with a null key
if (!nullKey) {
valueReader.decodeValueInto(mapBuilder, slice, elementOffset + valueOffset, valueLength);
}
elementOffset = elementOffset + valueOffset + valueLength;
} else {
// ignore entries with a null key
if (!nullKey) {
mapBuilder.appendNull();
}
}
// move onto the next null byte
if (3 == (i % 4)) {
nullByteCur++;
}
}
builder.closeEntry();
}
use of com.facebook.presto.common.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(null, 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