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