Search in sources :

Example 66 with BlockBuilder

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

the class MultiKeyValuePairs method serialize.

public void serialize(BlockBuilder out) {
    BlockBuilder arrayBlockBuilder = out.beginBlockEntry();
    for (int i = 0; i < keyBlockBuilder.getPositionCount(); i++) {
        BlockBuilder rowBlockBuilder = arrayBlockBuilder.beginBlockEntry();
        keyType.appendTo(keyBlockBuilder, i, rowBlockBuilder);
        valueType.appendTo(valueBlockBuilder, i, rowBlockBuilder);
        arrayBlockBuilder.closeEntry();
    }
    out.closeEntry();
}
Also used : BlockBuilder(com.facebook.presto.spi.block.BlockBuilder) InterleavedBlockBuilder(com.facebook.presto.spi.block.InterleavedBlockBuilder)

Example 67 with BlockBuilder

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

the class ArrayAggregationStateSerializer method deserialize.

@Override
public void deserialize(Block block, int index, ArrayAggregationState state) {
    Block stateBlock = (Block) arrayType.getObject(block, index);
    int positionCount = stateBlock.getPositionCount();
    BlockBuilder blockBuilder = elementType.createBlockBuilder(new BlockBuilderStatus(), positionCount);
    for (int i = 0; i < positionCount; i++) {
        elementType.appendTo(stateBlock, i, blockBuilder);
    }
    state.setBlockBuilder(blockBuilder);
}
Also used : Block(com.facebook.presto.spi.block.Block) BlockBuilder(com.facebook.presto.spi.block.BlockBuilder) BlockBuilderStatus(com.facebook.presto.spi.block.BlockBuilderStatus)

Example 68 with BlockBuilder

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

the class ApproximateDoublePercentileArrayAggregations method output.

@OutputFunction("array(double)")
public static void output(@AggregationState DigestAndPercentileArrayState state, BlockBuilder out) {
    QuantileDigest digest = state.getDigest();
    List<Double> percentiles = state.getPercentiles();
    if (percentiles == null || digest == null) {
        out.appendNull();
        return;
    }
    BlockBuilder blockBuilder = out.beginBlockEntry();
    for (int i = 0; i < percentiles.size(); i++) {
        Double percentile = percentiles.get(i);
        DOUBLE.writeDouble(blockBuilder, sortableLongToDouble(digest.getQuantile(percentile)));
    }
    out.closeEntry();
}
Also used : QuantileDigest(io.airlift.stats.QuantileDigest) FloatingPointBitsConverterUtil.sortableLongToDouble(com.facebook.presto.operator.aggregation.FloatingPointBitsConverterUtil.sortableLongToDouble) BlockBuilder(com.facebook.presto.spi.block.BlockBuilder) OutputFunction(com.facebook.presto.spi.function.OutputFunction)

Example 69 with BlockBuilder

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

the class ArrayUnionFunction method bigintUnion.

@SqlType("array(bigint)")
public static Block bigintUnion(@SqlType("array(bigint)") Block leftArray, @SqlType("array(bigint)") Block rightArray) {
    int leftArrayCount = leftArray.getPositionCount();
    int rightArrayCount = rightArray.getPositionCount();
    LongSet set = new LongOpenHashSet(leftArrayCount + rightArrayCount);
    BlockBuilder distinctElementBlockBuilder = BIGINT.createBlockBuilder(new BlockBuilderStatus(), leftArrayCount + rightArrayCount);
    AtomicBoolean containsNull = new AtomicBoolean(false);
    appendBigintArray(leftArray, containsNull, set, distinctElementBlockBuilder);
    appendBigintArray(rightArray, containsNull, set, distinctElementBlockBuilder);
    return distinctElementBlockBuilder.build();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) LongSet(it.unimi.dsi.fastutil.longs.LongSet) LongOpenHashSet(it.unimi.dsi.fastutil.longs.LongOpenHashSet) BlockBuilder(com.facebook.presto.spi.block.BlockBuilder) BlockBuilderStatus(com.facebook.presto.spi.block.BlockBuilderStatus) SqlType(com.facebook.presto.spi.function.SqlType)

Example 70 with BlockBuilder

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

the class TupleFilterProcessor method processColumnar.

@Override
public Page processColumnar(ConnectorSession session, Page page, List<? extends Type> types) {
    PageBuilder pageBuilder = new PageBuilder(types);
    int positionCount = page.getPositionCount();
    int[] selectedPositions = new int[positionCount];
    int selectedCount = 0;
    for (int i = 0; i < positionCount; i++) {
        if (matches(i, page)) {
            selectedPositions[selectedCount++] = i;
        }
    }
    for (int i = 0; i < outputTypes.size(); i++) {
        Type type = outputTypes.get(i);
        Block block = page.getBlock(i);
        BlockBuilder blockBuilder = pageBuilder.getBlockBuilder(i);
        for (int position : selectedPositions) {
            type.appendTo(block, position, blockBuilder);
        }
    }
    pageBuilder.declarePositions(selectedCount);
    return pageBuilder.build();
}
Also used : Type(com.facebook.presto.spi.type.Type) Block(com.facebook.presto.spi.block.Block) PageBuilder(com.facebook.presto.spi.PageBuilder) 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