use of com.facebook.presto.common.PageBuilder in project presto by prestodb.
the class InCodeGeneratorBenchmark method setup.
@Setup
public void setup() {
Random random = new Random();
RowExpression[] arguments = new RowExpression[1 + inListCount];
switch(type) {
case StandardTypes.BIGINT:
prestoType = BIGINT;
for (int i = 1; i <= inListCount; i++) {
arguments[i] = constant((long) random.nextInt(), BIGINT);
}
break;
case StandardTypes.DOUBLE:
prestoType = DOUBLE;
for (int i = 1; i <= inListCount; i++) {
arguments[i] = constant(random.nextDouble(), DOUBLE);
}
break;
case StandardTypes.VARCHAR:
prestoType = VARCHAR;
for (int i = 1; i <= inListCount; i++) {
arguments[i] = constant(Slices.utf8Slice(Long.toString(random.nextLong())), VARCHAR);
}
break;
default:
throw new IllegalStateException();
}
arguments[0] = field(0, prestoType);
RowExpression project = field(0, prestoType);
PageBuilder pageBuilder = new PageBuilder(ImmutableList.of(prestoType));
for (int i = 0; i < 10_000; i++) {
pageBuilder.declarePosition();
switch(type) {
case StandardTypes.BIGINT:
BIGINT.writeLong(pageBuilder.getBlockBuilder(0), random.nextInt());
break;
case StandardTypes.DOUBLE:
DOUBLE.writeDouble(pageBuilder.getBlockBuilder(0), random.nextDouble());
break;
case StandardTypes.VARCHAR:
VARCHAR.writeSlice(pageBuilder.getBlockBuilder(0), Slices.utf8Slice(Long.toString(random.nextLong())));
break;
}
}
inputPage = pageBuilder.build();
RowExpression filter = specialForm(IN, BOOLEAN, arguments);
MetadataManager metadata = MetadataManager.createTestMetadataManager();
processor = new ExpressionCompiler(metadata, new PageFunctionCompiler(metadata, 0)).compilePageProcessor(SESSION.getSqlFunctionProperties(), Optional.of(filter), ImmutableList.of(project)).get();
}
use of com.facebook.presto.common.PageBuilder in project presto by prestodb.
the class PagesIndex method getSortedPages.
public Iterator<Page> getSortedPages() {
return new AbstractIterator<Page>() {
private int currentPosition;
private final PageBuilder pageBuilder = new PageBuilder(types);
private final int[] outputChannels = new int[types.size()];
{
Arrays.setAll(outputChannels, IntUnaryOperator.identity());
}
@Override
public Page computeNext() {
currentPosition = buildPage(currentPosition, outputChannels, pageBuilder);
if (pageBuilder.isEmpty()) {
return endOfData();
}
Page page = pageBuilder.build();
pageBuilder.reset();
return page;
}
};
}
use of com.facebook.presto.common.PageBuilder in project presto by prestodb.
the class MetadataDeleteOperator method getOutput.
@Override
public Page getOutput() {
if (finished) {
return null;
}
finished = true;
OptionalLong rowsDeletedCount = metadata.metadataDelete(session, tableHandle);
// output page will only be constructed once,
// so a new PageBuilder is constructed (instead of using PageBuilder.reset)
PageBuilder page = new PageBuilder(1, TYPES);
BlockBuilder rowsBuilder = page.getBlockBuilder(0);
page.declarePosition();
if (rowsDeletedCount.isPresent()) {
BIGINT.writeLong(rowsBuilder, rowsDeletedCount.getAsLong());
} else {
rowsBuilder.appendNull();
}
return page.build();
}
use of com.facebook.presto.common.PageBuilder in project presto by prestodb.
the class TestHiveManifestUtils method createTestStatisticsPageWithOneRow.
private Page createTestStatisticsPageWithOneRow(List<Type> types, List<Object> values) {
assertEquals(types.size(), values.size());
PageBuilder pageBuilder = new PageBuilder(ImmutableList.copyOf(types));
pageBuilder.declarePosition();
for (int i = 0; i < types.size(); i++) {
Type type = types.get(i);
BlockBuilder blockBuilder = pageBuilder.getBlockBuilder(i);
Object value = values.get(i);
switch(type.getTypeSignature().getBase()) {
case BOOLEAN:
type.writeBoolean(blockBuilder, (Boolean) value);
break;
case StandardTypes.BIGINT:
type.writeLong(blockBuilder, (Long) value);
break;
case DOUBLE:
type.writeDouble(blockBuilder, (Double) value);
break;
case VARCHAR:
type.writeSlice(blockBuilder, utf8Slice((String) value));
break;
}
}
return pageBuilder.build();
}
use of com.facebook.presto.common.PageBuilder in project presto by prestodb.
the class GenericPartitioningSpiller method flush.
private synchronized ListenableFuture<?> flush(Predicate<PageBuilder> flushCondition) {
requireNonNull(flushCondition, "flushCondition is null");
ImmutableList.Builder<ListenableFuture<?>> futures = ImmutableList.builder();
for (int partition = 0; partition < spillers.length; partition++) {
PageBuilder pageBuilder = pageBuilders[partition];
if (flushCondition.test(pageBuilder)) {
futures.add(flush(partition));
}
}
return Futures.allAsList(futures.build());
}
Aggregations