use of com.facebook.presto.common.block.BlockBuilder in project presto by prestodb.
the class TestTinyintArrayType method getGreaterValue.
@Override
protected Object getGreaterValue(Object value) {
Block block = (Block) value;
BlockBuilder blockBuilder = TINYINT.createBlockBuilder(null, block.getPositionCount() + 1);
for (int i = 0; i < block.getPositionCount(); i++) {
TINYINT.appendTo(block, i, blockBuilder);
}
TINYINT.writeLong(blockBuilder, 1L);
return blockBuilder.build();
}
use of com.facebook.presto.common.block.BlockBuilder in project presto by prestodb.
the class TestUuidOperators method hashFromType.
private static long hashFromType(String uuidString) {
BlockBuilder blockBuilder = UUID.createBlockBuilder(null, 1);
UUID.writeSlice(blockBuilder, castFromVarcharToUuid(utf8Slice(uuidString)));
Block block = blockBuilder.build();
return UUID.hash(block, 0);
}
use of com.facebook.presto.common.block.BlockBuilder in project presto by prestodb.
the class MongoPageSource method getNextPage.
@Override
public Page getNextPage() {
verify(pageBuilder.isEmpty());
for (int i = 0; i < ROWS_PER_REQUEST; i++) {
if (!cursor.hasNext()) {
finished = true;
break;
}
currentDoc = cursor.next();
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);
}
}
Page page = pageBuilder.build();
pageBuilder.reset();
completedBytes += page.getSizeInBytes();
completedPositions += page.getPositionCount();
return page;
}
use of com.facebook.presto.common.block.BlockBuilder in project presto by prestodb.
the class TestDictionaryColumnWriter method testDictionary.
private List<StripeFooter> testDictionary(Type type, OrcEncoding encoding, OrcWriterOptions orcWriterOptions, DirectConversionTester directConversionTester, List<?> values) throws IOException {
List<Type> types = ImmutableList.of(type);
try (TempFile tempFile = new TempFile()) {
OrcWriter writer = createOrcWriter(tempFile.getFile(), encoding, ZSTD, Optional.empty(), types, orcWriterOptions, new OrcWriterStats());
int index = 0;
int batchId = 0;
while (index < values.size()) {
int end = Math.min(index + BATCH_ROWS, values.size());
BlockBuilder blockBuilder = type.createBlockBuilder(null, end - index);
appendListToBlock(type, values, blockBuilder, index, end);
Block[] blocks = new Block[] { blockBuilder.build() };
writer.write(new Page(blocks));
directConversionTester.validate(batchId, writer);
batchId++;
index = end;
}
writer.close();
writer.validate(new FileOrcDataSource(tempFile.getFile(), new DataSize(1, MEGABYTE), new DataSize(1, MEGABYTE), new DataSize(1, MEGABYTE), true));
index = 0;
try (OrcSelectiveRecordReader reader = createCustomOrcSelectiveRecordReader(tempFile, encoding, OrcPredicate.TRUE, type, INITIAL_BATCH_SIZE, true, false)) {
while (index < values.size()) {
Page page = reader.getNextPage();
if (page == null) {
break;
}
Block block = page.getBlock(0).getLoadedBlock();
index = verifyBlock(type, values, index, block);
}
assertEquals(index, values.size());
}
return OrcTester.getStripes(tempFile.getFile(), encoding);
}
}
use of com.facebook.presto.common.block.BlockBuilder in project presto by prestodb.
the class TestDictionaryColumnWriter method appendListToBlock.
private void appendListToBlock(Type type, List<?> values, BlockBuilder blockBuilder, int startIndex, int endIndex) {
while (startIndex < endIndex) {
Object value = values.get(startIndex++);
if (value == null) {
blockBuilder.appendNull();
} else {
if (isArrayType(type)) {
List<?> childList = (List<?>) value;
BlockBuilder childBlockBuilder = blockBuilder.beginBlockEntry();
appendListToBlock(type.getTypeParameters().get(0), childList, childBlockBuilder, 0, childList.size());
blockBuilder.closeEntry();
} else if (type.equals(VARCHAR)) {
type.writeSlice(blockBuilder, utf8Slice((String) value));
} else {
Number number = (Number) value;
type.writeLong(blockBuilder, number.longValue());
}
}
}
}
Aggregations