Search in sources :

Example 16 with ParametricAggregation

use of com.facebook.presto.operator.aggregation.ParametricAggregation in project presto by prestodb.

the class TestAnnotationEngineForAggregates method testSimpleGenericAggregationFunctionParse.

@Test
public void testSimpleGenericAggregationFunctionParse() {
    Signature expectedSignature = new Signature(QualifiedObjectName.valueOf(DEFAULT_NAMESPACE, "simple_generic_implementations"), FunctionKind.AGGREGATE, ImmutableList.of(typeVariable("T")), ImmutableList.of(), parseTypeSignature("T"), ImmutableList.of(parseTypeSignature("T")), false);
    ParametricAggregation aggregation = parseFunctionDefinition(GenericAggregationFunction.class);
    assertEquals(aggregation.getDescription(), "Simple aggregate with two generic implementations");
    assertTrue(aggregation.isDeterministic());
    assertEquals(aggregation.getSignature(), expectedSignature);
    ParametricImplementationsGroup<AggregationImplementation> implementations = aggregation.getImplementations();
    assertImplementationCount(implementations, 0, 0, 2);
    AggregationImplementation implementationDouble = implementations.getGenericImplementations().stream().filter(impl -> impl.getStateClass() == NullableDoubleState.class).collect(toImmutableList()).get(0);
    assertFalse(implementationDouble.getStateSerializerFactory().isPresent());
    assertEquals(implementationDouble.getDefinitionClass(), GenericAggregationFunction.class);
    assertDependencyCount(implementationDouble, 0, 0, 0);
    assertFalse(implementationDouble.hasSpecializedTypeParameters());
    List<AggregationMetadata.ParameterMetadata.ParameterType> expectedMetadataTypes = ImmutableList.of(AggregationMetadata.ParameterMetadata.ParameterType.STATE, AggregationMetadata.ParameterMetadata.ParameterType.INPUT_CHANNEL);
    assertTrue(implementationDouble.getInputParameterMetadataTypes().equals(expectedMetadataTypes));
    assertEquals(implementationDouble.getStateClass(), NullableDoubleState.class);
    AggregationImplementation implementationLong = implementations.getGenericImplementations().stream().filter(impl -> impl.getStateClass() == NullableLongState.class).collect(toImmutableList()).get(0);
    assertFalse(implementationLong.getStateSerializerFactory().isPresent());
    assertEquals(implementationLong.getDefinitionClass(), GenericAggregationFunction.class);
    assertDependencyCount(implementationLong, 0, 0, 0);
    assertFalse(implementationLong.hasSpecializedTypeParameters());
    assertTrue(implementationLong.getInputParameterMetadataTypes().equals(expectedMetadataTypes));
    assertEquals(implementationLong.getStateClass(), NullableLongState.class);
    InternalAggregationFunction specialized = aggregation.specialize(BoundVariables.builder().setTypeVariable("T", DoubleType.DOUBLE).build(), 1, FUNCTION_AND_TYPE_MANAGER);
    assertEquals(specialized.getFinalType(), DoubleType.DOUBLE);
    assertTrue(specialized.getParameterTypes().equals(ImmutableList.of(DoubleType.DOUBLE)));
    assertTrue(specialized.isDecomposable());
    assertEquals(specialized.name(), "simple_generic_implementations");
}
Also used : AggregationImplementation(com.facebook.presto.operator.aggregation.AggregationImplementation) NullableLongState(com.facebook.presto.operator.aggregation.state.NullableLongState) TypeSignature(com.facebook.presto.common.type.TypeSignature) TypeSignature.parseTypeSignature(com.facebook.presto.common.type.TypeSignature.parseTypeSignature) Signature(com.facebook.presto.spi.function.Signature) AggregationMetadata(com.facebook.presto.operator.aggregation.AggregationMetadata) ParametricAggregation(com.facebook.presto.operator.aggregation.ParametricAggregation) NullableDoubleState(com.facebook.presto.operator.aggregation.state.NullableDoubleState) InternalAggregationFunction(com.facebook.presto.operator.aggregation.InternalAggregationFunction) Test(org.testng.annotations.Test)

Aggregations

ParametricAggregation (com.facebook.presto.operator.aggregation.ParametricAggregation)16 AggregationImplementation (com.facebook.presto.operator.aggregation.AggregationImplementation)15 TypeSignature (com.facebook.presto.common.type.TypeSignature)14 TypeSignature.parseTypeSignature (com.facebook.presto.common.type.TypeSignature.parseTypeSignature)14 AggregationMetadata (com.facebook.presto.operator.aggregation.AggregationMetadata)14 InternalAggregationFunction (com.facebook.presto.operator.aggregation.InternalAggregationFunction)14 Signature (com.facebook.presto.spi.function.Signature)14 Test (org.testng.annotations.Test)14 NullableDoubleState (com.facebook.presto.operator.aggregation.state.NullableDoubleState)2 NullableLongState (com.facebook.presto.operator.aggregation.state.NullableLongState)1 LiteralImplementationDependency (com.facebook.presto.operator.annotations.LiteralImplementationDependency)1 OperatorImplementationDependency (com.facebook.presto.operator.annotations.OperatorImplementationDependency)1 TypeImplementationDependency (com.facebook.presto.operator.annotations.TypeImplementationDependency)1 LongVariableConstraint (com.facebook.presto.spi.function.LongVariableConstraint)1