Search in sources :

Example 1 with ParametricAggregation

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

the class TestAnnotationEngineForAggregates method testSimpleExplicitSpecializedAggregationParse.

// @Test - this is not yet supported
public void testSimpleExplicitSpecializedAggregationParse() {
    Signature expectedSignature = new Signature(QualifiedObjectName.valueOf(DEFAULT_NAMESPACE, "explicit_specialized_aggregate"), FunctionKind.AGGREGATE, ImmutableList.of(typeVariable("T")), ImmutableList.of(), parseTypeSignature("T"), ImmutableList.of(new TypeSignature(ARRAY, TypeSignatureParameter.of(parseTypeSignature("T")))), false);
    ParametricAggregation aggregation = parseFunctionDefinition(ExplicitSpecializedAggregationFunction.class);
    assertEquals(aggregation.getDescription(), "Simple explicit specialized aggregate");
    assertTrue(aggregation.isDeterministic());
    assertEquals(aggregation.getSignature(), expectedSignature);
    ParametricImplementationsGroup<AggregationImplementation> implementations = aggregation.getImplementations();
    assertImplementationCount(implementations, 0, 1, 1);
    AggregationImplementation implementation1 = implementations.getSpecializedImplementations().get(0);
    assertTrue(implementation1.hasSpecializedTypeParameters());
    assertFalse(implementation1.hasSpecializedTypeParameters());
    List<AggregationMetadata.ParameterMetadata.ParameterType> expectedMetadataTypes = ImmutableList.of(AggregationMetadata.ParameterMetadata.ParameterType.STATE, AggregationMetadata.ParameterMetadata.ParameterType.INPUT_CHANNEL);
    assertTrue(implementation1.getInputParameterMetadataTypes().equals(expectedMetadataTypes));
    AggregationImplementation implementation2 = implementations.getSpecializedImplementations().get(1);
    assertTrue(implementation2.hasSpecializedTypeParameters());
    assertFalse(implementation2.hasSpecializedTypeParameters());
    assertTrue(implementation2.getInputParameterMetadataTypes().equals(expectedMetadataTypes));
    InternalAggregationFunction specialized = aggregation.specialize(BoundVariables.builder().setTypeVariable("T", DoubleType.DOUBLE).build(), 1, FUNCTION_AND_TYPE_MANAGER);
    assertEquals(specialized.getFinalType(), DoubleType.DOUBLE);
    assertTrue(specialized.isDecomposable());
    assertEquals(specialized.name(), "implicit_specialized_aggregate");
}
Also used : AggregationImplementation(com.facebook.presto.operator.aggregation.AggregationImplementation) TypeSignature(com.facebook.presto.common.type.TypeSignature) TypeSignature.parseTypeSignature(com.facebook.presto.common.type.TypeSignature.parseTypeSignature) 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) InternalAggregationFunction(com.facebook.presto.operator.aggregation.InternalAggregationFunction)

Example 2 with ParametricAggregation

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

the class TestAnnotationEngineForAggregates method testNotDecomposableAggregationParse.

@Test
public void testNotDecomposableAggregationParse() {
    Signature expectedSignature = new Signature(QualifiedObjectName.valueOf(DEFAULT_NAMESPACE, "custom_decomposable_aggregate"), FunctionKind.AGGREGATE, DoubleType.DOUBLE.getTypeSignature(), ImmutableList.of(DoubleType.DOUBLE.getTypeSignature()));
    ParametricAggregation aggregation = parseFunctionDefinition(NotDecomposableAggregationFunction.class);
    assertEquals(aggregation.getDescription(), "Aggregate with Decomposable=false");
    assertTrue(aggregation.isDeterministic());
    assertEquals(aggregation.getSignature(), expectedSignature);
    InternalAggregationFunction specialized = aggregation.specialize(BoundVariables.builder().build(), 1, FUNCTION_AND_TYPE_MANAGER);
    assertEquals(specialized.getFinalType(), DoubleType.DOUBLE);
    assertFalse(specialized.isDecomposable());
    assertEquals(specialized.name(), "custom_decomposable_aggregate");
}
Also used : TypeSignature(com.facebook.presto.common.type.TypeSignature) TypeSignature.parseTypeSignature(com.facebook.presto.common.type.TypeSignature.parseTypeSignature) Signature(com.facebook.presto.spi.function.Signature) ParametricAggregation(com.facebook.presto.operator.aggregation.ParametricAggregation) InternalAggregationFunction(com.facebook.presto.operator.aggregation.InternalAggregationFunction) Test(org.testng.annotations.Test)

Example 3 with ParametricAggregation

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

the class TestAnnotationEngineForAggregates method testFixedTypeParameterInjectionAggregateFunctionParse.

@Test
public void testFixedTypeParameterInjectionAggregateFunctionParse() {
    Signature expectedSignature = new Signature(QualifiedObjectName.valueOf(DEFAULT_NAMESPACE, "fixed_type_parameter_injection"), FunctionKind.AGGREGATE, ImmutableList.of(), ImmutableList.of(), DoubleType.DOUBLE.getTypeSignature(), ImmutableList.of(DoubleType.DOUBLE.getTypeSignature()), false);
    ParametricAggregation aggregation = parseFunctionDefinition(FixedTypeParameterInjectionAggregateFunction.class);
    assertEquals(aggregation.getDescription(), "Simple aggregate with fixed parameter type injected");
    assertTrue(aggregation.isDeterministic());
    assertEquals(aggregation.getSignature(), expectedSignature);
    ParametricImplementationsGroup<AggregationImplementation> implementations = aggregation.getImplementations();
    assertImplementationCount(implementations, 1, 0, 0);
    AggregationImplementation implementationDouble = implementations.getExactImplementations().get(expectedSignature);
    assertFalse(implementationDouble.getStateSerializerFactory().isPresent());
    assertEquals(implementationDouble.getDefinitionClass(), FixedTypeParameterInjectionAggregateFunction.class);
    assertDependencyCount(implementationDouble, 1, 1, 1);
    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);
}
Also used : AggregationImplementation(com.facebook.presto.operator.aggregation.AggregationImplementation) 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) Test(org.testng.annotations.Test)

Example 4 with ParametricAggregation

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

the class TestAnnotationEngineForAggregates method testSimpleExactAggregationParse.

@Test
public void testSimpleExactAggregationParse() {
    Signature expectedSignature = new Signature(QualifiedObjectName.valueOf(DEFAULT_NAMESPACE, "simple_exact_aggregate"), FunctionKind.AGGREGATE, DoubleType.DOUBLE.getTypeSignature(), ImmutableList.of(DoubleType.DOUBLE.getTypeSignature()));
    ParametricAggregation aggregation = parseFunctionDefinition(ExactAggregationFunction.class);
    assertEquals(aggregation.getDescription(), "Simple exact aggregate description");
    assertTrue(aggregation.isDeterministic());
    assertEquals(aggregation.getSignature(), expectedSignature);
    ParametricImplementationsGroup<AggregationImplementation> implementations = aggregation.getImplementations();
    assertImplementationCount(implementations, 1, 0, 0);
    AggregationImplementation implementation = getOnlyElement(implementations.getExactImplementations().values());
    assertFalse(implementation.getStateSerializerFactory().isPresent());
    assertEquals(implementation.getDefinitionClass(), ExactAggregationFunction.class);
    assertDependencyCount(implementation, 0, 0, 0);
    assertFalse(implementation.hasSpecializedTypeParameters());
    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, FUNCTION_AND_TYPE_MANAGER);
    assertEquals(specialized.getFinalType(), DoubleType.DOUBLE);
    assertTrue(specialized.isDecomposable());
    assertEquals(specialized.name(), "simple_exact_aggregate");
}
Also used : AggregationImplementation(com.facebook.presto.operator.aggregation.AggregationImplementation) 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) InternalAggregationFunction(com.facebook.presto.operator.aggregation.InternalAggregationFunction) Test(org.testng.annotations.Test)

Example 5 with ParametricAggregation

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

the class TestAnnotationEngineForAggregates method testInjectTypeAggregateParse.

@Test
public void testInjectTypeAggregateParse() {
    Signature expectedSignature = new Signature(QualifiedObjectName.valueOf(DEFAULT_NAMESPACE, "inject_type_aggregate"), FunctionKind.AGGREGATE, ImmutableList.of(typeVariable("T")), ImmutableList.of(), parseTypeSignature("T"), ImmutableList.of(parseTypeSignature("T")), false);
    ParametricAggregation aggregation = parseFunctionDefinition(InjectTypeAggregateFunction.class);
    assertEquals(aggregation.getDescription(), "Simple aggregate with type injected");
    assertTrue(aggregation.isDeterministic());
    assertEquals(aggregation.getSignature(), expectedSignature);
    ParametricImplementationsGroup<AggregationImplementation> implementations = aggregation.getImplementations();
    assertEquals(implementations.getGenericImplementations().size(), 1);
    AggregationImplementation implementation = implementations.getGenericImplementations().get(0);
    assertTrue(implementation.getStateSerializerFactory().isPresent());
    assertEquals(implementation.getDefinitionClass(), InjectTypeAggregateFunction.class);
    assertDependencyCount(implementation, 1, 1, 1);
    assertEquals(implementation.getStateSerializerFactoryDependencies().size(), 1);
    assertTrue(implementation.getInputDependencies().get(0) instanceof TypeImplementationDependency);
    assertTrue(implementation.getCombineDependencies().get(0) instanceof TypeImplementationDependency);
    assertTrue(implementation.getOutputDependencies().get(0) instanceof TypeImplementationDependency);
    assertTrue(implementation.getStateSerializerFactoryDependencies().get(0) instanceof TypeImplementationDependency);
    assertFalse(implementation.hasSpecializedTypeParameters());
    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().setTypeVariable("T", DoubleType.DOUBLE).build(), 1, FUNCTION_AND_TYPE_MANAGER);
    assertEquals(specialized.getFinalType(), DoubleType.DOUBLE);
    assertTrue(specialized.isDecomposable());
    assertEquals(specialized.name(), "inject_type_aggregate");
}
Also used : AggregationImplementation(com.facebook.presto.operator.aggregation.AggregationImplementation) 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) InternalAggregationFunction(com.facebook.presto.operator.aggregation.InternalAggregationFunction) TypeImplementationDependency(com.facebook.presto.operator.annotations.TypeImplementationDependency) 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