use of io.trino.operator.aggregation.GroupedAggregator in project trino by trinodb.
the class InMemoryHashAggregationBuilder method getSizeInMemory.
public long getSizeInMemory() {
long sizeInMemory = groupByHash.getEstimatedSize();
for (GroupedAggregator groupedAggregator : groupedAggregators) {
sizeInMemory += groupedAggregator.getEstimatedSize();
}
updateIsFull(sizeInMemory);
return sizeInMemory;
}
use of io.trino.operator.aggregation.GroupedAggregator in project trino by trinodb.
the class TestSpatialPartitioningInternalAggregation method test.
@Test(dataProvider = "partitionCount")
public void test(int partitionCount) {
TestingAggregationFunction function = getFunction();
List<OGCGeometry> geometries = makeGeometries();
Block geometryBlock = makeGeometryBlock(geometries);
Block partitionCountBlock = BlockAssertions.createRLEBlock(partitionCount, geometries.size());
Rectangle expectedExtent = new Rectangle(-10, -10, Math.nextUp(10.0), Math.nextUp(10.0));
String expectedValue = getSpatialPartitioning(expectedExtent, geometries, partitionCount);
AggregatorFactory aggregatorFactory = function.createAggregatorFactory(SINGLE, Ints.asList(0, 1), OptionalInt.empty());
Page page = new Page(geometryBlock, partitionCountBlock);
Aggregator aggregator = aggregatorFactory.createAggregator();
aggregator.processPage(page);
String aggregation = (String) BlockAssertions.getOnlyValue(function.getFinalType(), getFinalBlock(function.getFinalType(), aggregator));
assertEquals(aggregation, expectedValue);
GroupedAggregator groupedAggregator = aggregatorFactory.createGroupedAggregator();
groupedAggregator.processPage(createGroupByIdBlock(0, page.getPositionCount()), page);
String groupValue = (String) getGroupValue(function.getFinalType(), groupedAggregator, 0);
assertEquals(groupValue, expectedValue);
}
use of io.trino.operator.aggregation.GroupedAggregator in project trino by trinodb.
the class InMemoryHashAggregationBuilder method buildResult.
private WorkProcessor<Page> buildResult(IntIterator groupIds) {
PageBuilder pageBuilder = new PageBuilder(buildTypes());
return WorkProcessor.create(() -> {
if (!groupIds.hasNext()) {
return ProcessState.finished();
}
pageBuilder.reset();
List<Type> types = groupByHash.getTypes();
while (!pageBuilder.isFull() && groupIds.hasNext()) {
int groupId = groupIds.nextInt();
groupByHash.appendValuesTo(groupId, pageBuilder, 0);
pageBuilder.declarePosition();
for (int i = 0; i < groupedAggregators.size(); i++) {
GroupedAggregator groupedAggregator = groupedAggregators.get(i);
BlockBuilder output = pageBuilder.getBlockBuilder(types.size() + i);
groupedAggregator.evaluate(groupId, output);
}
}
return ProcessState.ofResult(pageBuilder.build());
});
}
use of io.trino.operator.aggregation.GroupedAggregator in project trino by trinodb.
the class SkipAggregationBuilder method serializeAccumulatorState.
private BlockBuilder[] serializeAccumulatorState(int positionCount) {
BlockBuilder[] outputBuilders = new BlockBuilder[groupedAggregators.size()];
for (int i = 0; i < outputBuilders.length; i++) {
outputBuilders[i] = groupedAggregators.get(i).getType().createBlockBuilder(null, positionCount);
}
for (int position = 0; position < positionCount; position++) {
for (int i = 0; i < groupedAggregators.size(); i++) {
GroupedAggregator groupedAggregator = groupedAggregators.get(i);
BlockBuilder output = outputBuilders[i];
groupedAggregator.evaluate(position, output);
}
}
return outputBuilders;
}
Aggregations