use of com.facebook.presto.common.block.ColumnarMap in project presto by prestodb.
the class MapColumnWriter method writeBlock.
@Override
public void writeBlock(ColumnChunk columnChunk) throws IOException {
ColumnarMap columnarMap = ColumnarMap.toColumnarMap(columnChunk.getBlock());
ImmutableList<DefinitionLevelIterable> defLevelIterables = ImmutableList.<DefinitionLevelIterable>builder().addAll(columnChunk.getDefinitionLevelIterables()).add(DefinitionLevelIterables.of(columnarMap, maxDefinitionLevel)).build();
ImmutableList<RepetitionLevelIterable> repLevelIterables = ImmutableList.<RepetitionLevelIterable>builder().addAll(columnChunk.getRepetitionLevelIterables()).add(RepetitionLevelIterables.of(columnarMap, maxRepetitionLevel)).build();
keyWriter.writeBlock(new ColumnChunk(columnarMap.getKeysBlock(), defLevelIterables, repLevelIterables));
valueWriter.writeBlock(new ColumnChunk(columnarMap.getValuesBlock(), defLevelIterables, repLevelIterables));
}
use of com.facebook.presto.common.block.ColumnarMap in project presto by prestodb.
the class TestMapBlockBuilder method testMapBlockBuilderWithNullKeys.
@Test
public void testMapBlockBuilderWithNullKeys() {
MapBlockBuilder blockBuilder = createMapBlockBuilder();
for (int i = 0; i < MAP_POSITIONS; i++) {
if (i % 10 == 0) {
// Map is null
blockBuilder.appendNull();
} else {
// Map is valid.
BlockBuilder entryBuilder = blockBuilder.beginBlockEntry();
for (int j = 0; j < i; j++) {
if (j == 5) {
// Null Keys
entryBuilder.appendNull();
} else {
BIGINT.writeLong(entryBuilder, j);
}
BIGINT.writeLong(entryBuilder, i);
}
blockBuilder.closeEntry();
}
assertFalse(blockBuilder.isHashTablesPresent());
}
// Verify the contents of the map.
MapBlock mapBlock = (MapBlock) blockBuilder.build();
assertFalse(mapBlock.isHashTablesPresent());
ColumnarMap columnarMap = ColumnarMap.toColumnarMap(mapBlock);
for (int i = 0; i < MAP_POSITIONS; i++) {
assertEquals(columnarMap.isNull(i), i % 10 == 0);
Block keysBlock = columnarMap.getKeysBlock();
Block valuesBlock = columnarMap.getValuesBlock();
if (!columnarMap.isNull(i)) {
int offset = columnarMap.getOffset(i);
for (int j = 0; j < i; j++) {
assertEquals(keysBlock.isNull(offset + j), j == 5);
if (!keysBlock.isNull(offset + j)) {
assertEquals(BIGINT.getLong(keysBlock, offset + j), j);
}
assertEquals(BIGINT.getLong(valuesBlock, offset + j), i);
}
}
}
// Verify block and newBlockBuilder does not have the hashTables present.
assertFalse(mapBlock.isHashTablesPresent());
MapBlockBuilder anotherBuilder = (MapBlockBuilder) blockBuilder.newBlockBuilderLike(null);
assertFalse(anotherBuilder.isHashTablesPresent());
}
use of com.facebook.presto.common.block.ColumnarMap in project presto by prestodb.
the class TestOrcMapNullKey method readMap.
private static Map<Long, Long> readMap(Block block, int rowId) {
ColumnarMap columnarMap = ColumnarMap.toColumnarMap(block);
assertFalse(columnarMap.isNull(rowId));
Block keysBlock = columnarMap.getKeysBlock();
Block valuesBlock = columnarMap.getValuesBlock();
Map<Long, Long> actual = new HashMap<>();
for (int i = 0; i < columnarMap.getEntryCount(rowId); i++) {
int position = columnarMap.getOffset(rowId) + i;
Long key = keysBlock.isNull(position) ? null : BIGINT.getLong(keysBlock, position);
Long value = valuesBlock.isNull(position) ? null : BIGINT.getLong(valuesBlock, position);
actual.put(key, value);
}
return actual;
}
use of com.facebook.presto.common.block.ColumnarMap in project presto by prestodb.
the class TestUnnesterUtil method buildExpectedUnnestedMapBlocks.
private static Block[] buildExpectedUnnestedMapBlocks(Block block, Type keyType, Type valueType, int[] maxCardinalities, int totalEntries) {
ColumnarMap columnarMap = ColumnarMap.toColumnarMap(block);
Block keyBlock = columnarMap.getKeysBlock();
Block valuesBlock = columnarMap.getValuesBlock();
BlockBuilder keyBlockBuilder = keyType.createBlockBuilder(null, totalEntries);
BlockBuilder valueBlockBuilder = valueType.createBlockBuilder(null, totalEntries);
int positionCount = block.getPositionCount();
int blockPosition = 0;
for (int i = 0; i < positionCount; i++) {
int cardinality = columnarMap.getEntryCount(i);
for (int j = 0; j < cardinality; j++) {
keyType.appendTo(keyBlock, blockPosition, keyBlockBuilder);
valueType.appendTo(valuesBlock, blockPosition, valueBlockBuilder);
blockPosition++;
}
int maxCardinality = maxCardinalities[i];
for (int j = cardinality; j < maxCardinality; j++) {
keyBlockBuilder.appendNull();
valueBlockBuilder.appendNull();
}
}
Block[] blocks = new Block[2];
blocks[0] = keyBlockBuilder.build();
blocks[1] = valueBlockBuilder.build();
return blocks;
}
Aggregations