Search in sources :

Example 61 with BlockBuilder

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

the class MarkDistinctHash method markDistinctRows.

public Block markDistinctRows(Page page) {
    GroupByIdBlock ids = groupByHash.getGroupIds(page);
    BlockBuilder blockBuilder = BOOLEAN.createBlockBuilder(new BlockBuilderStatus(), ids.getPositionCount());
    for (int i = 0; i < ids.getPositionCount(); i++) {
        if (ids.getGroupId(i) == nextDistinctId) {
            BOOLEAN.writeBoolean(blockBuilder, true);
            nextDistinctId++;
        } else {
            BOOLEAN.writeBoolean(blockBuilder, false);
        }
    }
    return blockBuilder.build();
}
Also used : BlockBuilder(com.facebook.presto.spi.block.BlockBuilder) BlockBuilderStatus(com.facebook.presto.spi.block.BlockBuilderStatus)

Example 62 with BlockBuilder

use of com.facebook.presto.spi.block.BlockBuilder 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, tableLayout);
    PageBuilder page = new PageBuilder(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.spi.PageBuilder) BlockBuilder(com.facebook.presto.spi.block.BlockBuilder)

Example 63 with BlockBuilder

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

the class MultiChannelGroupByHash method processDictionary.

private Block processDictionary(Page page) {
    verify(canProcessDictionary(page), "invalid call to processDictionary");
    DictionaryBlock dictionaryBlock = (DictionaryBlock) page.getBlock(channels[0]);
    updateDictionaryLookBack(dictionaryBlock.getDictionary());
    Page dictionaryPage = createPageWithExtractedDictionary(page);
    BlockBuilder blockBuilder = BIGINT.createFixedSizeBlockBuilder(page.getPositionCount());
    for (int i = 0; i < page.getPositionCount(); i++) {
        int positionInDictionary = dictionaryBlock.getId(i);
        int groupId = getGroupId(hashGenerator, dictionaryPage, positionInDictionary);
        BIGINT.writeLong(blockBuilder, groupId);
    }
    verify(blockBuilder.getPositionCount() == page.getPositionCount(), "invalid position count");
    return blockBuilder.build();
}
Also used : DictionaryBlock(com.facebook.presto.spi.block.DictionaryBlock) Page(com.facebook.presto.spi.Page) BlockBuilder(com.facebook.presto.spi.block.BlockBuilder)

Example 64 with BlockBuilder

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

the class ArrayAggregationFunction method combine.

public static void combine(Type type, ArrayAggregationState state, ArrayAggregationState otherState) {
    BlockBuilder stateBlockBuilder = state.getBlockBuilder();
    BlockBuilder otherStateBlockBuilder = otherState.getBlockBuilder();
    if (otherStateBlockBuilder == null) {
        return;
    }
    if (stateBlockBuilder == null) {
        state.setBlockBuilder(otherStateBlockBuilder);
        return;
    }
    int otherPositionCount = otherStateBlockBuilder.getPositionCount();
    long startSize = stateBlockBuilder.getRetainedSizeInBytes();
    for (int i = 0; i < otherPositionCount; i++) {
        type.appendTo(otherStateBlockBuilder, i, stateBlockBuilder);
    }
    state.addMemoryUsage(stateBlockBuilder.getRetainedSizeInBytes() - startSize);
}
Also used : BlockBuilder(com.facebook.presto.spi.block.BlockBuilder)

Example 65 with BlockBuilder

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

the class DoubleHistogramAggregation method output.

@OutputFunction("map(double,double)")
public static void output(@AggregationState State state, BlockBuilder out) {
    if (state.get() == null) {
        out.appendNull();
    } else {
        Map<Double, Double> value = state.get().getBuckets();
        BlockBuilder blockBuilder = DoubleType.DOUBLE.createBlockBuilder(new BlockBuilderStatus(), value.size() * 2);
        for (Map.Entry<Double, Double> entry : value.entrySet()) {
            DoubleType.DOUBLE.writeDouble(blockBuilder, entry.getKey());
            DoubleType.DOUBLE.writeDouble(blockBuilder, entry.getValue());
        }
        Block block = blockBuilder.build();
        out.writeObject(block);
        out.closeEntry();
    }
}
Also used : Block(com.facebook.presto.spi.block.Block) Map(java.util.Map) BlockBuilder(com.facebook.presto.spi.block.BlockBuilder) BlockBuilderStatus(com.facebook.presto.spi.block.BlockBuilderStatus) OutputFunction(com.facebook.presto.spi.function.OutputFunction)

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