use of io.trino.spi.PageBuilder in project trino by trinodb.
the class TestBlockBuilder method testNewBlockBuilderLike.
@Test
public void testNewBlockBuilderLike() {
ArrayType longArrayType = new ArrayType(BIGINT);
ArrayType arrayType = new ArrayType(longArrayType);
List<Type> channels = ImmutableList.of(BIGINT, VARCHAR, arrayType);
PageBuilder pageBuilder = new PageBuilder(channels);
BlockBuilder bigintBlockBuilder = pageBuilder.getBlockBuilder(0);
BlockBuilder varcharBlockBuilder = pageBuilder.getBlockBuilder(1);
BlockBuilder arrayBlockBuilder = pageBuilder.getBlockBuilder(2);
for (int i = 0; i < 100; i++) {
BIGINT.writeLong(bigintBlockBuilder, i);
VARCHAR.writeSlice(varcharBlockBuilder, Slices.utf8Slice("test" + i));
BlockBuilder blockBuilder = longArrayType.createBlockBuilder(null, 1);
longArrayType.writeObject(blockBuilder, BIGINT.createBlockBuilder(null, 2).writeLong(i).writeLong(i * 2).build());
arrayType.writeObject(arrayBlockBuilder, blockBuilder);
pageBuilder.declarePosition();
}
PageBuilder newPageBuilder = pageBuilder.newPageBuilderLike();
for (int i = 0; i < channels.size(); i++) {
assertEquals(newPageBuilder.getType(i), pageBuilder.getType(i));
// we should get new block builder instances
assertNotEquals(pageBuilder.getBlockBuilder(i), newPageBuilder.getBlockBuilder(i));
assertEquals(newPageBuilder.getBlockBuilder(i).getPositionCount(), 0);
assertTrue(newPageBuilder.getBlockBuilder(i).getRetainedSizeInBytes() < pageBuilder.getBlockBuilder(i).getRetainedSizeInBytes());
}
}
use of io.trino.spi.PageBuilder in project trino by trinodb.
the class TestPagesIndexPageSorter method createOutputPages.
private static List<Page> createOutputPages(List<Type> types, List<Page> inputPages, long[] sortedAddresses) {
PageBuilder pageBuilder = new PageBuilder(types);
pageBuilder.reset();
for (long address : sortedAddresses) {
int index = sorter.decodePageIndex(address);
int position = sorter.decodePositionIndex(address);
Page page = inputPages.get(index);
for (int i = 0; i < types.size(); i++) {
Type type = types.get(i);
type.appendTo(page.getBlock(i), position, pageBuilder.getBlockBuilder(i));
}
pageBuilder.declarePosition();
}
return ImmutableList.of(pageBuilder.build());
}
use of io.trino.spi.PageBuilder in project trino by trinodb.
the class TestShardCompactor method sortAndMaterialize.
private static MaterializedResult sortAndMaterialize(List<Page> pages, List<Type> columnTypes, List<Integer> sortIndexes, List<SortOrder> sortOrders, List<Type> sortTypes) {
long[] orderedAddresses = PAGE_SORTER.sort(columnTypes, pages, sortIndexes, sortOrders, 10_000);
PageBuilder pageBuilder = new PageBuilder(columnTypes);
for (long orderedAddress : orderedAddresses) {
int pageIndex = PAGE_SORTER.decodePageIndex(orderedAddress);
int positionIndex = PAGE_SORTER.decodePositionIndex(orderedAddress);
Page page = pages.get(pageIndex);
pageBuilder.declarePosition();
for (int i = 0; i < columnTypes.size(); i++) {
columnTypes.get(i).appendTo(page.getBlock(i), positionIndex, pageBuilder.getBlockBuilder(i));
}
}
// extract the sortIndexes and reorder the blocks by sort indexes (useful for debugging)
Page buildPage = pageBuilder.build();
Block[] outputBlocks = new Block[buildPage.getChannelCount()];
for (int i = 0; i < sortIndexes.size(); i++) {
outputBlocks[i] = buildPage.getBlock(sortIndexes.get(i));
}
MaterializedResult.Builder resultBuilder = MaterializedResult.resultBuilder(SESSION, sortTypes);
resultBuilder.page(new Page(outputBlocks));
return resultBuilder.build();
}
Aggregations