Search in sources :

Example 1 with LiteralImplementationDependency

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

the class TestAnnotationEngineForScalars method testSimpleInjectionScalarParse.

@Test
public void testSimpleInjectionScalarParse() {
    Signature expectedSignature = new Signature("parametric_scalar_inject", ImmutableList.of(), ImmutableList.of(), BIGINT.getTypeSignature(), ImmutableList.of(new TypeSignature("varchar", TypeSignatureParameter.typeVariable("x"))), false);
    List<SqlScalarFunction> functions = ScalarFromAnnotationsParser.parseFunctionDefinition(SimpleInjectionScalarFunction.class);
    assertEquals(functions.size(), 1);
    ParametricScalar scalar = (ParametricScalar) functions.get(0);
    assertImplementationCount(scalar, 0, 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(), 1);
    assertTrue(dependencies.get(0) instanceof LiteralImplementationDependency);
    FunctionMetadata functionMetadata = scalar.getFunctionMetadata();
    assertEquals(functionMetadata.getSignature(), expectedSignature);
    assertTrue(functionMetadata.isDeterministic());
    assertFalse(functionMetadata.isHidden());
    assertEquals(functionMetadata.getDescription(), "Parametric scalar with literal injected");
}
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) 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) Test(org.testng.annotations.Test)

Example 2 with LiteralImplementationDependency

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

the class TestAnnotationEngineForAggregates method testInjectLiteralAggregateParse.

@Test
public void testInjectLiteralAggregateParse() {
    Signature expectedSignature = new Signature("inject_literal_aggregate", new TypeSignature("varchar", TypeSignatureParameter.typeVariable("x")), ImmutableList.of(new TypeSignature("varchar", TypeSignatureParameter.typeVariable("x"))));
    ParametricAggregation aggregation = getOnlyElement(parseFunctionDefinitions(InjectLiteralAggregateFunction.class));
    assertEquals(aggregation.getFunctionMetadata().getDescription(), "Simple aggregate with type literal");
    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(), InjectLiteralAggregateFunction.class);
    assertDependencyCount(implementation, 1, 1, 1);
    assertTrue(implementation.getInputDependencies().get(0) instanceof LiteralImplementationDependency);
    assertTrue(implementation.getCombineDependencies().get(0) instanceof LiteralImplementationDependency);
    assertTrue(implementation.getOutputDependencies().get(0) instanceof LiteralImplementationDependency);
    assertFalse(implementation.hasSpecializedTypeParameters());
    assertEquals(implementation.getInputParameterKinds(), ImmutableList.of(STATE, INPUT_CHANNEL));
    BoundSignature boundSignature = new BoundSignature(aggregation.getFunctionMetadata().getSignature().getName(), createVarcharType(17), ImmutableList.of(createVarcharType(17)));
    AggregationFunctionMetadata aggregationMetadata = aggregation.getAggregationMetadata();
    assertFalse(aggregationMetadata.isOrderSensitive());
    assertFalse(aggregationMetadata.getIntermediateTypes().isEmpty());
    aggregation.specialize(boundSignature, NO_FUNCTION_DEPENDENCIES);
}
Also used : AggregationImplementation(io.trino.operator.aggregation.AggregationImplementation) TypeSignature(io.trino.spi.type.TypeSignature) LiteralImplementationDependency(io.trino.operator.annotations.LiteralImplementationDependency) 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) AggregationFunctionMetadata(io.trino.metadata.AggregationFunctionMetadata) Test(org.testng.annotations.Test)

Aggregations

BoundSignature (io.trino.metadata.BoundSignature)2 Signature (io.trino.metadata.Signature)2 LiteralImplementationDependency (io.trino.operator.annotations.LiteralImplementationDependency)2 TypeSignature (io.trino.spi.type.TypeSignature)2 Test (org.testng.annotations.Test)2 AggregationFunctionMetadata (io.trino.metadata.AggregationFunctionMetadata)1 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 TypeImplementationDependency (io.trino.operator.annotations.TypeImplementationDependency)1 ParametricScalar (io.trino.operator.scalar.ParametricScalar)1 ParametricScalarImplementationChoice (io.trino.operator.scalar.annotations.ParametricScalarImplementation.ParametricScalarImplementationChoice)1