use of io.trino.operator.aggregation.Aggregator 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.Aggregator in project trino by trinodb.
the class TestEvaluateClassifierPredictions method testEvaluateClassifierPredictions.
@Test
public void testEvaluateClassifierPredictions() {
TestingFunctionResolution functionResolution = new TestingFunctionResolution(extractFunctions(new MLPlugin().getFunctions()));
TestingAggregationFunction aggregation = functionResolution.getAggregateFunction(QualifiedName.of("evaluate_classifier_predictions"), fromTypes(BIGINT, BIGINT));
Aggregator aggregator = aggregation.createAggregatorFactory(SINGLE, ImmutableList.of(0, 1), OptionalInt.empty()).createAggregator();
aggregator.processPage(getPage());
BlockBuilder finalOut = VARCHAR.createBlockBuilder(null, 1);
aggregator.evaluate(finalOut);
Block block = finalOut.build();
String output = VARCHAR.getSlice(block, 0).toStringUtf8();
List<String> parts = ImmutableList.copyOf(Splitter.on('\n').omitEmptyStrings().split(output));
assertEquals(parts.size(), 7, output);
assertEquals(parts.get(0), "Accuracy: 1/2 (50.00%)");
}
use of io.trino.operator.aggregation.Aggregator in project trino by trinodb.
the class AggregationOperator method getOutput.
@Override
public Page getOutput() {
if (state != State.HAS_OUTPUT) {
return null;
}
// project results into output blocks
List<Type> types = aggregates.stream().map(Aggregator::getType).collect(toImmutableList());
// output page will only be constructed once,
// so a new PageBuilder is constructed (instead of using PageBuilder.reset)
PageBuilder pageBuilder = new PageBuilder(1, types);
pageBuilder.declarePosition();
for (int i = 0; i < aggregates.size(); i++) {
Aggregator aggregator = aggregates.get(i);
BlockBuilder blockBuilder = pageBuilder.getBlockBuilder(i);
aggregator.evaluate(blockBuilder);
}
state = State.FINISHED;
return pageBuilder.build();
}
use of io.trino.operator.aggregation.Aggregator in project trino by trinodb.
the class AggregationOperator method addInput.
@Override
public void addInput(Page page) {
checkState(needsInput(), "Operator is already finishing");
requireNonNull(page, "page is null");
long memorySize = 0;
for (Aggregator aggregate : aggregates) {
aggregate.processPage(page);
memorySize += aggregate.getEstimatedSize();
}
userMemoryContext.setBytes(memorySize);
}
Aggregations