use of com.facebook.presto.common.PageBuilder in project presto by prestodb.
the class ParquetTester method writeParquetFileFromPresto.
public static void writeParquetFileFromPresto(File outputFile, List<Type> types, List<String> columnNames, Iterator<?>[] values, int size, CompressionCodecName compressionCodecName) throws Exception {
checkArgument(types.size() == columnNames.size() && types.size() == values.length);
ParquetWriter writer = new ParquetWriter(new FileOutputStream(outputFile), columnNames, types, ParquetWriterOptions.builder().setMaxPageSize(DataSize.succinctBytes(100)).setMaxBlockSize(DataSize.succinctBytes(100000)).build(), compressionCodecName.getHadoopCompressionCodecClassName());
PageBuilder pageBuilder = new PageBuilder(types);
for (int i = 0; i < types.size(); ++i) {
Type type = types.get(i);
Iterator<?> iterator = values[i];
BlockBuilder blockBuilder = pageBuilder.getBlockBuilder(i);
for (int j = 0; j < size; ++j) {
checkState(iterator.hasNext());
Object value = iterator.next();
writeValue(type, blockBuilder, value);
}
}
pageBuilder.declarePositions(size);
writer.write(pageBuilder.build());
writer.close();
}
use of com.facebook.presto.common.PageBuilder in project presto by prestodb.
the class InMemoryHashAggregationBuilder method buildResult.
private WorkProcessor<Page> buildResult(IntIterator groupIds) {
final PageBuilder pageBuilder = new PageBuilder(buildTypes());
return WorkProcessor.create(() -> {
if (!groupIds.hasNext()) {
return ProcessState.finished();
}
pageBuilder.reset();
List<Type> types = groupByHash.getTypes();
while (!pageBuilder.isFull() && groupIds.hasNext()) {
int groupId = groupIds.nextInt();
groupByHash.appendValuesTo(groupId, pageBuilder, 0);
pageBuilder.declarePosition();
for (int i = 0; i < aggregators.size(); i++) {
Aggregator aggregator = aggregators.get(i);
BlockBuilder output = pageBuilder.getBlockBuilder(types.size() + i);
aggregator.evaluate(groupId, output);
}
}
return ProcessState.ofResult(pageBuilder.build());
});
}
use of com.facebook.presto.common.PageBuilder in project presto by prestodb.
the class GenericPartitioningSpiller method partitionPage.
private synchronized IntArrayList partitionPage(Page page, IntPredicate spillPartitionMask) {
IntArrayList unspilledPositions = new IntArrayList();
for (int position = 0; position < page.getPositionCount(); position++) {
int partition = partitionFunction.getPartition(page, position);
if (!spillPartitionMask.test(partition)) {
unspilledPositions.add(position);
continue;
}
spilledPartitions.add(partition);
PageBuilder pageBuilder = pageBuilders[partition];
pageBuilder.declarePosition();
for (int channel = 0; channel < types.size(); channel++) {
Type type = types.get(channel);
type.appendTo(page.getBlock(channel), position, pageBuilder.getBlockBuilder(channel));
}
}
return unspilledPositions;
}
use of com.facebook.presto.common.PageBuilder in project presto by prestodb.
the class GenericPartitioningSpiller method flush.
private synchronized ListenableFuture<?> flush(int partition) {
PageBuilder pageBuilder = pageBuilders[partition];
if (pageBuilder.isEmpty()) {
return Futures.immediateFuture(null);
}
Page page = pageBuilder.build();
pageBuilder.reset();
return getSpiller(partition).spill(page);
}
use of com.facebook.presto.common.PageBuilder in project presto by prestodb.
the class PageAssertions method mergePages.
public static Page mergePages(List<Type> types, List<Page> pages) {
PageBuilder pageBuilder = new PageBuilder(types);
int totalPositionCount = 0;
for (Page page : pages) {
verify(page.getChannelCount() == types.size(), format("Number of channels in page %d is not equal to number of types %d", page.getChannelCount(), types.size()));
for (int i = 0; i < types.size(); i++) {
BlockBuilder blockBuilder = pageBuilder.getBlockBuilder(i);
Block block = page.getBlock(i);
for (int position = 0; position < page.getPositionCount(); position++) {
if (block.isNull(position)) {
blockBuilder.appendNull();
} else {
block.writePositionTo(position, blockBuilder);
}
}
}
totalPositionCount += page.getPositionCount();
}
pageBuilder.declarePositions(totalPositionCount);
return pageBuilder.build();
}
Aggregations