use of io.prestosql.spi.PageBuilder in project hetu-core by openlookeng.
the class TestMergingPageIterator method testMerging.
@Test
public void testMerging() {
List<Type> types = ImmutableList.of(INTEGER, INTEGER);
List<Integer> sortIndexes = ImmutableList.of(1);
List<SortOrder> sortOrders = ImmutableList.of(SortOrder.ASC_NULLS_FIRST);
List<List<Page>> pageLists = new ArrayList<>();
PageBuilder pageBuilder = new PageBuilder(types);
for (int i = 0; i < 10; i++) {
Iterator<Integer> values = IntStream.range(0, 1000).map(ignored -> ThreadLocalRandom.current().nextInt(100_000)).mapToObj(n -> ((n % 100) == 0) ? null : n).sorted(nullsFirst(naturalOrder())).iterator();
List<Page> pages = new ArrayList<>();
for (int j = 0; j < 10; j++) {
for (int k = 0; k < 100; k++) {
Integer n = values.next();
pageBuilder.declarePosition();
if (n == null) {
pageBuilder.getBlockBuilder(0).appendNull();
pageBuilder.getBlockBuilder(1).appendNull();
} else {
INTEGER.writeLong(pageBuilder.getBlockBuilder(0), n);
INTEGER.writeLong(pageBuilder.getBlockBuilder(1), n * 22L);
}
}
pages.add(pageBuilder.build());
pageBuilder.reset();
}
pageLists.add(pages);
assertFalse(values.hasNext());
}
List<Iterator<Page>> pages = pageLists.stream().map(List::iterator).collect(toList());
Iterator<Page> iterator = new MergingPageIterator(pages, types, sortIndexes, sortOrders);
List<Long> values = new ArrayList<>();
while (iterator.hasNext()) {
Page page = iterator.next();
for (int i = 0; i < page.getPositionCount(); i++) {
if (page.getBlock(0).isNull(i)) {
assertTrue(page.getBlock(1).isNull(i));
values.add(null);
} else {
long x = INTEGER.getLong(page.getBlock(0), i);
long y = INTEGER.getLong(page.getBlock(1), i);
assertEquals(y, x * 22);
values.add(x);
}
}
}
assertThat(values).isSortedAccordingTo(nullsFirst(naturalOrder()));
}
use of io.prestosql.spi.PageBuilder in project hetu-core by openlookeng.
the class ArrayConcatFunction method concat.
@UsedByGeneratedCode
public static Block concat(Type elementType, Object state, Block[] blocks) {
int resultPositionCount = 0;
// fast path when there is at most one non empty block
Block nonEmptyBlock = null;
for (int i = 0; i < blocks.length; i++) {
resultPositionCount += blocks[i].getPositionCount();
if (blocks[i].getPositionCount() > 0) {
nonEmptyBlock = blocks[i];
}
}
if (nonEmptyBlock == null) {
return blocks[0];
}
if (resultPositionCount == nonEmptyBlock.getPositionCount()) {
return nonEmptyBlock;
}
PageBuilder pageBuilder = (PageBuilder) state;
if (pageBuilder.isFull()) {
pageBuilder.reset();
}
BlockBuilder blockBuilder = pageBuilder.getBlockBuilder(0);
for (int blockIndex = 0; blockIndex < blocks.length; blockIndex++) {
Block block = blocks[blockIndex];
for (int i = 0; i < block.getPositionCount(); i++) {
elementType.appendTo(block, i, blockBuilder);
}
}
pageBuilder.declarePositions(resultPositionCount);
return blockBuilder.getRegion(blockBuilder.getPositionCount() - resultPositionCount, resultPositionCount);
}
use of io.prestosql.spi.PageBuilder in project hetu-core by openlookeng.
the class GenericPartitioningSpiller method flush.
private synchronized ListenableFuture<?> flush(int partition) {
PageBuilder pageBuilder = pageBuilders.get(partition);
if (pageBuilder.isEmpty()) {
return Futures.immediateFuture(null);
}
Page page = pageBuilder.build();
pageBuilder.reset();
return getSpiller(partition).spill(page);
}
use of io.prestosql.spi.PageBuilder in project hetu-core by openlookeng.
the class MultiChannelGroupBySort method startNewPage.
private void startNewPage() {
if (currentPageBuilder != null) {
completedPagesMemorySize += currentPageBuilder.getRetainedSizeInBytes();
currentPageBuilder = currentPageBuilder.newPageBuilderLike();
if (nextGroupIdStartingRange == Integer.MAX_VALUE) {
nextGroupIdStartingRange = nextSortBasedGroupId;
} else {
maxGroupId.add(nextSortBasedGroupId);
}
} else {
currentPageBuilder = new PageBuilder(types);
}
for (int i = 0; i < types.size(); i++) {
channelBuilders.get(i).add(currentPageBuilder.getBlockBuilder(i));
}
}
use of io.prestosql.spi.PageBuilder in project hetu-core by openlookeng.
the class GroupAggregationOperator method getGlobalAggregationOutput.
protected Page getGlobalAggregationOutput() {
List<Accumulator> accumulators = accumulatorFactories.stream().map(AccumulatorFactory::createAccumulator).collect(Collectors.toList());
// global aggregation output page will only be constructed once,
// so a new PageBuilder is constructed (instead of using PageBuilder.reset)
PageBuilder output = new PageBuilder(globalAggregationGroupIds.size(), types);
for (int groupId : globalAggregationGroupIds) {
output.declarePosition();
int channel = 0;
for (; channel < groupByTypes.size(); channel++) {
if (channel == groupIdChannel.get()) {
output.getBlockBuilder(channel).writeLong(groupId);
} else {
output.getBlockBuilder(channel).appendNull();
}
}
if (hashChannel.isPresent()) {
long hashValue = calculateDefaultOutputHash(groupByTypes, groupIdChannel.get(), groupId);
output.getBlockBuilder(channel++).writeLong(hashValue);
}
for (int j = 0; j < accumulators.size(); channel++, j++) {
if (step.isOutputPartial()) {
accumulators.get(j).evaluateIntermediate(output.getBlockBuilder(channel));
} else {
accumulators.get(j).evaluateFinal(output.getBlockBuilder(channel));
}
}
}
if (output.isEmpty()) {
return null;
}
return output.build();
}
Aggregations