Search in sources :

Example 31 with BlockBuilder

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

the class TestPagesSerde method testVarcharSerializedSize.

@Test
public void testVarcharSerializedSize() {
    BlockBuilder builder = VARCHAR.createBlockBuilder(new BlockBuilderStatus(), 5);
    // empty page
    Page page = new Page(builder.build());
    int pageSize = serializedSize(ImmutableList.of(VARCHAR), page);
    // page overhead
    assertEquals(pageSize, 43);
    // page with one value
    VARCHAR.writeString(builder, "alice");
    page = new Page(builder.build());
    int firstValueSize = serializedSize(ImmutableList.of(VARCHAR), page) - pageSize;
    // length + "alice" + null
    assertEquals(firstValueSize, 4 + 5 + 1);
    // page with two values
    VARCHAR.writeString(builder, "bob");
    page = new Page(builder.build());
    int secondValueSize = serializedSize(ImmutableList.of(VARCHAR), page) - (pageSize + firstValueSize);
    // length + "bob" (null shared with first entry)
    assertEquals(secondValueSize, 4 + 3);
}
Also used : Page(com.facebook.presto.spi.Page) BlockBuilder(com.facebook.presto.spi.block.BlockBuilder) BlockBuilderStatus(com.facebook.presto.spi.block.BlockBuilderStatus) Test(org.testng.annotations.Test)

Example 32 with BlockBuilder

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

the class OperatorAssertion method toRow.

public static Block toRow(List<Type> parameterTypes, Object... values) {
    checkArgument(parameterTypes.size() == values.length, "parameterTypes.size(" + parameterTypes.size() + ") does not equal to values.length(" + values.length + ")");
    BlockBuilder blockBuilder = new InterleavedBlockBuilder(parameterTypes, new BlockBuilderStatus(), parameterTypes.size());
    for (int i = 0; i < values.length; i++) {
        appendToBlockBuilder(parameterTypes.get(i), values[i], blockBuilder);
    }
    return blockBuilder.build();
}
Also used : InterleavedBlockBuilder(com.facebook.presto.spi.block.InterleavedBlockBuilder) BlockBuilder(com.facebook.presto.spi.block.BlockBuilder) InterleavedBlockBuilder(com.facebook.presto.spi.block.InterleavedBlockBuilder) TypeJsonUtils.appendToBlockBuilder(com.facebook.presto.type.TypeJsonUtils.appendToBlockBuilder) BlockBuilderStatus(com.facebook.presto.spi.block.BlockBuilderStatus)

Example 33 with BlockBuilder

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

the class TestHashAggregationOperator method testHashBuilderResize.

@Test(dataProvider = "hashEnabledAndMemoryLimitBeforeSpillValues")
public void testHashBuilderResize(boolean hashEnabled, long memoryLimitBeforeSpill, long memoryLimitForMergeWithMemory) {
    BlockBuilder builder = VARCHAR.createBlockBuilder(new BlockBuilderStatus(), 1, DEFAULT_MAX_BLOCK_SIZE_IN_BYTES);
    // this must be larger than DEFAULT_MAX_BLOCK_SIZE, 64K
    VARCHAR.writeSlice(builder, Slices.allocate(200_000));
    builder.build();
    List<Integer> hashChannels = Ints.asList(0);
    RowPagesBuilder rowPagesBuilder = rowPagesBuilder(hashEnabled, hashChannels, VARCHAR);
    List<Page> input = rowPagesBuilder.addSequencePage(10, 100).addBlocksPage(builder.build()).addSequencePage(10, 100).build();
    DriverContext driverContext = createTaskContext(executor, TEST_SESSION, new DataSize(10, MEGABYTE)).addPipelineContext(0, true, true).addDriverContext();
    HashAggregationOperatorFactory operatorFactory = new HashAggregationOperatorFactory(0, new PlanNodeId("test"), ImmutableList.of(VARCHAR), hashChannels, ImmutableList.of(), Step.SINGLE, ImmutableList.of(COUNT.bind(ImmutableList.of(0), Optional.empty())), rowPagesBuilder.getHashChannel(), Optional.empty(), 100_000, new DataSize(16, MEGABYTE), memoryLimitBeforeSpill > 0, succinctBytes(memoryLimitBeforeSpill), succinctBytes(memoryLimitForMergeWithMemory), spillerFactory, joinCompiler);
    toPages(operatorFactory, driverContext, input);
}
Also used : PlanNodeId(com.facebook.presto.sql.planner.plan.PlanNodeId) RowPagesBuilder(com.facebook.presto.RowPagesBuilder) DataSize(io.airlift.units.DataSize) Page(com.facebook.presto.spi.Page) BlockBuilder(com.facebook.presto.spi.block.BlockBuilder) BlockBuilderStatus(com.facebook.presto.spi.block.BlockBuilderStatus) HashAggregationOperatorFactory(com.facebook.presto.operator.HashAggregationOperator.HashAggregationOperatorFactory) Test(org.testng.annotations.Test)

Example 34 with BlockBuilder

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

the class AbstractTestApproximateCountDistinct method createBlock.

/**
     * Produce a block with the given values in the last field.
     */
private static Block createBlock(Type type, List<Object> values) {
    BlockBuilder blockBuilder = type.createBlockBuilder(new BlockBuilderStatus(), values.size());
    for (Object value : values) {
        Class<?> javaType = type.getJavaType();
        if (value == null) {
            blockBuilder.appendNull();
        } else if (javaType == boolean.class) {
            type.writeBoolean(blockBuilder, (Boolean) value);
        } else if (javaType == long.class) {
            type.writeLong(blockBuilder, (Long) value);
        } else if (javaType == double.class) {
            type.writeDouble(blockBuilder, (Double) value);
        } else if (javaType == Slice.class) {
            Slice slice = (Slice) value;
            type.writeSlice(blockBuilder, slice, 0, slice.length());
        } else {
            throw new UnsupportedOperationException("not yet implemented: " + javaType);
        }
    }
    return blockBuilder.build();
}
Also used : Slice(io.airlift.slice.Slice) BlockBuilder(com.facebook.presto.spi.block.BlockBuilder) BlockBuilderStatus(com.facebook.presto.spi.block.BlockBuilderStatus)

Example 35 with BlockBuilder

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

the class AggregationTestUtils method getIntermediateBlock.

public static Block getIntermediateBlock(GroupedAccumulator accumulator) {
    BlockBuilder blockBuilder = accumulator.getIntermediateType().createBlockBuilder(new BlockBuilderStatus(), 1000);
    accumulator.evaluateIntermediate(0, blockBuilder);
    return blockBuilder.build();
}
Also used : BlockBuilder(com.facebook.presto.spi.block.BlockBuilder) BlockBuilderStatus(com.facebook.presto.spi.block.BlockBuilderStatus)

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