Search in sources :

Example 11 with RowBlock

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

the class TestStructColumnReader method testReaderLowerCasesFieldNamesFromType.

/**
 * Reader has fields with upper case characters, writer has same names downcased.
 */
@Test
public void testReaderLowerCasesFieldNamesFromType() throws IOException {
    List<String> readerFields = new ArrayList<>(Arrays.asList("field_A", "field_B", "field_C"));
    List<String> writerFields = new ArrayList<>(Arrays.asList("field_a", "field_b", "field_c"));
    List<String> writerData = new ArrayList<>(Arrays.asList("fieldAValue", "fieldBValue", "fieldCValue"));
    Type readerType = getType(readerFields);
    Type writerType = getType(writerFields);
    write(tempFile, writerType, writerData);
    RowBlock readBlock = read(tempFile, readerType);
    List<?> actual = (List<?>) readerType.getObjectValue(TestingConnectorSession.SESSION, readBlock, 0);
    assertEquals(actual.size(), readerFields.size());
    assertEquals(actual.get(0), "fieldAValue");
    assertEquals(actual.get(1), "fieldBValue");
    assertEquals(actual.get(2), "fieldCValue");
}
Also used : Type(io.trino.spi.type.Type) OrcType(io.trino.orc.metadata.OrcType) ArrayList(java.util.ArrayList) RowBlock(io.trino.spi.block.RowBlock) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) Test(org.testng.annotations.Test)

Example 12 with RowBlock

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

the class OrcFileWriter method appendRows.

@Override
public void appendRows(Page dataPage) {
    Block[] blocks = new Block[fileInputColumnIndexes.length];
    boolean[] nullBlocksArray = new boolean[fileInputColumnIndexes.length];
    boolean hasNullBlocks = false;
    int positionCount = dataPage.getPositionCount();
    for (int i = 0; i < fileInputColumnIndexes.length; i++) {
        int inputColumnIndex = fileInputColumnIndexes[i];
        if (inputColumnIndex < 0) {
            hasNullBlocks = true;
            blocks[i] = new RunLengthEncodedBlock(nullBlocks.get(i), positionCount);
        } else {
            blocks[i] = dataPage.getBlock(inputColumnIndex);
        }
        nullBlocksArray[i] = inputColumnIndex < 0;
    }
    if (transaction.isInsert() && useAcidSchema) {
        Optional<boolean[]> nullBlocks = hasNullBlocks ? Optional.of(nullBlocksArray) : Optional.empty();
        Block rowBlock = RowBlock.fromFieldBlocks(positionCount, nullBlocks, blocks);
        blocks = buildAcidColumns(rowBlock, transaction);
    }
    Page page = new Page(dataPage.getPositionCount(), blocks);
    try {
        orcWriter.write(page);
    } catch (IOException | UncheckedIOException e) {
        throw new TrinoException(HIVE_WRITER_DATA_ERROR, e);
    }
}
Also used : Block(io.trino.spi.block.Block) LongArrayBlock(io.trino.spi.block.LongArrayBlock) RunLengthEncodedBlock(io.trino.spi.block.RunLengthEncodedBlock) RowBlock(io.trino.spi.block.RowBlock) TrinoException(io.trino.spi.TrinoException) Page(io.trino.spi.Page) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) RunLengthEncodedBlock(io.trino.spi.block.RunLengthEncodedBlock)

Example 13 with RowBlock

use of io.trino.spi.block.RowBlock 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 14 with RowBlock

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

the class TestCheckpointWriter method makeComparableStatistics.

private Optional<Map<String, Object>> makeComparableStatistics(Optional<Map<String, Object>> original) {
    if (original.isEmpty()) {
        return Optional.empty();
    }
    Map<String, Object> stats = original.get();
    ImmutableMap.Builder<String, Object> comparableStats = ImmutableMap.builder();
    for (String key : stats.keySet()) {
        Object statsValue = stats.get(key);
        if (statsValue instanceof RowBlock) {
            RowBlock rowBlock = (RowBlock) statsValue;
            comparableStats.put(key, rowBlock.getChildren().stream().map(Block::getLogicalSizeInBytes).collect(toImmutableList()));
        } else {
            comparableStats.put(key, statsValue);
        }
    }
    return Optional.of(comparableStats.buildOrThrow());
}
Also used : Utils.nativeValueToBlock(io.trino.spi.predicate.Utils.nativeValueToBlock) Block(io.trino.spi.block.Block) RowBlock(io.trino.spi.block.RowBlock) RowBlock(io.trino.spi.block.RowBlock) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

RowBlock (io.trino.spi.block.RowBlock)14 Block (io.trino.spi.block.Block)8 Type (io.trino.spi.type.Type)8 ImmutableList (com.google.common.collect.ImmutableList)6 OrcType (io.trino.orc.metadata.OrcType)6 ArrayList (java.util.ArrayList)6 Test (org.testng.annotations.Test)6 List (java.util.List)5 RunLengthEncodedBlock (io.trino.spi.block.RunLengthEncodedBlock)4 Page (io.trino.spi.Page)3 ReaderUtils.verifyStreamType (io.trino.orc.reader.ReaderUtils.verifyStreamType)2 ColumnarRow (io.trino.spi.block.ColumnarRow)2 ColumnarRow.toColumnarRow (io.trino.spi.block.ColumnarRow.toColumnarRow)2 LazyBlock (io.trino.spi.block.LazyBlock)2 RowType (io.trino.spi.type.RowType)2 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 OrcCorruptionException (io.trino.orc.OrcCorruptionException)1 ColumnReaders.createColumnReader (io.trino.orc.reader.ColumnReaders.createColumnReader)1 Field (io.trino.parquet.Field)1