use of com.facebook.presto.common.PageBuilder in project presto by prestodb.
the class PinotSegmentPageSource method fillNextPage.
protected Page fillNextPage() {
// This is the list of handles we came up with when generating the PQL
// This could be a superset/permutation of the handles being requested in this scan
List<PinotColumnHandle> expectedColumnHandles = split.getExpectedColumnHandles();
PageBuilder pageBuilder = new PageBuilder(columnTypes);
// Note that declared positions in the Page should be the same with number of rows in each Block
pageBuilder.declarePositions(currentDataTable.getDataTable().getNumberOfRows());
for (int columnHandleIndex = 0; columnHandleIndex < columnHandles.size(); columnHandleIndex++) {
BlockBuilder blockBuilder = pageBuilder.getBlockBuilder(columnHandleIndex);
Type columnType = columnTypes.get(columnHandleIndex);
// Write a block for each column in the original order.
PinotColumnHandle handle = columnHandles.get(columnHandleIndex);
// map the handle needed by the scan to its index corresponding to the generated PQL
// All handles requested by the scan should be a subset of the expected handles
// ie., the expected column handles (corresponding to the generated PQL) can contain
// extra columns that we drop.
int indexReturnedByPinot = expectedColumnHandles.indexOf(handle);
if (indexReturnedByPinot < 0) {
throw new PinotException(PINOT_INVALID_PQL_GENERATED, split.getSegmentPinotQuery(), String.format("Expected column handle %s to be present in the handles %s corresponding to the segment PQL", handle, expectedColumnHandles));
}
writeBlock(blockBuilder, columnType, indexReturnedByPinot);
}
return pageBuilder.build();
}
use of com.facebook.presto.common.PageBuilder in project presto by prestodb.
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