Search in sources :

Example 1 with TypeImplementationDependency

use of com.facebook.presto.operator.annotations.TypeImplementationDependency 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)

Example 2 with TypeImplementationDependency

use of com.facebook.presto.operator.annotations.TypeImplementationDependency in project presto by prestodb.

the class TestAnnotationEngineForScalars method testConstructorInjectionScalarParse.

@Test
public void testConstructorInjectionScalarParse() {
    Signature expectedSignature = new Signature(QualifiedObjectName.valueOf(DEFAULT_NAMESPACE, "parametric_scalar_inject_constructor"), FunctionKind.SCALAR, ImmutableList.of(typeVariable("T")), ImmutableList.of(), BIGINT.getTypeSignature(), ImmutableList.of(parseTypeSignature("array(T)")), false);
    List<SqlScalarFunction> functions = ScalarFromAnnotationsParser.parseFunctionDefinition(ConstructorInjectionScalarFunction.class);
    assertEquals(functions.size(), 1);
    ParametricScalar scalar = (ParametricScalar) functions.get(0);
    assertImplementationCount(scalar, 2, 0, 1);
    List<ParametricScalarImplementationChoice> parametricScalarImplementationChoices = scalar.getImplementations().getGenericImplementations().get(0).getChoices();
    assertEquals(parametricScalarImplementationChoices.size(), 1);
    List<ImplementationDependency> dependencies = parametricScalarImplementationChoices.get(0).getDependencies();
    assertEquals(dependencies.size(), 0);
    List<ImplementationDependency> constructorDependencies = parametricScalarImplementationChoices.get(0).getConstructorDependencies();
    assertEquals(constructorDependencies.size(), 1);
    assertTrue(constructorDependencies.get(0) instanceof TypeImplementationDependency);
    assertEquals(scalar.getSignature(), expectedSignature);
    assertTrue(scalar.isDeterministic());
    assertEquals(scalar.getVisibility(), PUBLIC);
    assertEquals(scalar.getDescription(), "Parametric scalar with type injected though constructor");
}
Also used : TypeImplementationDependency(com.facebook.presto.operator.annotations.TypeImplementationDependency) ImplementationDependency(com.facebook.presto.operator.annotations.ImplementationDependency) LiteralImplementationDependency(com.facebook.presto.operator.annotations.LiteralImplementationDependency) TypeSignature.parseTypeSignature(com.facebook.presto.common.type.TypeSignature.parseTypeSignature) Signature(com.facebook.presto.spi.function.Signature) ParametricScalarImplementationChoice(com.facebook.presto.operator.scalar.annotations.ParametricScalarImplementation.ParametricScalarImplementationChoice) ParametricScalar(com.facebook.presto.operator.scalar.ParametricScalar) SqlScalarFunction(com.facebook.presto.metadata.SqlScalarFunction) TypeImplementationDependency(com.facebook.presto.operator.annotations.TypeImplementationDependency) Test(org.testng.annotations.Test)

Aggregations

TypeSignature.parseTypeSignature (com.facebook.presto.common.type.TypeSignature.parseTypeSignature)2 TypeImplementationDependency (com.facebook.presto.operator.annotations.TypeImplementationDependency)2 Signature (com.facebook.presto.spi.function.Signature)2 Test (org.testng.annotations.Test)2 TypeSignature (com.facebook.presto.common.type.TypeSignature)1 SqlScalarFunction (com.facebook.presto.metadata.SqlScalarFunction)1 AggregationImplementation (com.facebook.presto.operator.aggregation.AggregationImplementation)1 AggregationMetadata (com.facebook.presto.operator.aggregation.AggregationMetadata)1 InternalAggregationFunction (com.facebook.presto.operator.aggregation.InternalAggregationFunction)1 ParametricAggregation (com.facebook.presto.operator.aggregation.ParametricAggregation)1 ImplementationDependency (com.facebook.presto.operator.annotations.ImplementationDependency)1 LiteralImplementationDependency (com.facebook.presto.operator.annotations.LiteralImplementationDependency)1 ParametricScalar (com.facebook.presto.operator.scalar.ParametricScalar)1 ParametricScalarImplementationChoice (com.facebook.presto.operator.scalar.annotations.ParametricScalarImplementation.ParametricScalarImplementationChoice)1