Search in sources :

Example 1 with Accumulator

use of io.prestosql.operator.aggregation.Accumulator in project hetu-core by openlookeng.

the class TestEvaluateClassifierPredictions method testEvaluateClassifierPredictions.

@Test
public void testEvaluateClassifierPredictions() {
    metadata.getFunctionAndTypeManager().registerBuiltInFunctions(extractFunctions(new MLPlugin().getFunctions()));
    InternalAggregationFunction aggregation = metadata.getFunctionAndTypeManager().getAggregateFunctionImplementation(new Signature(QualifiedObjectName.valueOfDefaultFunction("evaluate_classifier_predictions"), AGGREGATE, parseTypeSignature(StandardTypes.VARCHAR), parseTypeSignature(StandardTypes.BIGINT), parseTypeSignature(StandardTypes.BIGINT)));
    Accumulator accumulator = aggregation.bind(ImmutableList.of(0, 1), Optional.empty()).createAccumulator();
    accumulator.addInput(getPage());
    BlockBuilder finalOut = accumulator.getFinalType().createBlockBuilder(null, 1);
    accumulator.evaluateFinal(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 : Accumulator(io.prestosql.operator.aggregation.Accumulator) TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) Signature(io.prestosql.spi.function.Signature) Block(io.prestosql.spi.block.Block) InternalAggregationFunction(io.prestosql.operator.aggregation.InternalAggregationFunction) BlockBuilder(io.prestosql.spi.block.BlockBuilder) Test(org.testng.annotations.Test)

Example 2 with Accumulator

use of io.prestosql.operator.aggregation.Accumulator in project hetu-core by openlookeng.

the class GroupAggregationOperator method getGlobalAggregationOutput.

protected Page getGlobalAggregationOutput() {
    List<Accumulator> accumulators = accumulatorFactories.stream().map(AccumulatorFactory::createAccumulator).collect(Collectors.toList());
    // global aggregation output page will only be constructed once,
    // so a new PageBuilder is constructed (instead of using PageBuilder.reset)
    PageBuilder output = new PageBuilder(globalAggregationGroupIds.size(), types);
    for (int groupId : globalAggregationGroupIds) {
        output.declarePosition();
        int channel = 0;
        for (; channel < groupByTypes.size(); channel++) {
            if (channel == groupIdChannel.get()) {
                output.getBlockBuilder(channel).writeLong(groupId);
            } else {
                output.getBlockBuilder(channel).appendNull();
            }
        }
        if (hashChannel.isPresent()) {
            long hashValue = calculateDefaultOutputHash(groupByTypes, groupIdChannel.get(), groupId);
            output.getBlockBuilder(channel++).writeLong(hashValue);
        }
        for (int j = 0; j < accumulators.size(); channel++, j++) {
            if (step.isOutputPartial()) {
                accumulators.get(j).evaluateIntermediate(output.getBlockBuilder(channel));
            } else {
                accumulators.get(j).evaluateFinal(output.getBlockBuilder(channel));
            }
        }
    }
    if (output.isEmpty()) {
        return null;
    }
    return output.build();
}
Also used : Accumulator(io.prestosql.operator.aggregation.Accumulator) PageBuilder(io.prestosql.spi.PageBuilder)

Example 3 with Accumulator

use of io.prestosql.operator.aggregation.Accumulator in project hetu-core by openlookeng.

the class TestSpatialPartitioningInternalAggregation method test.

@Test(dataProvider = "partitionCount")
public void test(int partitionCount) {
    InternalAggregationFunction 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);
    AccumulatorFactory accumulatorFactory = function.bind(Ints.asList(0, 1, 2), Optional.empty());
    Page page = new Page(geometryBlock, partitionCountBlock);
    Accumulator accumulator = accumulatorFactory.createAccumulator();
    accumulator.addInput(page);
    String aggregation = (String) BlockAssertions.getOnlyValue(accumulator.getFinalType(), getFinalBlock(accumulator));
    assertEquals(aggregation, expectedValue);
    GroupedAccumulator groupedAggregation = accumulatorFactory.createGroupedAccumulator();
    groupedAggregation.addInput(createGroupByIdBlock(0, page.getPositionCount()), page);
    String groupValue = (String) getGroupValue(groupedAggregation, 0);
    assertEquals(groupValue, expectedValue);
}
Also used : OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) Accumulator(io.prestosql.operator.aggregation.Accumulator) GroupedAccumulator(io.prestosql.operator.aggregation.GroupedAccumulator) AccumulatorFactory(io.prestosql.operator.aggregation.AccumulatorFactory) Rectangle(io.prestosql.geospatial.Rectangle) AggregationTestUtils.getFinalBlock(io.prestosql.operator.aggregation.AggregationTestUtils.getFinalBlock) Block(io.prestosql.spi.block.Block) AggregationTestUtils.createGroupByIdBlock(io.prestosql.operator.aggregation.AggregationTestUtils.createGroupByIdBlock) Page(io.prestosql.spi.Page) InternalAggregationFunction(io.prestosql.operator.aggregation.InternalAggregationFunction) GroupedAccumulator(io.prestosql.operator.aggregation.GroupedAccumulator) Test(org.testng.annotations.Test)

Aggregations

Accumulator (io.prestosql.operator.aggregation.Accumulator)3 InternalAggregationFunction (io.prestosql.operator.aggregation.InternalAggregationFunction)2 Block (io.prestosql.spi.block.Block)2 Test (org.testng.annotations.Test)2 OGCGeometry (com.esri.core.geometry.ogc.OGCGeometry)1 Rectangle (io.prestosql.geospatial.Rectangle)1 AccumulatorFactory (io.prestosql.operator.aggregation.AccumulatorFactory)1 AggregationTestUtils.createGroupByIdBlock (io.prestosql.operator.aggregation.AggregationTestUtils.createGroupByIdBlock)1 AggregationTestUtils.getFinalBlock (io.prestosql.operator.aggregation.AggregationTestUtils.getFinalBlock)1 GroupedAccumulator (io.prestosql.operator.aggregation.GroupedAccumulator)1 Page (io.prestosql.spi.Page)1 PageBuilder (io.prestosql.spi.PageBuilder)1 BlockBuilder (io.prestosql.spi.block.BlockBuilder)1 Signature (io.prestosql.spi.function.Signature)1 TypeSignature.parseTypeSignature (io.prestosql.spi.type.TypeSignature.parseTypeSignature)1