Source:
public Page getNextPage() { if (types.isEmpty()) { int rowCount = 0; synchronized (this) { while (true) { if (currentIteratorIndex >= rowIterators.size()) { break; } if (rowCount >= MAX_ROWS_PER_ZERO_COLUMN_PAGE) { break; } Iterator<Tuple2<MutablePartitionId, PrestoSparkMutableRow>> currentIterator = rowIterators.get(currentIteratorIndex); if (!currentIterator.hasNext()) { currentIteratorIndex++; continue; } currentIterator.next(); rowCount++; } } if (rowCount == 0) { return null; } return new Page(rowCount); } SliceOutput output = new DynamicSliceOutput(BUFFER_SIZE); int rowCount = 0; synchronized (this) { while (true) { if (currentIteratorIndex >= rowIterators.size()) { break; } if (output.size() >= TARGET_SIZE) { break; } Iterator<Tuple2<MutablePartitionId, PrestoSparkMutableRow>> currentIterator = rowIterators.get(currentIteratorIndex); if (!currentIterator.hasNext()) { currentIteratorIndex++; continue; } PrestoSparkMutableRow row = currentIterator.next()._2; ByteBuffer buffer = row.getBuffer(); output.writeBytes(buffer.array(), buffer.arrayOffset() + buffer.position(), buffer.remaining()); rowCount++; } } if (rowCount == 0) { return null; } SliceInput sliceInput = output.slice().getInput(); PageBuilder pageBuilder = new PageBuilder(types); while (sliceInput.isReadable()) { pageBuilder.declarePosition(); for (int channel = 0; channel < types.size(); channel++) { BlockBuilder blockBuilder = pageBuilder.getBlockBuilder(channel); blockBuilder.readPositionFrom(sliceInput); } } Page page = pageBuilder.build(); verify(page.getPositionCount() == rowCount, "unexpected row count: %s != %s", page.getPositionCount(), rowCount); return page; }

Target:
public Page getNextPage() { if (types.isEmpty()) { int rowCount = 0; synchronized (this) { while (true) { if (currentIteratorIndex >= rowIterators.size()) { break; } if (rowCount >= MAX_ROWS_PER_ZERO_COLUMN_PAGE) { break; } Iterator<Tuple2<MutablePartitionId, PrestoSparkMutableRow>> currentIterator = rowIterators.get(currentIteratorIndex); if (currentIterator.hasNext()) { currentIterator.next(); rowCount++; } else { currentIteratorIndex++; } } } if (rowCount == 0) { return null; } return new Page(rowCount); } SliceOutput output = new DynamicSliceOutput(BUFFER_SIZE); int rowCount = 0; synchronized (this) { while (true) { if (currentIteratorIndex >= rowIterators.size()) { break; } if (output.size() >= TARGET_SIZE) { break; } Iterator<Tuple2<MutablePartitionId, PrestoSparkMutableRow>> currentIterator = rowIterators.get(currentIteratorIndex); if (currentIterator.hasNext()) { PrestoSparkMutableRow row = currentIterator.next()._2; ByteBuffer buffer = row.getBuffer(); output.writeBytes(buffer.array(), buffer.arrayOffset() + buffer.position(), buffer.remaining()); rowCount++; } else { currentIteratorIndex++; } } } if (rowCount == 0) { return null; } SliceInput sliceInput = output.slice().getInput(); PageBuilder pageBuilder = new PageBuilder(types); while (sliceInput.isReadable()) { pageBuilder.declarePosition(); for (int channel = 0; channel < types.size(); channel++) { BlockBuilder blockBuilder = pageBuilder.getBlockBuilder(channel); blockBuilder.readPositionFrom(sliceInput); } } Page page = pageBuilder.build(); verify(page.getPositionCount() == rowCount, "unexpected row count: %s != %s", page.getPositionCount(), rowCount); return page; }