Search in sources :

Example 1 with SingleRowBlockWriter

use of com.facebook.presto.common.block.SingleRowBlockWriter in project presto by prestodb.

the class TestSimpleRowType method createTestBlock.

private static Block createTestBlock() {
    RowBlockBuilder blockBuilder = (RowBlockBuilder) TYPE.createBlockBuilder(null, 3);
    SingleRowBlockWriter singleRowBlockWriter;
    singleRowBlockWriter = blockBuilder.beginBlockEntry();
    BIGINT.writeLong(singleRowBlockWriter, 1);
    VARCHAR.writeSlice(singleRowBlockWriter, utf8Slice("cat"));
    blockBuilder.closeEntry();
    singleRowBlockWriter = blockBuilder.beginBlockEntry();
    BIGINT.writeLong(singleRowBlockWriter, 2);
    VARCHAR.writeSlice(singleRowBlockWriter, utf8Slice("cats"));
    blockBuilder.closeEntry();
    singleRowBlockWriter = blockBuilder.beginBlockEntry();
    BIGINT.writeLong(singleRowBlockWriter, 3);
    VARCHAR.writeSlice(singleRowBlockWriter, utf8Slice("dog"));
    blockBuilder.closeEntry();
    return blockBuilder.build();
}
Also used : RowBlockBuilder(com.facebook.presto.common.block.RowBlockBuilder) SingleRowBlockWriter(com.facebook.presto.common.block.SingleRowBlockWriter)

Example 2 with SingleRowBlockWriter

use of com.facebook.presto.common.block.SingleRowBlockWriter in project presto by prestodb.

the class TestDirectEntryBlockBuilder method testNestedRow.

@Test
public void testNestedRow() {
    MapType mapType = new MapType(BIGINT, VARCHAR, MethodHandleUtil.methodHandle(TestDirectEntryBlockBuilder.class, "throwUnsupportedOperation"), MethodHandleUtil.methodHandle(TestDirectEntryBlockBuilder.class, "throwUnsupportedOperation"));
    ArrayType arrayType = new ArrayType(DOUBLE);
    RowType.Field nestedRowField = new RowType.Field(Optional.of("my_struct"), INTEGER);
    RowType nestedRowType = RowType.from(ImmutableList.of(nestedRowField));
    List<Type> rowType = ImmutableList.of(REAL, mapType, arrayType, nestedRowType);
    RowBlockBuilder beginEntryBlockBuilder = new RowBlockBuilder(rowType, null, 1);
    for (int i = 0; i < POSITION_COUNT; i++) {
        SingleRowBlockWriter singleRowBlockWriter = beginEntryBlockBuilder.beginBlockEntry();
        REAL.writeLong(singleRowBlockWriter, i);
        // Write Map<Bigint, Varchar> with 5 entries.
        BlockBuilder mapWriter = singleRowBlockWriter.beginBlockEntry();
        for (int j = 0; j < 5; j++) {
            BIGINT.writeLong(mapWriter, i + j);
            VARCHAR.writeSlice(mapWriter, utf8Slice("Value1" + j));
        }
        singleRowBlockWriter.closeEntry();
        // Write array .
        BlockBuilder arrayWriter = singleRowBlockWriter.beginBlockEntry();
        for (int j = 0; j < 8; j++) {
            DOUBLE.writeDouble(arrayWriter, i * 3 + j);
        }
        singleRowBlockWriter.closeEntry();
        // Write row type.
        BlockBuilder rowWriter = singleRowBlockWriter.beginBlockEntry();
        if (i % 2 == 0) {
            rowWriter.appendNull();
        } else {
            INTEGER.writeLong(rowWriter, i);
        }
        singleRowBlockWriter.closeEntry();
        beginEntryBlockBuilder.closeEntry();
        beginEntryBlockBuilder.appendNull();
    }
    RowBlockBuilder directEntryBlockBuilder = new RowBlockBuilder(rowType, null, 1);
    for (int i = 0; i < POSITION_COUNT; i++) {
        directEntryBlockBuilder.beginDirectEntry();
        REAL.writeLong(directEntryBlockBuilder.getBlockBuilder(0), i);
        // Write Map<Bigint, Varchar> with 5 entries.
        MapBlockBuilder mapBlockBuilder = (MapBlockBuilder) directEntryBlockBuilder.getBlockBuilder(1);
        mapBlockBuilder.beginDirectEntry();
        BlockBuilder keyBuilder = mapBlockBuilder.getKeyBlockBuilder();
        BlockBuilder valueBuilder = mapBlockBuilder.getValueBlockBuilder();
        for (int j = 0; j < 5; j++) {
            BIGINT.writeLong(keyBuilder, i + j);
            VARCHAR.writeSlice(valueBuilder, utf8Slice("Value1" + j));
        }
        mapBlockBuilder.closeEntry();
        // Write array .
        ArrayBlockBuilder arrayBuilder = (ArrayBlockBuilder) directEntryBlockBuilder.getBlockBuilder(2);
        arrayBuilder.beginDirectEntry();
        for (int j = 0; j < 8; j++) {
            DOUBLE.writeDouble(arrayBuilder.getElementBlockBuilder(), i * 3 + j);
        }
        arrayBuilder.closeEntry();
        // Write row type.
        RowBlockBuilder nestedRowBuilder = (RowBlockBuilder) directEntryBlockBuilder.getBlockBuilder(3);
        nestedRowBuilder.beginDirectEntry();
        BlockBuilder nestedRowValueBuilder = nestedRowBuilder.getBlockBuilder(0);
        if (i % 2 == 0) {
            nestedRowValueBuilder.appendNull();
        } else {
            INTEGER.writeLong(nestedRowValueBuilder, i);
        }
        nestedRowBuilder.closeEntry();
        directEntryBlockBuilder.closeEntry();
        directEntryBlockBuilder.appendNull();
    }
    Slice beginEntrySlice = getSlilce(beginEntryBlockBuilder);
    Slice directEntrySlice = getSlilce(directEntryBlockBuilder);
    assertEquals(beginEntrySlice.compareTo(directEntrySlice), 0);
}
Also used : RowBlockBuilder(com.facebook.presto.common.block.RowBlockBuilder) MapBlockBuilder(com.facebook.presto.common.block.MapBlockBuilder) RowType(com.facebook.presto.common.type.RowType) SingleRowBlockWriter(com.facebook.presto.common.block.SingleRowBlockWriter) MapType(com.facebook.presto.common.type.MapType) ArrayType(com.facebook.presto.common.type.ArrayType) MapType(com.facebook.presto.common.type.MapType) ArrayType(com.facebook.presto.common.type.ArrayType) Type(com.facebook.presto.common.type.Type) RowType(com.facebook.presto.common.type.RowType) ArrayBlockBuilder(com.facebook.presto.common.block.ArrayBlockBuilder) Slice(io.airlift.slice.Slice) Slices.utf8Slice(io.airlift.slice.Slices.utf8Slice) MapBlockBuilder(com.facebook.presto.common.block.MapBlockBuilder) RowBlockBuilder(com.facebook.presto.common.block.RowBlockBuilder) BlockBuilder(com.facebook.presto.common.block.BlockBuilder) ArrayBlockBuilder(com.facebook.presto.common.block.ArrayBlockBuilder) Test(org.testng.annotations.Test)

Example 3 with SingleRowBlockWriter

use of com.facebook.presto.common.block.SingleRowBlockWriter in project presto by prestodb.

the class TestSimpleRowType method getGreaterValue.

@Override
protected Object getGreaterValue(Object value) {
    RowBlockBuilder blockBuilder = (RowBlockBuilder) TYPE.createBlockBuilder(null, 1);
    SingleRowBlockWriter singleRowBlockWriter;
    Block block = (Block) value;
    singleRowBlockWriter = blockBuilder.beginBlockEntry();
    BIGINT.writeLong(singleRowBlockWriter, block.getSingleValueBlock(0).getLong(0) + 1);
    VARCHAR.writeSlice(singleRowBlockWriter, block.getSingleValueBlock(1).getSlice(0, 0, 1));
    blockBuilder.closeEntry();
    return TYPE.getObject(blockBuilder.build(), 0);
}
Also used : RowBlockBuilder(com.facebook.presto.common.block.RowBlockBuilder) Block(com.facebook.presto.common.block.Block) SingleRowBlockWriter(com.facebook.presto.common.block.SingleRowBlockWriter)

Aggregations

RowBlockBuilder (com.facebook.presto.common.block.RowBlockBuilder)3 SingleRowBlockWriter (com.facebook.presto.common.block.SingleRowBlockWriter)3 ArrayBlockBuilder (com.facebook.presto.common.block.ArrayBlockBuilder)1 Block (com.facebook.presto.common.block.Block)1 BlockBuilder (com.facebook.presto.common.block.BlockBuilder)1 MapBlockBuilder (com.facebook.presto.common.block.MapBlockBuilder)1 ArrayType (com.facebook.presto.common.type.ArrayType)1 MapType (com.facebook.presto.common.type.MapType)1 RowType (com.facebook.presto.common.type.RowType)1 Type (com.facebook.presto.common.type.Type)1 Slice (io.airlift.slice.Slice)1 Slices.utf8Slice (io.airlift.slice.Slices.utf8Slice)1 Test (org.testng.annotations.Test)1