use of com.facebook.presto.spi.block.BlockBuilderStatus in project presto by prestodb.
the class TestJsonType method createTestBlock.
public static Block createTestBlock() {
BlockBuilder blockBuilder = JSON.createBlockBuilder(new BlockBuilderStatus(), 1);
Slice slice = Slices.utf8Slice("{\"x\":1, \"y\":2}");
JSON.writeSlice(blockBuilder, slice);
return blockBuilder.build();
}
use of com.facebook.presto.spi.block.BlockBuilderStatus in project presto by prestodb.
the class MLFunctions method featuresHelper.
private static Block featuresHelper(double... features) {
BlockBuilder blockBuilder = new InterleavedBlockBuilder(ImmutableList.of(BigintType.BIGINT, DoubleType.DOUBLE), new BlockBuilderStatus(), features.length);
for (int i = 0; i < features.length; i++) {
BigintType.BIGINT.writeLong(blockBuilder, i);
DoubleType.DOUBLE.writeDouble(blockBuilder, features[i]);
}
return blockBuilder.build();
}
use of com.facebook.presto.spi.block.BlockBuilderStatus in project presto by prestodb.
the class DecimalStreamReader method readBlock.
@Override
public Block readBlock(Type type) throws IOException {
DecimalType decimalType = (DecimalType) type;
if (!rowGroupOpen) {
openRowGroup();
}
seekToOffset();
allocateVectors();
BlockBuilder builder = decimalType.createBlockBuilder(new BlockBuilderStatus(), nextBatchSize);
if (presentStream == null) {
if (decimalStream == null) {
throw new OrcCorruptionException("Value is not null but decimal stream is not present");
}
if (scaleStream == null) {
throw new OrcCorruptionException("Value is not null but scale stream is not present");
}
Arrays.fill(nullVector, false);
scaleStream.nextLongVector(nextBatchSize, scaleVector);
if (decimalType.isShort()) {
decimalStream.nextShortDecimalVector(nextBatchSize, builder, decimalType, scaleVector);
} else {
decimalStream.nextLongDecimalVector(nextBatchSize, builder, decimalType, scaleVector);
}
} else {
int nullValues = presentStream.getUnsetBits(nextBatchSize, nullVector);
if (nullValues != nextBatchSize) {
if (decimalStream == null) {
throw new OrcCorruptionException("Value is not null but decimal stream is not present");
}
if (scaleStream == null) {
throw new OrcCorruptionException("Value is not null but scale stream is not present");
}
scaleStream.nextLongVector(nextBatchSize, scaleVector, nullVector);
if (decimalType.isShort()) {
decimalStream.nextShortDecimalVector(nextBatchSize, builder, decimalType, scaleVector, nullVector);
} else {
decimalStream.nextLongDecimalVector(nextBatchSize, builder, decimalType, scaleVector, nullVector);
}
} else {
for (int i = 0; i < nextBatchSize; i++) {
builder.appendNull();
}
}
}
readOffset = 0;
nextBatchSize = 0;
return builder.build();
}
use of com.facebook.presto.spi.block.BlockBuilderStatus in project presto by prestodb.
the class DoubleStreamReader method readBlock.
@Override
public Block readBlock(Type type) throws IOException {
if (!rowGroupOpen) {
openRowGroup();
}
if (readOffset > 0) {
if (presentStream != null) {
// skip ahead the present bit reader, but count the set bits
// and use this as the skip size for the data reader
readOffset = presentStream.countBitsSet(readOffset);
}
if (readOffset > 0) {
if (dataStream == null) {
throw new OrcCorruptionException("Value is not null but data stream is not present");
}
dataStream.skip(readOffset);
}
}
BlockBuilder builder = type.createBlockBuilder(new BlockBuilderStatus(), nextBatchSize);
if (presentStream == null) {
if (dataStream == null) {
throw new OrcCorruptionException("Value is not null but data stream is not present");
}
dataStream.nextVector(type, nextBatchSize, builder);
} else {
if (nullVector.length < nextBatchSize) {
nullVector = new boolean[nextBatchSize];
}
int nullValues = presentStream.getUnsetBits(nextBatchSize, nullVector);
if (nullValues != nextBatchSize) {
if (dataStream == null) {
throw new OrcCorruptionException("Value is not null but data stream is not present");
}
dataStream.nextVector(type, nextBatchSize, builder, nullVector);
} else {
for (int i = 0; i < nextBatchSize; i++) {
builder.appendNull();
}
}
}
readOffset = 0;
nextBatchSize = 0;
return builder.build();
}
use of com.facebook.presto.spi.block.BlockBuilderStatus in project presto by prestodb.
the class ListStreamReader method readBlock.
@Override
public Block readBlock(Type type) throws IOException {
if (!rowGroupOpen) {
openRowGroup();
}
if (readOffset > 0) {
if (presentStream != null) {
// skip ahead the present bit reader, but count the set bits
// and use this as the skip size for the data reader
readOffset = presentStream.countBitsSet(readOffset);
}
if (readOffset > 0) {
if (lengthStream == null) {
throw new OrcCorruptionException("Value is not null but data stream is not present");
}
long elementSkipSize = lengthStream.sum(readOffset);
elementStreamReader.prepareNextRead(toIntExact(elementSkipSize));
}
}
// The length vector could be reused, but this simplifies the code below by
// taking advantage of null entries being initialized to zero. The vector
// could be reinitialized for each loop, but that is likely just as expensive
// as allocating a new array
int[] lengthVector = new int[nextBatchSize];
boolean[] nullVector = new boolean[nextBatchSize];
if (presentStream == null) {
if (lengthStream == null) {
throw new OrcCorruptionException("Value is not null but data stream is not present");
}
lengthStream.nextIntVector(nextBatchSize, lengthVector);
} else {
int nullValues = presentStream.getUnsetBits(nextBatchSize, nullVector);
if (nullValues != nextBatchSize) {
if (lengthStream == null) {
throw new OrcCorruptionException("Value is not null but data stream is not present");
}
lengthStream.nextIntVector(nextBatchSize, lengthVector, nullVector);
}
}
int[] offsets = new int[nextBatchSize + 1];
for (int i = 1; i < offsets.length; i++) {
int length = lengthVector[i - 1];
offsets[i] = offsets[i - 1] + length;
}
Type elementType = type.getTypeParameters().get(0);
int elementCount = offsets[offsets.length - 1];
Block elements;
if (elementCount > 0) {
elementStreamReader.prepareNextRead(elementCount);
elements = elementStreamReader.readBlock(elementType);
} else {
elements = elementType.createBlockBuilder(new BlockBuilderStatus(), 0).build();
}
ArrayBlock arrayBlock = new ArrayBlock(nextBatchSize, nullVector, offsets, elements);
readOffset = 0;
nextBatchSize = 0;
return arrayBlock;
}
Aggregations