Search in sources :

Example 1 with InternalAggregationFunction

use of io.prestosql.operator.aggregation.InternalAggregationFunction 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 InternalAggregationFunction

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

the class TestLearnAggregations method testLearnLibSvm.

@Test
public void testLearnLibSvm() {
    Type mapType = METADATA.getFunctionAndTypeManager().getParameterizedType("map", ImmutableList.of(TypeSignatureParameter.of(parseTypeSignature(StandardTypes.BIGINT)), TypeSignatureParameter.of(parseTypeSignature(StandardTypes.DOUBLE))));
    InternalAggregationFunction aggregation = parseFunctionDefinitionWithTypesConstraint(LearnLibSvmClassifierAggregation.class, BIGINT_CLASSIFIER.getTypeSignature(), ImmutableList.of(BIGINT.getTypeSignature(), mapType.getTypeSignature(), VarcharType.getParametrizedVarcharSignature("x"))).specialize(BoundVariables.builder().setLongVariable("x", (long) Integer.MAX_VALUE).build(), 3, METADATA.getFunctionAndTypeManager());
    assertLearnClassifer(aggregation.bind(ImmutableList.of(0, 1, 2), Optional.empty()).createAccumulator());
}
Also used : RegressorType(io.prestosql.plugin.ml.type.RegressorType) ModelType(io.prestosql.plugin.ml.type.ModelType) Type(io.prestosql.spi.type.Type) ClassifierParametricType(io.prestosql.plugin.ml.type.ClassifierParametricType) VarcharType(io.prestosql.spi.type.VarcharType) InternalAggregationFunction(io.prestosql.operator.aggregation.InternalAggregationFunction) Test(org.testng.annotations.Test)

Example 3 with InternalAggregationFunction

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

the class TestHashAggregationOperator method testHashAggregationMemoryReservation.

@Test(dataProvider = "hashEnabledAndMemoryLimitForMergeValues")
public void testHashAggregationMemoryReservation(boolean hashEnabled, boolean spillEnabled, boolean revokeMemoryWhenAddingPages, long memoryLimitForMerge, long memoryLimitForMergeWithMemory) {
    Metadata localMetadata = createTestMetadataManager();
    InternalAggregationFunction arrayAggColumn = localMetadata.getFunctionAndTypeManager().getAggregateFunctionImplementation(new Signature(QualifiedObjectName.valueOfDefaultFunction("array_agg"), AGGREGATE, parseTypeSignature("array(bigint)"), parseTypeSignature(StandardTypes.BIGINT)));
    List<Integer> hashChannels = Ints.asList(1);
    RowPagesBuilder rowPagesBuilder = rowPagesBuilder(hashEnabled, hashChannels, BIGINT, BIGINT);
    List<Page> input = rowPagesBuilder.addSequencePage(10, 100, 0).addSequencePage(10, 200, 0).addSequencePage(10, 300, 0).build();
    DriverContext driverContext = createTaskContext(executor, scheduledExecutor, TEST_SESSION, new DataSize(10, Unit.MEGABYTE)).addPipelineContext(0, true, true, false).addDriverContext();
    HashAggregationOperatorFactory operatorFactory = new HashAggregationOperatorFactory(0, new PlanNodeId("test"), ImmutableList.of(BIGINT), hashChannels, ImmutableList.of(), Step.SINGLE, true, ImmutableList.of(arrayAggColumn.bind(ImmutableList.of(0), Optional.empty())), rowPagesBuilder.getHashChannel(), Optional.empty(), 100_000, Optional.of(new DataSize(16, MEGABYTE)), spillEnabled, succinctBytes(memoryLimitForMerge), succinctBytes(memoryLimitForMergeWithMemory), spillerFactory, joinCompiler, false);
    Operator operator = operatorFactory.createOperator(driverContext);
    toPages(operator, input.iterator(), revokeMemoryWhenAddingPages);
    assertEquals(operator.getOperatorContext().getOperatorStats().getUserMemoryReservation().toBytes(), 0);
}
Also used : RowPagesBuilder(io.prestosql.RowPagesBuilder) Metadata(io.prestosql.metadata.Metadata) Page(io.prestosql.spi.Page) InternalAggregationFunction(io.prestosql.operator.aggregation.InternalAggregationFunction) PlanNodeId(io.prestosql.spi.plan.PlanNodeId) TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) Signature(io.prestosql.spi.function.Signature) DataSize(io.airlift.units.DataSize) HashAggregationOperatorFactory(io.prestosql.operator.HashAggregationOperator.HashAggregationOperatorFactory) Test(org.testng.annotations.Test)

Example 4 with InternalAggregationFunction

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

the class TestHashAggregationOperator method testMemoryLimit.

@Test(dataProvider = "hashEnabled", expectedExceptions = ExceededMemoryLimitException.class, expectedExceptionsMessageRegExp = "Query exceeded per-node user memory limit of 10B.*")
public void testMemoryLimit(boolean hashEnabled) {
    Metadata localMetadata = createTestMetadataManager();
    InternalAggregationFunction maxVarcharColumn = localMetadata.getFunctionAndTypeManager().getAggregateFunctionImplementation(new Signature(QualifiedObjectName.valueOfDefaultFunction("max"), AGGREGATE, parseTypeSignature(StandardTypes.VARCHAR), parseTypeSignature(StandardTypes.VARCHAR)));
    List<Integer> hashChannels = Ints.asList(1);
    RowPagesBuilder rowPagesBuilder = rowPagesBuilder(hashEnabled, hashChannels, VARCHAR, BIGINT, VARCHAR, BIGINT);
    List<Page> input = rowPagesBuilder.addSequencePage(10, 100, 0, 100, 0).addSequencePage(10, 100, 0, 200, 0).addSequencePage(10, 100, 0, 300, 0).build();
    DriverContext driverContext = createTaskContext(executor, scheduledExecutor, TEST_SESSION, new DataSize(10, Unit.BYTE)).addPipelineContext(0, true, true, false).addDriverContext();
    HashAggregationOperatorFactory operatorFactory = new HashAggregationOperatorFactory(0, new PlanNodeId("test"), ImmutableList.of(BIGINT), hashChannels, ImmutableList.of(), Step.SINGLE, ImmutableList.of(COUNT.bind(ImmutableList.of(0), Optional.empty()), LONG_SUM.bind(ImmutableList.of(3), Optional.empty()), LONG_AVERAGE.bind(ImmutableList.of(3), Optional.empty()), maxVarcharColumn.bind(ImmutableList.of(2), Optional.empty())), rowPagesBuilder.getHashChannel(), Optional.empty(), 100_000, Optional.of(new DataSize(16, MEGABYTE)), joinCompiler, false);
    toPages(operatorFactory, driverContext, input);
}
Also used : PlanNodeId(io.prestosql.spi.plan.PlanNodeId) RowPagesBuilder(io.prestosql.RowPagesBuilder) TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) Signature(io.prestosql.spi.function.Signature) DataSize(io.airlift.units.DataSize) Metadata(io.prestosql.metadata.Metadata) Page(io.prestosql.spi.Page) InternalAggregationFunction(io.prestosql.operator.aggregation.InternalAggregationFunction) HashAggregationOperatorFactory(io.prestosql.operator.HashAggregationOperator.HashAggregationOperatorFactory) Test(org.testng.annotations.Test)

Example 5 with InternalAggregationFunction

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

the class TestAnnotationEngineForAggregates method testNotAnnotatedAggregateStateAggregationParse.

@Test
public void testNotAnnotatedAggregateStateAggregationParse() {
    ParametricAggregation aggregation = parseFunctionDefinition(NotAnnotatedAggregateStateAggregationFunction.class);
    AggregationImplementation implementation = getOnlyElement(aggregation.getImplementations().getExactImplementations().values());
    List<AggregationMetadata.ParameterMetadata.ParameterType> expectedMetadataTypes = ImmutableList.of(AggregationMetadata.ParameterMetadata.ParameterType.STATE, AggregationMetadata.ParameterMetadata.ParameterType.INPUT_CHANNEL);
    assertTrue(implementation.getInputParameterMetadataTypes().equals(expectedMetadataTypes));
    InternalAggregationFunction specialized = aggregation.specialize(BoundVariables.builder().build(), 1, METADATA.getFunctionAndTypeManager());
    assertEquals(specialized.getFinalType(), DoubleType.DOUBLE);
    assertTrue(specialized.isDecomposable());
    assertEquals(specialized.name(), "no_aggregation_state_aggregate");
}
Also used : AggregationImplementation(io.prestosql.operator.aggregation.AggregationImplementation) AggregationMetadata(io.prestosql.operator.aggregation.AggregationMetadata) ParametricAggregation(io.prestosql.operator.aggregation.ParametricAggregation) InternalAggregationFunction(io.prestosql.operator.aggregation.InternalAggregationFunction) Test(org.testng.annotations.Test)

Aggregations

InternalAggregationFunction (io.prestosql.operator.aggregation.InternalAggregationFunction)82 Test (org.testng.annotations.Test)72 Signature (io.prestosql.spi.function.Signature)69 TypeSignature.parseTypeSignature (io.prestosql.spi.type.TypeSignature.parseTypeSignature)68 AggregationMetadata (io.prestosql.operator.aggregation.AggregationMetadata)17 ParametricAggregation (io.prestosql.operator.aggregation.ParametricAggregation)14 AggregationImplementation (io.prestosql.operator.aggregation.AggregationImplementation)13 TypeSignature (io.prestosql.spi.type.TypeSignature)13 PlanNodeId (io.prestosql.spi.plan.PlanNodeId)10 Page (io.prestosql.spi.Page)9 Type (io.prestosql.spi.type.Type)9 Metadata (io.prestosql.metadata.Metadata)7 DataSize (io.airlift.units.DataSize)6 RowPagesBuilder (io.prestosql.RowPagesBuilder)6 HashAggregationOperatorFactory (io.prestosql.operator.HashAggregationOperator.HashAggregationOperatorFactory)6 DynamicClassLoader (io.airlift.bytecode.DynamicClassLoader)5 AccumulatorStateDescriptor (io.prestosql.operator.aggregation.AggregationMetadata.AccumulatorStateDescriptor)5 GenericAccumulatorFactoryBinder (io.prestosql.operator.aggregation.GenericAccumulatorFactoryBinder)5 MaterializedResult (io.prestosql.testing.MaterializedResult)5 AggregationOperatorFactory (io.prestosql.operator.AggregationOperator.AggregationOperatorFactory)4