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");
}
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);
}
}
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());
}
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());
}
Aggregations