use of com.facebook.presto.spi.block.BlockBuilder in project presto by prestodb.
the class MarkDistinctHash method markDistinctRows.
public Block markDistinctRows(Page page) {
GroupByIdBlock ids = groupByHash.getGroupIds(page);
BlockBuilder blockBuilder = BOOLEAN.createBlockBuilder(new BlockBuilderStatus(), ids.getPositionCount());
for (int i = 0; i < ids.getPositionCount(); i++) {
if (ids.getGroupId(i) == nextDistinctId) {
BOOLEAN.writeBoolean(blockBuilder, true);
nextDistinctId++;
} else {
BOOLEAN.writeBoolean(blockBuilder, false);
}
}
return blockBuilder.build();
}
use of com.facebook.presto.spi.block.BlockBuilder in project presto by prestodb.
the class MetadataDeleteOperator method getOutput.
@Override
public Page getOutput() {
if (finished) {
return null;
}
finished = true;
OptionalLong rowsDeletedCount = metadata.metadataDelete(session, tableHandle, tableLayout);
PageBuilder page = new PageBuilder(TYPES);
BlockBuilder rowsBuilder = page.getBlockBuilder(0);
page.declarePosition();
if (rowsDeletedCount.isPresent()) {
BIGINT.writeLong(rowsBuilder, rowsDeletedCount.getAsLong());
} else {
rowsBuilder.appendNull();
}
return page.build();
}
use of com.facebook.presto.spi.block.BlockBuilder in project presto by prestodb.
the class MultiChannelGroupByHash method processDictionary.
private Block processDictionary(Page page) {
verify(canProcessDictionary(page), "invalid call to processDictionary");
DictionaryBlock dictionaryBlock = (DictionaryBlock) page.getBlock(channels[0]);
updateDictionaryLookBack(dictionaryBlock.getDictionary());
Page dictionaryPage = createPageWithExtractedDictionary(page);
BlockBuilder blockBuilder = BIGINT.createFixedSizeBlockBuilder(page.getPositionCount());
for (int i = 0; i < page.getPositionCount(); i++) {
int positionInDictionary = dictionaryBlock.getId(i);
int groupId = getGroupId(hashGenerator, dictionaryPage, positionInDictionary);
BIGINT.writeLong(blockBuilder, groupId);
}
verify(blockBuilder.getPositionCount() == page.getPositionCount(), "invalid position count");
return blockBuilder.build();
}
use of com.facebook.presto.spi.block.BlockBuilder in project presto by prestodb.
the class ArrayAggregationFunction method combine.
public static void combine(Type type, ArrayAggregationState state, ArrayAggregationState otherState) {
BlockBuilder stateBlockBuilder = state.getBlockBuilder();
BlockBuilder otherStateBlockBuilder = otherState.getBlockBuilder();
if (otherStateBlockBuilder == null) {
return;
}
if (stateBlockBuilder == null) {
state.setBlockBuilder(otherStateBlockBuilder);
return;
}
int otherPositionCount = otherStateBlockBuilder.getPositionCount();
long startSize = stateBlockBuilder.getRetainedSizeInBytes();
for (int i = 0; i < otherPositionCount; i++) {
type.appendTo(otherStateBlockBuilder, i, stateBlockBuilder);
}
state.addMemoryUsage(stateBlockBuilder.getRetainedSizeInBytes() - startSize);
}
use of com.facebook.presto.spi.block.BlockBuilder in project presto by prestodb.
the class DoubleHistogramAggregation method output.
@OutputFunction("map(double,double)")
public static void output(@AggregationState State state, BlockBuilder out) {
if (state.get() == null) {
out.appendNull();
} else {
Map<Double, Double> value = state.get().getBuckets();
BlockBuilder blockBuilder = DoubleType.DOUBLE.createBlockBuilder(new BlockBuilderStatus(), value.size() * 2);
for (Map.Entry<Double, Double> entry : value.entrySet()) {
DoubleType.DOUBLE.writeDouble(blockBuilder, entry.getKey());
DoubleType.DOUBLE.writeDouble(blockBuilder, entry.getValue());
}
Block block = blockBuilder.build();
out.writeObject(block);
out.closeEntry();
}
}
Aggregations