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);
}
Aggregations