Search in sources :

Example 1 with Aggregator

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);
}
Also used : OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) GroupedAggregator(io.trino.operator.aggregation.GroupedAggregator) Rectangle(io.trino.geospatial.Rectangle) AggregationTestUtils.createGroupByIdBlock(io.trino.operator.aggregation.AggregationTestUtils.createGroupByIdBlock) AggregationTestUtils.getFinalBlock(io.trino.operator.aggregation.AggregationTestUtils.getFinalBlock) Block(io.trino.spi.block.Block) Aggregator(io.trino.operator.aggregation.Aggregator) GroupedAggregator(io.trino.operator.aggregation.GroupedAggregator) Page(io.trino.spi.Page) AggregatorFactory(io.trino.operator.aggregation.AggregatorFactory) TestingAggregationFunction(io.trino.operator.aggregation.TestingAggregationFunction) Test(org.testng.annotations.Test)

Example 2 with Aggregator

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%)");
}
Also used : TestingFunctionResolution(io.trino.metadata.TestingFunctionResolution) Aggregator(io.trino.operator.aggregation.Aggregator) Block(io.trino.spi.block.Block) TestingAggregationFunction(io.trino.operator.aggregation.TestingAggregationFunction) BlockBuilder(io.trino.spi.block.BlockBuilder) Test(org.testng.annotations.Test)

Example 3 with Aggregator

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();
}
Also used : Type(io.trino.spi.type.Type) Aggregator(io.trino.operator.aggregation.Aggregator) PageBuilder(io.trino.spi.PageBuilder) BlockBuilder(io.trino.spi.block.BlockBuilder)

Example 4 with Aggregator

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);
}
Also used : Aggregator(io.trino.operator.aggregation.Aggregator)

Aggregations

Aggregator (io.trino.operator.aggregation.Aggregator)4 TestingAggregationFunction (io.trino.operator.aggregation.TestingAggregationFunction)2 Block (io.trino.spi.block.Block)2 BlockBuilder (io.trino.spi.block.BlockBuilder)2 Test (org.testng.annotations.Test)2 OGCGeometry (com.esri.core.geometry.ogc.OGCGeometry)1 Rectangle (io.trino.geospatial.Rectangle)1 TestingFunctionResolution (io.trino.metadata.TestingFunctionResolution)1 AggregationTestUtils.createGroupByIdBlock (io.trino.operator.aggregation.AggregationTestUtils.createGroupByIdBlock)1 AggregationTestUtils.getFinalBlock (io.trino.operator.aggregation.AggregationTestUtils.getFinalBlock)1 AggregatorFactory (io.trino.operator.aggregation.AggregatorFactory)1 GroupedAggregator (io.trino.operator.aggregation.GroupedAggregator)1 Page (io.trino.spi.Page)1 PageBuilder (io.trino.spi.PageBuilder)1 Type (io.trino.spi.type.Type)1