Search in sources :

Example 21 with PageBuilder

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();
}
Also used : MetadataManager(com.facebook.presto.metadata.MetadataManager) Random(java.util.Random) RowExpression(com.facebook.presto.spi.relation.RowExpression) PageBuilder(com.facebook.presto.common.PageBuilder) Setup(org.openjdk.jmh.annotations.Setup)

Example 22 with PageBuilder

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;
        }
    };
}
Also used : Page(com.facebook.presto.common.Page) AbstractIterator(com.google.common.collect.AbstractIterator) PageBuilder(com.facebook.presto.common.PageBuilder)

Example 23 with PageBuilder

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();
}
Also used : OptionalLong(java.util.OptionalLong) PageBuilder(com.facebook.presto.common.PageBuilder) BlockBuilder(com.facebook.presto.common.block.BlockBuilder)

Example 24 with PageBuilder

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();
}
Also used : Type(com.facebook.presto.common.type.Type) PageBuilder(com.facebook.presto.common.PageBuilder) BlockBuilder(com.facebook.presto.common.block.BlockBuilder)

Example 25 with PageBuilder

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());
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) PageBuilder(com.facebook.presto.common.PageBuilder)

Aggregations

PageBuilder (com.facebook.presto.common.PageBuilder)57 Page (com.facebook.presto.common.Page)27 Type (com.facebook.presto.common.type.Type)25 BlockBuilder (com.facebook.presto.common.block.BlockBuilder)23 ImmutableList (com.google.common.collect.ImmutableList)14 Block (com.facebook.presto.common.block.Block)11 Test (org.testng.annotations.Test)11 ArrayType (com.facebook.presto.common.type.ArrayType)8 ArrayList (java.util.ArrayList)8 List (java.util.List)8 Benchmark (org.openjdk.jmh.annotations.Benchmark)7 INTEGER (com.facebook.presto.common.type.IntegerType.INTEGER)4 BIGINT (com.facebook.presto.common.type.BigintType.BIGINT)3 DOUBLE (com.facebook.presto.common.type.DoubleType.DOUBLE)3 VarcharType.createUnboundedVarcharType (com.facebook.presto.common.type.VarcharType.createUnboundedVarcharType)3 ConnectorPageSource (com.facebook.presto.spi.ConnectorPageSource)3 ConnectorSession (com.facebook.presto.spi.ConnectorSession)3 MaterializedResult (com.facebook.presto.testing.MaterializedResult)3 Slices (io.airlift.slice.Slices)3 File (java.io.File)3