use of com.facebook.presto.spi.block.BlockBuilder 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.BlockBuilder 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.BlockBuilder in project presto by prestodb.
the class MongoPageSource method getNextPage.
@Override
public Page getNextPage() {
PageBuilder pageBuilder = new PageBuilder(columnTypes);
count = 0;
for (int i = 0; i < ROWS_PER_REQUEST; i++) {
if (!cursor.hasNext()) {
finished = true;
break;
}
currentDoc = cursor.next();
count++;
pageBuilder.declarePosition();
for (int column = 0; column < columnTypes.size(); column++) {
BlockBuilder output = pageBuilder.getBlockBuilder(column);
appendTo(columnTypes.get(column), currentDoc.get(columnNames.get(column)), output);
}
}
totalCount += count;
return pageBuilder.build();
}
use of com.facebook.presto.spi.block.BlockBuilder in project presto by prestodb.
the class TestLearnAggregations method assertLearnClassifer.
private static void assertLearnClassifer(Accumulator accumulator) throws Exception {
accumulator.addInput(getPage());
BlockBuilder finalOut = accumulator.getFinalType().createBlockBuilder(new BlockBuilderStatus(), 1);
accumulator.evaluateFinal(finalOut);
Block block = finalOut.build();
Slice slice = accumulator.getFinalType().getSlice(block, 0);
Model deserialized = ModelUtils.deserialize(slice);
assertNotNull(deserialized, "deserialization failed");
assertTrue(deserialized instanceof Classifier, "deserialized model is not a classifier");
}
use of com.facebook.presto.spi.block.BlockBuilder in project presto by prestodb.
the class TestLearnAggregations method mapSliceOf.
private static Block mapSliceOf(Type keyType, Type valueType, Object key, Object value) {
BlockBuilder blockBuilder = new InterleavedBlockBuilder(ImmutableList.of(keyType, valueType), new BlockBuilderStatus(), 100);
appendToBlockBuilder(keyType, key, blockBuilder);
appendToBlockBuilder(valueType, value, blockBuilder);
return blockBuilder.build();
}
Aggregations