use of com.facebook.presto.common.PageBuilder in project presto by prestodb.
the class PinotBrokerPageSourceSql method buildBlockAndTypeBuilder.
@VisibleForTesting
@Override
public BlockAndTypeBuilder buildBlockAndTypeBuilder(List<PinotColumnHandle> columnHandles, GeneratedPinotQuery brokerSql) {
// When we created the SQL, we came up with some column handles
// however other optimizers post-pushdown can come in and prune/re-order the required column handles
// so we need to map from the column handles the PQL corresponds to, to the actual column handles
// needed in the scan.
List<Type> expectedTypes = columnHandles.stream().map(PinotColumnHandle::getDataType).collect(Collectors.toList());
PageBuilder pageBuilder = new PageBuilder(expectedTypes);
// The expectedColumnHandles are the handles corresponding to the generated SQL
// However, the engine could end up requesting only a permutation/subset of those handles
// during the actual scan
// Map the handles from planning time to the handles asked in the scan
// so that we know which columns to discard.
int[] handleMapping = new int[expectedHandles.size()];
for (int i = 0; i < handleMapping.length; ++i) {
handleMapping[i] = columnHandles.indexOf(expectedHandles.get(i));
}
ArrayList<BlockBuilder> columnBlockBuilders = new ArrayList<>();
ArrayList<Type> columnTypes = new ArrayList<>();
for (int expectedColumnIndex : brokerSql.getExpectedColumnIndices()) {
// columnIndex is the index of this column in the current scan
// It is obtained from the mapping and can be -ve, which means that the
// expectedColumnIndex'th column returned by Pinot can be discarded.
int columnIndex = -1;
if (expectedColumnIndex >= 0) {
columnIndex = handleMapping[expectedColumnIndex];
}
columnBlockBuilders.add(columnIndex >= 0 ? pageBuilder.getBlockBuilder(columnIndex) : null);
columnTypes.add(columnIndex >= 0 ? expectedTypes.get(columnIndex) : null);
}
return new BlockAndTypeBuilder(pageBuilder, columnBlockBuilders, columnTypes);
}
use of com.facebook.presto.common.PageBuilder in project presto by prestodb.
the class TableFinishOperator method getOutput.
@Override
public Page getOutput() {
if (!isBlocked().isDone()) {
return null;
}
if (!statisticsAggregationOperator.isFinished()) {
verify(statisticsAggregationOperator.isBlocked().isDone(), "aggregation operator should not be blocked");
OperationTimer timer = new OperationTimer(statisticsCpuTimerEnabled);
Page page = statisticsAggregationOperator.getOutput();
timer.end(statisticsTiming);
if (page == null) {
return null;
}
for (int position = 0; position < page.getPositionCount(); position++) {
computedStatisticsBuilder.add(getComputedStatistics(page, position));
}
return null;
}
if (state != State.FINISHING) {
return null;
}
state = State.FINISHED;
lifespanAndStageStateTracker.commit();
outputMetadata.set(tableFinisher.finishTable(lifespanAndStageStateTracker.getFinalFragments(), computedStatisticsBuilder.build()));
// output page will only be constructed once,
// so a new PageBuilder is constructed (instead of using PageBuilder.reset)
PageBuilder page = new PageBuilder(1, TYPES);
page.declarePosition();
BIGINT.writeLong(page.getBlockBuilder(0), lifespanAndStageStateTracker.getFinalRowCount());
return page.build();
}
use of com.facebook.presto.common.PageBuilder in project presto by prestodb.
the class RowNumberOperator method getSelectedRows.
private Page getSelectedRows() {
verify(selectedRowPageBuilder.isPresent());
int rowNumberChannel = types.size() - 1;
PageBuilder pageBuilder = selectedRowPageBuilder.get();
verify(pageBuilder.isEmpty());
for (int currentPosition = 0; currentPosition < inputPage.getPositionCount(); currentPosition++) {
long partitionId = getPartitionId(currentPosition);
long rowCount = partitionRowCount.get(partitionId);
if (rowCount == maxRowsPerPartition.get()) {
continue;
}
pageBuilder.declarePosition();
for (int i = 0; i < outputChannels.length; i++) {
int channel = outputChannels[i];
Type type = types.get(i);
type.appendTo(inputPage.getBlock(channel), currentPosition, pageBuilder.getBlockBuilder(i));
}
BIGINT.writeLong(pageBuilder.getBlockBuilder(rowNumberChannel), rowCount + 1);
partitionRowCount.set(partitionId, rowCount + 1);
}
if (pageBuilder.isEmpty()) {
return null;
}
Page page = pageBuilder.build();
pageBuilder.reset();
return page;
}
use of com.facebook.presto.common.PageBuilder in project presto by prestodb.
the class BenchmarkGroupByHash method bigintGroupByHash.
@Benchmark
@OperationsPerInvocation(POSITIONS)
public Object bigintGroupByHash(SingleChannelBenchmarkData data) {
GroupByHash groupByHash = new BigintGroupByHash(0, data.getHashEnabled(), EXPECTED_SIZE, NOOP);
for (Page page : data.getPages()) {
Work<?> work = groupByHash.addPage(page);
boolean finished;
do {
finished = work.process();
} while (!finished);
}
ImmutableList.Builder<Page> pages = ImmutableList.builder();
PageBuilder pageBuilder = new PageBuilder(groupByHash.getTypes());
for (int groupId = 0; groupId < groupByHash.getGroupCount(); groupId++) {
pageBuilder.declarePosition();
groupByHash.appendValuesTo(groupId, pageBuilder, 0);
if (pageBuilder.isFull()) {
pages.add(pageBuilder.build());
pageBuilder.reset();
}
}
pages.add(pageBuilder.build());
return pageBuilder.build();
}
use of com.facebook.presto.common.PageBuilder in project presto by prestodb.
the class BenchmarkGroupByHash method createVarcharPages.
private static List<Page> createVarcharPages(int positionCount, int groupCount, int channelCount, boolean hashEnabled) {
List<Type> types = Collections.nCopies(channelCount, VARCHAR);
ImmutableList.Builder<Page> pages = ImmutableList.builder();
if (hashEnabled) {
types = ImmutableList.copyOf(Iterables.concat(types, ImmutableList.of(BIGINT)));
}
PageBuilder pageBuilder = new PageBuilder(types);
for (int position = 0; position < positionCount; position++) {
int rand = ThreadLocalRandom.current().nextInt(groupCount);
Slice value = Slices.wrappedBuffer(ByteBuffer.allocate(4).putInt(rand));
pageBuilder.declarePosition();
for (int channel = 0; channel < channelCount; channel++) {
VARCHAR.writeSlice(pageBuilder.getBlockBuilder(channel), value);
}
if (hashEnabled) {
BIGINT.writeLong(pageBuilder.getBlockBuilder(channelCount), VarcharOperators.hashCode(value));
}
if (pageBuilder.isFull()) {
pages.add(pageBuilder.build());
pageBuilder.reset();
}
}
pages.add(pageBuilder.build());
return pages.build();
}
Aggregations