Search in sources :

Example 26 with BoundSignature

use of io.trino.metadata.BoundSignature in project trino by trinodb.

the class TestAnnotationEngineForAggregates method testSimpleExactAggregationParse.

@Test
public void testSimpleExactAggregationParse() {
    Signature expectedSignature = new Signature("simple_exact_aggregate", DoubleType.DOUBLE.getTypeSignature(), ImmutableList.of(DoubleType.DOUBLE.getTypeSignature()));
    ParametricAggregation aggregation = getOnlyElement(parseFunctionDefinitions(ExactAggregationFunction.class));
    assertEquals(aggregation.getFunctionMetadata().getDescription(), "Simple exact aggregate description");
    assertTrue(aggregation.getFunctionMetadata().isDeterministic());
    assertEquals(aggregation.getFunctionMetadata().getSignature(), expectedSignature);
    ParametricImplementationsGroup<AggregationImplementation> implementations = aggregation.getImplementations();
    assertImplementationCount(implementations, 1, 0, 0);
    AggregationImplementation implementation = getOnlyElement(implementations.getExactImplementations().values());
    assertEquals(implementation.getDefinitionClass(), ExactAggregationFunction.class);
    assertDependencyCount(implementation, 0, 0, 0);
    assertFalse(implementation.hasSpecializedTypeParameters());
    assertEquals(implementation.getInputParameterKinds(), ImmutableList.of(STATE, INPUT_CHANNEL));
    BoundSignature boundSignature = new BoundSignature(expectedSignature.getName(), DoubleType.DOUBLE, ImmutableList.of(DoubleType.DOUBLE));
    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) 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)

Example 27 with BoundSignature

use of io.trino.metadata.BoundSignature in project trino by trinodb.

the class TestAnnotationEngineForScalars method testSingleImplementationScalarParse.

@Test
public void testSingleImplementationScalarParse() {
    Signature expectedSignature = new Signature("single_implementation_parametric_scalar", DOUBLE.getTypeSignature(), ImmutableList.of(DOUBLE.getTypeSignature()));
    List<SqlScalarFunction> functions = ScalarFromAnnotationsParser.parseFunctionDefinition(SingleImplementationScalarFunction.class);
    assertEquals(functions.size(), 1);
    ParametricScalar scalar = (ParametricScalar) functions.get(0);
    FunctionMetadata functionMetadata = scalar.getFunctionMetadata();
    assertEquals(functionMetadata.getSignature(), expectedSignature);
    assertTrue(functionMetadata.isDeterministic());
    assertFalse(functionMetadata.isHidden());
    assertEquals(functionMetadata.getDescription(), "Simple scalar with single implementation based on class");
    assertFalse(functionMetadata.getFunctionNullability().isArgumentNullable(0));
    assertImplementationCount(scalar, 1, 0, 0);
    BoundSignature boundSignature = new BoundSignature(expectedSignature.getName(), DOUBLE, ImmutableList.of(DOUBLE));
    ChoicesScalarFunctionImplementation specialized = (ChoicesScalarFunctionImplementation) scalar.specialize(boundSignature, new FunctionDependencies(FUNCTION_MANAGER::getScalarFunctionInvoker, ImmutableMap.of(), ImmutableSet.of()));
    assertFalse(specialized.getChoices().get(0).getInstanceFactory().isPresent());
}
Also used : FunctionMetadata(io.trino.metadata.FunctionMetadata) Signature(io.trino.metadata.Signature) TypeSignature(io.trino.spi.type.TypeSignature) BoundSignature(io.trino.metadata.BoundSignature) BoundSignature(io.trino.metadata.BoundSignature) ParametricScalar(io.trino.operator.scalar.ParametricScalar) ChoicesScalarFunctionImplementation(io.trino.operator.scalar.ChoicesScalarFunctionImplementation) SqlScalarFunction(io.trino.metadata.SqlScalarFunction) FunctionDependencies(io.trino.metadata.FunctionDependencies) Test(org.testng.annotations.Test)

Aggregations

BoundSignature (io.trino.metadata.BoundSignature)27 Signature (io.trino.metadata.Signature)20 TypeSignature (io.trino.spi.type.TypeSignature)18 Test (org.testng.annotations.Test)17 ParametricAggregation (io.trino.operator.aggregation.ParametricAggregation)13 AggregationFunctionMetadata (io.trino.metadata.AggregationFunctionMetadata)12 AggregationImplementation (io.trino.operator.aggregation.AggregationImplementation)12 MethodHandle (java.lang.invoke.MethodHandle)8 FunctionMetadata (io.trino.metadata.FunctionMetadata)7 ImmutableList (com.google.common.collect.ImmutableList)6 FunctionDependencies (io.trino.metadata.FunctionDependencies)6 List (java.util.List)6 SqlScalarFunction (io.trino.metadata.SqlScalarFunction)5 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)4 FunctionNullability (io.trino.metadata.FunctionNullability)4 Type (io.trino.spi.type.Type)4 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)3 FunctionDependencyDeclaration (io.trino.metadata.FunctionDependencyDeclaration)3 ChoicesScalarFunctionImplementation (io.trino.operator.scalar.ChoicesScalarFunctionImplementation)3 TrinoException (io.trino.spi.TrinoException)3