Search in sources :

Example 1 with TypeImplementationDependency

use of io.trino.operator.annotations.TypeImplementationDependency in project trino by trinodb.

the class TestAnnotationEngineForScalars method testConstructorInjectionScalarParse.

@Test
public void testConstructorInjectionScalarParse() {
    Signature expectedSignature = new Signature("parametric_scalar_inject_constructor", ImmutableList.of(typeVariable("T")), ImmutableList.of(), BIGINT.getTypeSignature(), ImmutableList.of(arrayType(new TypeSignature("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);
    FunctionMetadata functionMetadata = scalar.getFunctionMetadata();
    assertEquals(functionMetadata.getSignature(), expectedSignature);
    assertTrue(functionMetadata.isDeterministic());
    assertFalse(functionMetadata.isHidden());
    assertEquals(functionMetadata.getDescription(), "Parametric scalar with type injected though constructor");
}
Also used : FunctionMetadata(io.trino.metadata.FunctionMetadata) TypeSignature(io.trino.spi.type.TypeSignature) ImplementationDependency(io.trino.operator.annotations.ImplementationDependency) TypeImplementationDependency(io.trino.operator.annotations.TypeImplementationDependency) LiteralImplementationDependency(io.trino.operator.annotations.LiteralImplementationDependency) Signature(io.trino.metadata.Signature) TypeSignature(io.trino.spi.type.TypeSignature) BoundSignature(io.trino.metadata.BoundSignature) ParametricScalarImplementationChoice(io.trino.operator.scalar.annotations.ParametricScalarImplementation.ParametricScalarImplementationChoice) ParametricScalar(io.trino.operator.scalar.ParametricScalar) SqlScalarFunction(io.trino.metadata.SqlScalarFunction) TypeImplementationDependency(io.trino.operator.annotations.TypeImplementationDependency) Test(org.testng.annotations.Test)

Example 2 with TypeImplementationDependency

use of io.trino.operator.annotations.TypeImplementationDependency in project trino by trinodb.

the class TestAnnotationEngineForAggregates method testInjectTypeAggregateParse.

@Test
public void testInjectTypeAggregateParse() {
    Signature expectedSignature = new Signature("inject_type_aggregate", ImmutableList.of(typeVariable("T")), ImmutableList.of(), new TypeSignature("T"), ImmutableList.of(new TypeSignature("T")), false);
    ParametricAggregation aggregation = getOnlyElement(parseFunctionDefinitions(InjectTypeAggregateFunction.class));
    assertEquals(aggregation.getFunctionMetadata().getDescription(), "Simple aggregate with type injected");
    assertTrue(aggregation.getFunctionMetadata().isDeterministic());
    assertEquals(aggregation.getFunctionMetadata().getSignature(), expectedSignature);
    ParametricImplementationsGroup<AggregationImplementation> implementations = aggregation.getImplementations();
    assertEquals(implementations.getGenericImplementations().size(), 1);
    AggregationImplementation implementation = implementations.getGenericImplementations().get(0);
    assertEquals(implementation.getDefinitionClass(), InjectTypeAggregateFunction.class);
    assertDependencyCount(implementation, 1, 1, 1);
    assertTrue(implementation.getInputDependencies().get(0) instanceof TypeImplementationDependency);
    assertTrue(implementation.getCombineDependencies().get(0) instanceof TypeImplementationDependency);
    assertTrue(implementation.getOutputDependencies().get(0) instanceof TypeImplementationDependency);
    assertFalse(implementation.hasSpecializedTypeParameters());
    assertEquals(implementation.getInputParameterKinds(), ImmutableList.of(STATE, INPUT_CHANNEL));
    BoundSignature boundSignature = new BoundSignature(aggregation.getFunctionMetadata().getSignature().getName(), DoubleType.DOUBLE, ImmutableList.of(DoubleType.DOUBLE));
    specializeAggregationFunction(boundSignature, aggregation);
}
Also used : AggregationImplementation(io.trino.operator.aggregation.AggregationImplementation) TypeSignature(io.trino.spi.type.TypeSignature) TypeSignature(io.trino.spi.type.TypeSignature) Signature(io.trino.metadata.Signature) BoundSignature(io.trino.metadata.BoundSignature) BoundSignature(io.trino.metadata.BoundSignature) ParametricAggregation(io.trino.operator.aggregation.ParametricAggregation) TypeImplementationDependency(io.trino.operator.annotations.TypeImplementationDependency) Test(org.testng.annotations.Test)

Aggregations

BoundSignature (io.trino.metadata.BoundSignature)2 Signature (io.trino.metadata.Signature)2 TypeImplementationDependency (io.trino.operator.annotations.TypeImplementationDependency)2 TypeSignature (io.trino.spi.type.TypeSignature)2 Test (org.testng.annotations.Test)2 FunctionMetadata (io.trino.metadata.FunctionMetadata)1 SqlScalarFunction (io.trino.metadata.SqlScalarFunction)1 AggregationImplementation (io.trino.operator.aggregation.AggregationImplementation)1 ParametricAggregation (io.trino.operator.aggregation.ParametricAggregation)1 ImplementationDependency (io.trino.operator.annotations.ImplementationDependency)1 LiteralImplementationDependency (io.trino.operator.annotations.LiteralImplementationDependency)1 ParametricScalar (io.trino.operator.scalar.ParametricScalar)1 ParametricScalarImplementationChoice (io.trino.operator.scalar.annotations.ParametricScalarImplementation.ParametricScalarImplementationChoice)1