Search in sources :

Example 1 with SingleArrayBlockWriter

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

the class TestDirectEntryBlockBuilder method testArrayWithNestedMap.

@Test
public void testArrayWithNestedMap() {
    MapType mapType = new MapType(BIGINT, VARCHAR, MethodHandleUtil.methodHandle(TestDirectEntryBlockBuilder.class, "throwUnsupportedOperation"), MethodHandleUtil.methodHandle(TestDirectEntryBlockBuilder.class, "throwUnsupportedOperation"));
    ArrayBlockBuilder beginEntryBlockBuilder = new ArrayBlockBuilder(mapType, null, POSITION_COUNT);
    for (int i = 0; i < POSITION_COUNT; i++) {
        SingleArrayBlockWriter singleArrayBlockWriter = beginEntryBlockBuilder.beginBlockEntry();
        for (int j = 0; j < 10; j++) {
            BlockBuilder innerMapWriter = singleArrayBlockWriter.beginBlockEntry();
            BIGINT.writeLong(innerMapWriter, i);
            VARCHAR.writeSlice(innerMapWriter, utf8Slice("Value1" + j));
            BIGINT.writeLong(innerMapWriter, i + 1);
            VARCHAR.writeSlice(innerMapWriter, utf8Slice("Value2" + j));
            singleArrayBlockWriter.closeEntry();
            singleArrayBlockWriter.appendNull();
        }
        beginEntryBlockBuilder.closeEntry();
    }
    ArrayBlockBuilder directEntryBlockBuilder = new ArrayBlockBuilder(mapType, null, POSITION_COUNT);
    for (int i = 0; i < POSITION_COUNT; i++) {
        directEntryBlockBuilder.beginDirectEntry();
        MapBlockBuilder innerBuilder = (MapBlockBuilder) directEntryBlockBuilder.getElementBlockBuilder();
        BlockBuilder keyBuilder = innerBuilder.getKeyBlockBuilder();
        BlockBuilder valueBuilder = innerBuilder.getValueBlockBuilder();
        for (int j = 0; j < 10; j++) {
            innerBuilder.beginDirectEntry();
            BIGINT.writeLong(keyBuilder, i);
            BIGINT.writeLong(keyBuilder, i + 1);
            VARCHAR.writeSlice(valueBuilder, utf8Slice("Value1" + j));
            VARCHAR.writeSlice(valueBuilder, utf8Slice("Value2" + j));
            innerBuilder.closeEntry();
            innerBuilder.appendNull();
        }
        directEntryBlockBuilder.closeEntry();
    }
    Slice beginEntrySlice = getSlilce(beginEntryBlockBuilder);
    Slice directEntrySlice = getSlilce(directEntryBlockBuilder);
    assertEquals(beginEntrySlice.compareTo(directEntrySlice), 0);
}
Also used : ArrayBlockBuilder(com.facebook.presto.common.block.ArrayBlockBuilder) SingleArrayBlockWriter(com.facebook.presto.common.block.SingleArrayBlockWriter) MapBlockBuilder(com.facebook.presto.common.block.MapBlockBuilder) Slice(io.airlift.slice.Slice) Slices.utf8Slice(io.airlift.slice.Slices.utf8Slice) MapType(com.facebook.presto.common.type.MapType) 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)

Aggregations

ArrayBlockBuilder (com.facebook.presto.common.block.ArrayBlockBuilder)1 BlockBuilder (com.facebook.presto.common.block.BlockBuilder)1 MapBlockBuilder (com.facebook.presto.common.block.MapBlockBuilder)1 RowBlockBuilder (com.facebook.presto.common.block.RowBlockBuilder)1 SingleArrayBlockWriter (com.facebook.presto.common.block.SingleArrayBlockWriter)1 MapType (com.facebook.presto.common.type.MapType)1 Slice (io.airlift.slice.Slice)1 Slices.utf8Slice (io.airlift.slice.Slices.utf8Slice)1 Test (org.testng.annotations.Test)1