return pages;
}
List<TupleInfo> tupleInfos = getTupleInfos(pages);
PageBuilder pageBuilder = new PageBuilder(tupleInfos);
ImmutableList.Builder<Page> partitionedPages = ImmutableList.builder();
for (Page page : pages) {
// open the page
BlockCursor[] cursors = new BlockCursor[tupleInfos.size()];
for (int i = 0; i < cursors.length; i++) {
cursors[i] = page.getBlock(i).cursor();
}
// for each position
for (int position = 0; position < page.getPositionCount(); position++) {
// advance all cursors
for (BlockCursor cursor : cursors) {
cursor.advanceNextPosition();
}
// if hash is not in range skip
int partitionHashBucket = getPartitionHashBucket(tupleInfos, cursors);
if (partitionHashBucket != partition) {
continue;
}
// append row
for (int channel = 0; channel < cursors.length; channel++) {
pageBuilder.getBlockBuilder(channel).append(cursors[channel]);
}
// if page is full, flush
if (pageBuilder.isFull()) {
partitionedPages.add(pageBuilder.build());
pageBuilder.reset();
}
}
}
if (!pageBuilder.isEmpty()) {
partitionedPages.add(pageBuilder.build());
}
return partitionedPages.build();
}