Search in sources :

Example 56 with BlockBuilder

use of com.facebook.presto.spi.block.BlockBuilder in project presto by prestodb.

the class AssignUniqueIdOperator method generateIdColumn.

private Block generateIdColumn() {
    BlockBuilder block = BIGINT.createFixedSizeBlockBuilder(inputPage.getPositionCount());
    for (int currentPosition = 0; currentPosition < inputPage.getPositionCount(); currentPosition++) {
        if (rowIdCounter >= maxRowIdCounterValue) {
            requestValues();
        }
        long rowId = rowIdCounter++;
        verify((rowId & uniqueValueMask) == 0, "RowId and uniqueValue mask overlaps");
        BIGINT.writeLong(block, uniqueValueMask | rowId);
    }
    return block.build();
}
Also used : BlockBuilder(com.facebook.presto.spi.block.BlockBuilder)

Example 57 with BlockBuilder

use of com.facebook.presto.spi.block.BlockBuilder in project presto by prestodb.

the class BigintGroupByHash method appendValuesTo.

@Override
public void appendValuesTo(int groupId, PageBuilder pageBuilder, int outputChannelOffset) {
    checkArgument(groupId >= 0, "groupId is negative");
    BlockBuilder blockBuilder = pageBuilder.getBlockBuilder(outputChannelOffset);
    if (groupId == nullGroupId) {
        blockBuilder.appendNull();
    } else {
        BIGINT.writeLong(blockBuilder, valuesByGroupId.get(groupId));
    }
    if (outputRawHash) {
        BlockBuilder hashBlockBuilder = pageBuilder.getBlockBuilder(outputChannelOffset + 1);
        if (groupId == nullGroupId) {
            BIGINT.writeLong(hashBlockBuilder, NULL_HASH_CODE);
        } else {
            BIGINT.writeLong(hashBlockBuilder, BigintOperators.hashCode(valuesByGroupId.get(groupId)));
        }
    }
}
Also used : BlockBuilder(com.facebook.presto.spi.block.BlockBuilder)

Example 58 with BlockBuilder

use of com.facebook.presto.spi.block.BlockBuilder in project presto by prestodb.

the class BigintGroupByHash method getGroupIds.

@Override
public GroupByIdBlock getGroupIds(Page page) {
    int positionCount = page.getPositionCount();
    // we know the exact size required for the block
    BlockBuilder blockBuilder = BIGINT.createFixedSizeBlockBuilder(positionCount);
    // get the group id for each position
    Block block = page.getBlock(hashChannel);
    for (int position = 0; position < positionCount; position++) {
        // get the group for the current row
        int groupId = putIfAbsent(position, block);
        // output the group id for this row
        BIGINT.writeLong(blockBuilder, groupId);
    }
    return new GroupByIdBlock(nextGroupId, blockBuilder.build());
}
Also used : Block(com.facebook.presto.spi.block.Block) BlockBuilder(com.facebook.presto.spi.block.BlockBuilder)

Example 59 with BlockBuilder

use of com.facebook.presto.spi.block.BlockBuilder in project presto by prestodb.

the class DeleteOperator method getOutput.

@Override
public Page getOutput() {
    if ((state != State.FINISHING) || !finishFuture.isDone()) {
        return null;
    }
    state = State.FINISHED;
    Collection<Slice> fragments = getFutureValue(finishFuture);
    PageBuilder page = new PageBuilder(TYPES);
    BlockBuilder rowsBuilder = page.getBlockBuilder(0);
    BlockBuilder fragmentBuilder = page.getBlockBuilder(1);
    // write row count
    page.declarePosition();
    BIGINT.writeLong(rowsBuilder, rowCount);
    fragmentBuilder.appendNull();
    // write fragments
    for (Slice fragment : fragments) {
        page.declarePosition();
        rowsBuilder.appendNull();
        VARBINARY.writeSlice(fragmentBuilder, fragment);
    }
    return page.build();
}
Also used : Slice(io.airlift.slice.Slice) PageBuilder(com.facebook.presto.spi.PageBuilder) BlockBuilder(com.facebook.presto.spi.block.BlockBuilder)

Example 60 with BlockBuilder

use of com.facebook.presto.spi.block.BlockBuilder in project presto by prestodb.

the class MapUnnester method appendTo.

protected void appendTo(PageBuilder pageBuilder, int outputChannelOffset) {
    BlockBuilder keyBlockBuilder = pageBuilder.getBlockBuilder(outputChannelOffset);
    BlockBuilder valueBlockBuilder = pageBuilder.getBlockBuilder(outputChannelOffset + 1);
    keyType.appendTo(block, position++, keyBlockBuilder);
    valueType.appendTo(block, position++, valueBlockBuilder);
}
Also used : BlockBuilder(com.facebook.presto.spi.block.BlockBuilder)

Aggregations

BlockBuilder (com.facebook.presto.spi.block.BlockBuilder)290 BlockBuilderStatus (com.facebook.presto.spi.block.BlockBuilderStatus)211 Block (com.facebook.presto.spi.block.Block)56 Slice (io.airlift.slice.Slice)53 InterleavedBlockBuilder (com.facebook.presto.spi.block.InterleavedBlockBuilder)39 Test (org.testng.annotations.Test)38 Type (com.facebook.presto.spi.type.Type)33 SqlType (com.facebook.presto.spi.function.SqlType)24 ArrayType (com.facebook.presto.type.ArrayType)19 Page (com.facebook.presto.spi.Page)18 UsedByGeneratedCode (com.facebook.presto.annotation.UsedByGeneratedCode)17 TypeParameter (com.facebook.presto.spi.function.TypeParameter)15 MapType (com.facebook.presto.type.MapType)14 RowType (com.facebook.presto.type.RowType)14 TypeJsonUtils.appendToBlockBuilder (com.facebook.presto.type.TypeJsonUtils.appendToBlockBuilder)13 PageBuilder (com.facebook.presto.spi.PageBuilder)12 ImmutableList (com.google.common.collect.ImmutableList)12 PrestoException (com.facebook.presto.spi.PrestoException)11 RunLengthEncodedBlock (com.facebook.presto.spi.block.RunLengthEncodedBlock)11 DictionaryBlock (com.facebook.presto.spi.block.DictionaryBlock)10