Search in sources :

Example 6 with PageBuilder

use of com.facebook.presto.common.PageBuilder in project presto by prestodb.

the class PinotBrokerPageSourceSql method buildBlockAndTypeBuilder.

@VisibleForTesting
@Override
public BlockAndTypeBuilder buildBlockAndTypeBuilder(List<PinotColumnHandle> columnHandles, GeneratedPinotQuery brokerSql) {
    // When we created the SQL, we came up with some column handles
    // however other optimizers post-pushdown can come in and prune/re-order the required column handles
    // so we need to map from the column handles the PQL corresponds to, to the actual column handles
    // needed in the scan.
    List<Type> expectedTypes = columnHandles.stream().map(PinotColumnHandle::getDataType).collect(Collectors.toList());
    PageBuilder pageBuilder = new PageBuilder(expectedTypes);
    // The expectedColumnHandles are the handles corresponding to the generated SQL
    // However, the engine could end up requesting only a permutation/subset of those handles
    // during the actual scan
    // Map the handles from planning time to the handles asked in the scan
    // so that we know which columns to discard.
    int[] handleMapping = new int[expectedHandles.size()];
    for (int i = 0; i < handleMapping.length; ++i) {
        handleMapping[i] = columnHandles.indexOf(expectedHandles.get(i));
    }
    ArrayList<BlockBuilder> columnBlockBuilders = new ArrayList<>();
    ArrayList<Type> columnTypes = new ArrayList<>();
    for (int expectedColumnIndex : brokerSql.getExpectedColumnIndices()) {
        // columnIndex is the index of this column in the current scan
        // It is obtained from the mapping and can be -ve, which means that the
        // expectedColumnIndex'th column returned by Pinot can be discarded.
        int columnIndex = -1;
        if (expectedColumnIndex >= 0) {
            columnIndex = handleMapping[expectedColumnIndex];
        }
        columnBlockBuilders.add(columnIndex >= 0 ? pageBuilder.getBlockBuilder(columnIndex) : null);
        columnTypes.add(columnIndex >= 0 ? expectedTypes.get(columnIndex) : null);
    }
    return new BlockAndTypeBuilder(pageBuilder, columnBlockBuilders, columnTypes);
}
Also used : Type(com.facebook.presto.common.type.Type) ArrayList(java.util.ArrayList) PageBuilder(com.facebook.presto.common.PageBuilder) BlockBuilder(com.facebook.presto.common.block.BlockBuilder) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 7 with PageBuilder

use of com.facebook.presto.common.PageBuilder in project presto by prestodb.

the class TableFinishOperator method getOutput.

@Override
public Page getOutput() {
    if (!isBlocked().isDone()) {
        return null;
    }
    if (!statisticsAggregationOperator.isFinished()) {
        verify(statisticsAggregationOperator.isBlocked().isDone(), "aggregation operator should not be blocked");
        OperationTimer timer = new OperationTimer(statisticsCpuTimerEnabled);
        Page page = statisticsAggregationOperator.getOutput();
        timer.end(statisticsTiming);
        if (page == null) {
            return null;
        }
        for (int position = 0; position < page.getPositionCount(); position++) {
            computedStatisticsBuilder.add(getComputedStatistics(page, position));
        }
        return null;
    }
    if (state != State.FINISHING) {
        return null;
    }
    state = State.FINISHED;
    lifespanAndStageStateTracker.commit();
    outputMetadata.set(tableFinisher.finishTable(lifespanAndStageStateTracker.getFinalFragments(), computedStatisticsBuilder.build()));
    // output page will only be constructed once,
    // so a new PageBuilder is constructed (instead of using PageBuilder.reset)
    PageBuilder page = new PageBuilder(1, TYPES);
    page.declarePosition();
    BIGINT.writeLong(page.getBlockBuilder(0), lifespanAndStageStateTracker.getFinalRowCount());
    return page.build();
}
Also used : Page(com.facebook.presto.common.Page) PageBuilder(com.facebook.presto.common.PageBuilder)

Example 8 with PageBuilder

use of com.facebook.presto.common.PageBuilder in project presto by prestodb.

the class RowNumberOperator method getSelectedRows.

private Page getSelectedRows() {
    verify(selectedRowPageBuilder.isPresent());
    int rowNumberChannel = types.size() - 1;
    PageBuilder pageBuilder = selectedRowPageBuilder.get();
    verify(pageBuilder.isEmpty());
    for (int currentPosition = 0; currentPosition < inputPage.getPositionCount(); currentPosition++) {
        long partitionId = getPartitionId(currentPosition);
        long rowCount = partitionRowCount.get(partitionId);
        if (rowCount == maxRowsPerPartition.get()) {
            continue;
        }
        pageBuilder.declarePosition();
        for (int i = 0; i < outputChannels.length; i++) {
            int channel = outputChannels[i];
            Type type = types.get(i);
            type.appendTo(inputPage.getBlock(channel), currentPosition, pageBuilder.getBlockBuilder(i));
        }
        BIGINT.writeLong(pageBuilder.getBlockBuilder(rowNumberChannel), rowCount + 1);
        partitionRowCount.set(partitionId, rowCount + 1);
    }
    if (pageBuilder.isEmpty()) {
        return null;
    }
    Page page = pageBuilder.build();
    pageBuilder.reset();
    return page;
}
Also used : Type(com.facebook.presto.common.type.Type) Page(com.facebook.presto.common.Page) PageBuilder(com.facebook.presto.common.PageBuilder)

Example 9 with PageBuilder

use of com.facebook.presto.common.PageBuilder in project presto by prestodb.

the class BenchmarkGroupByHash method bigintGroupByHash.

@Benchmark
@OperationsPerInvocation(POSITIONS)
public Object bigintGroupByHash(SingleChannelBenchmarkData data) {
    GroupByHash groupByHash = new BigintGroupByHash(0, data.getHashEnabled(), EXPECTED_SIZE, NOOP);
    for (Page page : data.getPages()) {
        Work<?> work = groupByHash.addPage(page);
        boolean finished;
        do {
            finished = work.process();
        } while (!finished);
    }
    ImmutableList.Builder<Page> pages = ImmutableList.builder();
    PageBuilder pageBuilder = new PageBuilder(groupByHash.getTypes());
    for (int groupId = 0; groupId < groupByHash.getGroupCount(); groupId++) {
        pageBuilder.declarePosition();
        groupByHash.appendValuesTo(groupId, pageBuilder, 0);
        if (pageBuilder.isFull()) {
            pages.add(pageBuilder.build());
            pageBuilder.reset();
        }
    }
    pages.add(pageBuilder.build());
    return pageBuilder.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) Page(com.facebook.presto.common.Page) PageBuilder(com.facebook.presto.common.PageBuilder) Benchmark(org.openjdk.jmh.annotations.Benchmark) OperationsPerInvocation(org.openjdk.jmh.annotations.OperationsPerInvocation)

Example 10 with PageBuilder

use of com.facebook.presto.common.PageBuilder in project presto by prestodb.

the class BenchmarkGroupByHash method createVarcharPages.

private static List<Page> createVarcharPages(int positionCount, int groupCount, int channelCount, boolean hashEnabled) {
    List<Type> types = Collections.nCopies(channelCount, VARCHAR);
    ImmutableList.Builder<Page> pages = ImmutableList.builder();
    if (hashEnabled) {
        types = ImmutableList.copyOf(Iterables.concat(types, ImmutableList.of(BIGINT)));
    }
    PageBuilder pageBuilder = new PageBuilder(types);
    for (int position = 0; position < positionCount; position++) {
        int rand = ThreadLocalRandom.current().nextInt(groupCount);
        Slice value = Slices.wrappedBuffer(ByteBuffer.allocate(4).putInt(rand));
        pageBuilder.declarePosition();
        for (int channel = 0; channel < channelCount; channel++) {
            VARCHAR.writeSlice(pageBuilder.getBlockBuilder(channel), value);
        }
        if (hashEnabled) {
            BIGINT.writeLong(pageBuilder.getBlockBuilder(channelCount), VarcharOperators.hashCode(value));
        }
        if (pageBuilder.isFull()) {
            pages.add(pageBuilder.build());
            pageBuilder.reset();
        }
    }
    pages.add(pageBuilder.build());
    return pages.build();
}
Also used : Type(com.facebook.presto.common.type.Type) ImmutableList(com.google.common.collect.ImmutableList) Slice(io.airlift.slice.Slice) Page(com.facebook.presto.common.Page) 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