use of io.trino.spi.block.ColumnarMap in project trino by trinodb.
the class TestColumnarMap method assertColumnarMap.
private static void assertColumnarMap(Block block, Slice[][][] expectedValues) {
ColumnarMap columnarMap = toColumnarMap(block);
assertEquals(columnarMap.getPositionCount(), expectedValues.length);
Block keysBlock = columnarMap.getKeysBlock();
Block valuesBlock = columnarMap.getValuesBlock();
int elementsPosition = 0;
for (int position = 0; position < expectedValues.length; position++) {
Slice[][] expectedMap = expectedValues[position];
assertEquals(columnarMap.isNull(position), expectedMap == null);
if (expectedMap == null) {
assertEquals(columnarMap.getEntryCount(position), 0);
continue;
}
assertEquals(columnarMap.getEntryCount(position), expectedMap.length);
assertEquals(columnarMap.getOffset(position), elementsPosition);
for (int i = 0; i < columnarMap.getEntryCount(position); i++) {
Slice[] expectedEntry = expectedMap[i];
Slice expectedKey = expectedEntry[0];
assertBlockPosition(keysBlock, elementsPosition, expectedKey);
Slice expectedValue = expectedEntry[1];
assertBlockPosition(valuesBlock, elementsPosition, expectedValue);
elementsPosition++;
}
}
}
use of io.trino.spi.block.ColumnarMap in project trino by trinodb.
the class MapColumnWriter method writeBlock.
@Override
public void writeBlock(Block block) {
checkState(!closed);
checkArgument(block.getPositionCount() > 0, "Block is empty");
ColumnarMap columnarMap = toColumnarMap(block);
writeColumnarMap(columnarMap);
}
use of io.trino.spi.block.ColumnarMap in project trino by trinodb.
the class MapColumnWriter method writeBlock.
@Override
public void writeBlock(ColumnChunk columnChunk) throws IOException {
ColumnarMap columnarMap = ColumnarMap.toColumnarMap(columnChunk.getBlock());
ImmutableList<DefLevelIterable> defLevelIterables = ImmutableList.<DefLevelIterable>builder().addAll(columnChunk.getDefLevelIterables()).add(DefLevelIterables.of(columnarMap, maxDefinitionLevel)).build();
ImmutableList<RepLevelIterable> repLevelIterables = ImmutableList.<RepLevelIterable>builder().addAll(columnChunk.getRepLevelIterables()).add(RepLevelIterables.of(columnarMap, maxRepetitionLevel)).build();
keyWriter.writeBlock(new ColumnChunk(columnarMap.getKeysBlock(), defLevelIterables, repLevelIterables));
valueWriter.writeBlock(new ColumnChunk(columnarMap.getValuesBlock(), defLevelIterables, repLevelIterables));
}
Aggregations