Search in sources :

Example 1 with ColumnarMap

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++;
        }
    }
}
Also used : ColumnarMap(io.trino.spi.block.ColumnarMap) ColumnarMap.toColumnarMap(io.trino.spi.block.ColumnarMap.toColumnarMap) Slice(io.airlift.slice.Slice) DictionaryBlock(io.trino.spi.block.DictionaryBlock) Block(io.trino.spi.block.Block) ColumnarTestUtils.createTestRleBlock(io.trino.block.ColumnarTestUtils.createTestRleBlock) RunLengthEncodedBlock(io.trino.spi.block.RunLengthEncodedBlock) ColumnarTestUtils.createTestDictionaryBlock(io.trino.block.ColumnarTestUtils.createTestDictionaryBlock) ColumnarTestUtils.assertBlock(io.trino.block.ColumnarTestUtils.assertBlock)

Example 2 with ColumnarMap

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);
}
Also used : ColumnarMap(io.trino.spi.block.ColumnarMap) ColumnarMap.toColumnarMap(io.trino.spi.block.ColumnarMap.toColumnarMap)

Example 3 with 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));
}
Also used : DefLevelIterable(io.trino.parquet.writer.repdef.DefLevelIterable) ColumnarMap(io.trino.spi.block.ColumnarMap) RepLevelIterable(io.trino.parquet.writer.repdef.RepLevelIterable)

Aggregations

ColumnarMap (io.trino.spi.block.ColumnarMap)3 ColumnarMap.toColumnarMap (io.trino.spi.block.ColumnarMap.toColumnarMap)2 Slice (io.airlift.slice.Slice)1 ColumnarTestUtils.assertBlock (io.trino.block.ColumnarTestUtils.assertBlock)1 ColumnarTestUtils.createTestDictionaryBlock (io.trino.block.ColumnarTestUtils.createTestDictionaryBlock)1 ColumnarTestUtils.createTestRleBlock (io.trino.block.ColumnarTestUtils.createTestRleBlock)1 DefLevelIterable (io.trino.parquet.writer.repdef.DefLevelIterable)1 RepLevelIterable (io.trino.parquet.writer.repdef.RepLevelIterable)1 Block (io.trino.spi.block.Block)1 DictionaryBlock (io.trino.spi.block.DictionaryBlock)1 RunLengthEncodedBlock (io.trino.spi.block.RunLengthEncodedBlock)1