Search in sources :

Example 51 with BlockBuilder

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

the class TestMergeHyperLogLogAggregation method getSequenceBlocks.

@Override
public Block[] getSequenceBlocks(int start, int length) {
    BlockBuilder blockBuilder = HYPER_LOG_LOG.createBlockBuilder(new BlockBuilderStatus(), length);
    for (int i = start; i < start + length; i++) {
        HyperLogLog hll = HyperLogLog.newInstance(NUMBER_OF_BUCKETS);
        hll.add(i);
        HYPER_LOG_LOG.writeSlice(blockBuilder, hll.serialize());
    }
    return new Block[] { blockBuilder.build() };
}
Also used : Block(com.facebook.presto.spi.block.Block) HyperLogLog(io.airlift.stats.cardinality.HyperLogLog) BlockBuilder(com.facebook.presto.spi.block.BlockBuilder) BlockBuilderStatus(com.facebook.presto.spi.block.BlockBuilderStatus)

Example 52 with BlockBuilder

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

the class TestMapAggAggregation method testDoubleRowMap.

@Test
public void testDoubleRowMap() throws Exception {
    RowType innerRowType = new RowType(ImmutableList.of(INTEGER, DOUBLE), Optional.of(ImmutableList.of("f1", "f2")));
    MapType mapType = new MapType(DOUBLE, innerRowType);
    InternalAggregationFunction aggFunc = metadata.getFunctionRegistry().getAggregateFunctionImplementation(new Signature(NAME, AGGREGATE, mapType.getTypeSignature(), parseTypeSignature(StandardTypes.DOUBLE), innerRowType.getTypeSignature()));
    BlockBuilder builder = innerRowType.createBlockBuilder(new BlockBuilderStatus(), 3);
    innerRowType.writeObject(builder, toRow(ImmutableList.of(INTEGER, DOUBLE), 1L, 1.0));
    innerRowType.writeObject(builder, toRow(ImmutableList.of(INTEGER, DOUBLE), 2L, 2.0));
    innerRowType.writeObject(builder, toRow(ImmutableList.of(INTEGER, DOUBLE), 3L, 3.0));
    assertAggregation(aggFunc, ImmutableMap.of(1.0, ImmutableList.of(1, 1.0), 2.0, ImmutableList.of(2, 2.0), 3.0, ImmutableList.of(3, 3.0)), createDoublesBlock(1.0, 2.0, 3.0), builder.build());
}
Also used : Signature(com.facebook.presto.metadata.Signature) TypeSignature.parseTypeSignature(com.facebook.presto.spi.type.TypeSignature.parseTypeSignature) RowType(com.facebook.presto.type.RowType) MapType(com.facebook.presto.type.MapType) BlockBuilder(com.facebook.presto.spi.block.BlockBuilder) BlockBuilderStatus(com.facebook.presto.spi.block.BlockBuilderStatus) Test(org.testng.annotations.Test)

Example 53 with BlockBuilder

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

the class AccumuloRowSerializer method getBlockFromMap.

/**
     * Encodes the given map into a Block.
     *
     * @param mapType Presto type of the map
     * @param map Map of key/value pairs to encode
     * @return Presto Block
     */
static Block getBlockFromMap(Type mapType, Map<?, ?> map) {
    Type keyType = mapType.getTypeParameters().get(0);
    Type valueType = mapType.getTypeParameters().get(1);
    BlockBuilder builder = new InterleavedBlockBuilder(ImmutableList.of(keyType, valueType), new BlockBuilderStatus(), map.size() * 2);
    for (Entry<?, ?> entry : map.entrySet()) {
        writeObject(builder, keyType, entry.getKey());
        writeObject(builder, valueType, entry.getValue());
    }
    return builder.build();
}
Also used : Type(com.facebook.presto.spi.type.Type) VarcharType(com.facebook.presto.spi.type.VarcharType) InterleavedBlockBuilder(com.facebook.presto.spi.block.InterleavedBlockBuilder) BlockBuilder(com.facebook.presto.spi.block.BlockBuilder) InterleavedBlockBuilder(com.facebook.presto.spi.block.InterleavedBlockBuilder) BlockBuilderStatus(com.facebook.presto.spi.block.BlockBuilderStatus)

Example 54 with BlockBuilder

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

the class ArrayUnnester method appendTo.

protected void appendTo(PageBuilder pageBuilder, int outputChannelOffset) {
    BlockBuilder blockBuilder = pageBuilder.getBlockBuilder(outputChannelOffset);
    elementType.appendTo(arrayBlock, position, blockBuilder);
    position++;
}
Also used : BlockBuilder(com.facebook.presto.spi.block.BlockBuilder)

Example 55 with BlockBuilder

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

the class HashSemiJoinOperator method addInput.

@Override
public void addInput(Page page) {
    requireNonNull(page, "page is null");
    checkState(!finishing, "Operator is finishing");
    checkState(channelSet != null, "Set has not been built yet");
    checkState(outputPage == null, "Operator still has pending output");
    // create the block builder for the new boolean column
    // we know the exact size required for the block
    BlockBuilder blockBuilder = BOOLEAN.createFixedSizeBlockBuilder(page.getPositionCount());
    Page probeJoinPage = new Page(page.getBlock(probeJoinChannel));
    // update hashing strategy to use probe cursor
    for (int position = 0; position < page.getPositionCount(); position++) {
        if (probeJoinPage.getBlock(0).isNull(position)) {
            throw new PrestoException(NOT_SUPPORTED, "NULL values are not allowed on the probe side of SemiJoin operator. See the query plan for details.");
        } else {
            boolean contains = channelSet.contains(position, probeJoinPage);
            if (!contains && channelSet.containsNull()) {
                blockBuilder.appendNull();
            } else {
                BOOLEAN.writeBoolean(blockBuilder, contains);
            }
        }
    }
    // add the new boolean column to the page
    Block[] sourceBlocks = page.getBlocks();
    // +1 for the single boolean output channel
    Block[] outputBlocks = new Block[sourceBlocks.length + 1];
    System.arraycopy(sourceBlocks, 0, outputBlocks, 0, sourceBlocks.length);
    outputBlocks[sourceBlocks.length] = blockBuilder.build();
    outputPage = new Page(outputBlocks);
}
Also used : Block(com.facebook.presto.spi.block.Block) Page(com.facebook.presto.spi.Page) PrestoException(com.facebook.presto.spi.PrestoException) 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