Search in sources :

Example 6 with ColumnarRow

use of io.trino.spi.block.ColumnarRow in project trino by trinodb.

the class StructColumnWriter method writeBlock.

@Override
public void writeBlock(ColumnChunk columnChunk) throws IOException {
    ColumnarRow columnarRow = toColumnarRow(columnChunk.getBlock());
    checkArgument(columnarRow.getFieldCount() == columnWriters.size(), "ColumnarRow field size %s is not equal to columnWriters size %s", columnarRow.getFieldCount(), columnWriters.size());
    List<DefLevelIterable> defLevelIterables = ImmutableList.<DefLevelIterable>builder().addAll(columnChunk.getDefLevelIterables()).add(DefLevelIterables.of(columnarRow, maxDefinitionLevel)).build();
    List<RepLevelIterable> repLevelIterables = ImmutableList.<RepLevelIterable>builder().addAll(columnChunk.getRepLevelIterables()).add(RepLevelIterables.of(columnChunk.getBlock())).build();
    for (int i = 0; i < columnWriters.size(); ++i) {
        ColumnWriter columnWriter = columnWriters.get(i);
        Block block = columnarRow.getField(i);
        columnWriter.writeBlock(new ColumnChunk(block, defLevelIterables, repLevelIterables));
    }
}
Also used : ColumnarRow.toColumnarRow(io.trino.spi.block.ColumnarRow.toColumnarRow) ColumnarRow(io.trino.spi.block.ColumnarRow) DefLevelIterable(io.trino.parquet.writer.repdef.DefLevelIterable) Block(io.trino.spi.block.Block) RepLevelIterable(io.trino.parquet.writer.repdef.RepLevelIterable)

Example 7 with ColumnarRow

use of io.trino.spi.block.ColumnarRow in project trino by trinodb.

the class TestReaderProjectionsAdapter method testLazyDereferenceProjectionLoading.

@Test
public void testLazyDereferenceProjectionLoading() {
    List<HiveColumnHandle> columns = ImmutableList.of(createProjectedColumnHandle(TEST_FULL_COLUMNS.get("col"), ImmutableList.of(0, 0)));
    List<Object> inputBlockData = new ArrayList<>();
    inputBlockData.add(rowData(rowData(11L, 12L, 13L), 1L));
    inputBlockData.add(rowData(null, 2L));
    inputBlockData.add(null);
    inputBlockData.add(rowData(rowData(31L, 32L, 33L), 3L));
    // Produce an output page by applying adaptation
    Optional<ReaderColumns> readerProjections = projectBaseColumns(columns);
    ReaderProjectionsAdapter adapter = new ReaderProjectionsAdapter(columns.stream().map(ColumnHandle.class::cast).collect(toImmutableList()), readerProjections.get(), column -> ((HiveColumnHandle) column).getType(), HivePageSourceProvider::getProjection);
    Page inputPage = createPage(ImmutableList.of(inputBlockData), adapter.getInputTypes());
    adapter.adaptPage(inputPage).getLoadedPage();
    // Verify that only the block corresponding to subfield "col.f_row_0.f_bigint_0" should be completely loaded, others are not.
    // Assertion for "col"
    Block lazyBlockLevel1 = inputPage.getBlock(0);
    assertTrue(lazyBlockLevel1 instanceof LazyBlock);
    assertFalse(lazyBlockLevel1.isLoaded());
    RowBlock rowBlockLevel1 = ((RowBlock) (((LazyBlock) lazyBlockLevel1).getBlock()));
    assertFalse(rowBlockLevel1.isLoaded());
    // Assertion for "col.f_row_0" and col.f_bigint_0"
    ColumnarRow columnarRowLevel1 = toColumnarRow(rowBlockLevel1);
    assertFalse(columnarRowLevel1.getField(0).isLoaded());
    assertFalse(columnarRowLevel1.getField(1).isLoaded());
    Block lazyBlockLevel2 = columnarRowLevel1.getField(0);
    assertTrue(lazyBlockLevel2 instanceof LazyBlock);
    RowBlock rowBlockLevel2 = ((RowBlock) (((LazyBlock) lazyBlockLevel2).getBlock()));
    assertFalse(rowBlockLevel2.isLoaded());
    ColumnarRow columnarRowLevel2 = toColumnarRow(rowBlockLevel2);
    // Assertion for "col.f_row_0.f_bigint_0" and "col.f_row_0.f_bigint_1"
    assertTrue(columnarRowLevel2.getField(0).isLoaded());
    assertFalse(columnarRowLevel2.getField(1).isLoaded());
}
Also used : ColumnHandle(io.trino.spi.connector.ColumnHandle) TestHiveReaderProjectionsUtil.createProjectedColumnHandle(io.trino.plugin.hive.TestHiveReaderProjectionsUtil.createProjectedColumnHandle) ArrayList(java.util.ArrayList) Page(io.trino.spi.Page) RowBlock(io.trino.spi.block.RowBlock) ColumnarRow.toColumnarRow(io.trino.spi.block.ColumnarRow.toColumnarRow) ColumnarRow(io.trino.spi.block.ColumnarRow) LazyBlock(io.trino.spi.block.LazyBlock) LazyBlock(io.trino.spi.block.LazyBlock) Block(io.trino.spi.block.Block) RowBlock(io.trino.spi.block.RowBlock) Test(org.testng.annotations.Test)

Example 8 with ColumnarRow

use of io.trino.spi.block.ColumnarRow in project trino by trinodb.

the class MultimapAggregationStateSerializer method deserialize.

@Override
public void deserialize(Block block, int index, MultimapAggregationState state) {
    state.reset();
    ColumnarRow columnarRow = toColumnarRow(arrayType.getObject(block, index));
    Block keys = columnarRow.getField(KEY_CHANNEL);
    Block values = columnarRow.getField(VALUE_CHANNEL);
    for (int i = 0; i < columnarRow.getPositionCount(); i++) {
        state.add(keys, values, i);
    }
}
Also used : ColumnarRow(io.trino.spi.block.ColumnarRow) ColumnarRow.toColumnarRow(io.trino.spi.block.ColumnarRow.toColumnarRow) Block(io.trino.spi.block.Block)

Example 9 with ColumnarRow

use of io.trino.spi.block.ColumnarRow in project trino by trinodb.

the class TestColumnarRow method assertColumnarRow.

private static <T> void assertColumnarRow(Block block, T[] expectedValues) {
    ColumnarRow columnarRow = toColumnarRow(block);
    assertEquals(columnarRow.getPositionCount(), expectedValues.length);
    for (int fieldId = 0; fieldId < FIELD_COUNT; fieldId++) {
        Block fieldBlock = columnarRow.getField(fieldId);
        int elementsPosition = 0;
        for (int position = 0; position < expectedValues.length; position++) {
            T expectedRow = expectedValues[position];
            assertEquals(columnarRow.isNull(position), expectedRow == null);
            if (expectedRow == null) {
                continue;
            }
            Object expectedElement = Array.get(expectedRow, fieldId);
            assertBlockPosition(fieldBlock, elementsPosition, expectedElement);
            elementsPosition++;
        }
    }
}
Also used : ColumnarRow.toColumnarRow(io.trino.spi.block.ColumnarRow.toColumnarRow) ColumnarRow(io.trino.spi.block.ColumnarRow) RunLengthEncodedBlock(io.trino.spi.block.RunLengthEncodedBlock) ColumnarTestUtils.createTestDictionaryBlock(io.trino.block.ColumnarTestUtils.createTestDictionaryBlock) ColumnarTestUtils.assertBlock(io.trino.block.ColumnarTestUtils.assertBlock) DictionaryBlock(io.trino.spi.block.DictionaryBlock) Block(io.trino.spi.block.Block) ColumnarTestUtils.createTestRleBlock(io.trino.block.ColumnarTestUtils.createTestRleBlock)

Aggregations

ColumnarRow (io.trino.spi.block.ColumnarRow)9 ColumnarRow.toColumnarRow (io.trino.spi.block.ColumnarRow.toColumnarRow)9 Block (io.trino.spi.block.Block)7 Page (io.trino.spi.Page)2 RowBlock (io.trino.spi.block.RowBlock)2 RunLengthEncodedBlock (io.trino.spi.block.RunLengthEncodedBlock)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 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 TestHiveReaderProjectionsUtil.createProjectedColumnHandle (io.trino.plugin.hive.TestHiveReaderProjectionsUtil.createProjectedColumnHandle)1 AbstractRowBlock (io.trino.spi.block.AbstractRowBlock)1 DictionaryBlock (io.trino.spi.block.DictionaryBlock)1 LazyBlock (io.trino.spi.block.LazyBlock)1 LongArrayBlock (io.trino.spi.block.LongArrayBlock)1 ColumnHandle (io.trino.spi.connector.ColumnHandle)1