Search in sources :

Example 6 with BoundSignature

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

the class TestAnnotationEngineForAggregates method testSimpleImplicitSpecializedAggregationParse.

// TODO this is not yet supported
@Test(enabled = false)
public void testSimpleImplicitSpecializedAggregationParse() {
    Signature expectedSignature = new Signature("implicit_specialized_aggregate", ImmutableList.of(typeVariable("T")), ImmutableList.of(), new TypeSignature("T"), ImmutableList.of(new TypeSignature(ARRAY, TypeSignatureParameter.typeParameter(new TypeSignature("T"))), new TypeSignature("T")), false);
    ParametricAggregation aggregation = getOnlyElement(parseFunctionDefinitions(ImplicitSpecializedAggregationFunction.class));
    assertEquals(aggregation.getFunctionMetadata().getDescription(), "Simple implicit specialized aggregate");
    assertTrue(aggregation.getFunctionMetadata().isDeterministic());
    assertEquals(aggregation.getFunctionMetadata().getSignature(), expectedSignature);
    ParametricImplementationsGroup<AggregationImplementation> implementations = aggregation.getImplementations();
    assertImplementationCount(implementations, 0, 0, 2);
    AggregationImplementation implementation1 = implementations.getSpecializedImplementations().get(0);
    assertTrue(implementation1.hasSpecializedTypeParameters());
    assertFalse(implementation1.hasSpecializedTypeParameters());
    assertEquals(implementation1.getInputParameterKinds(), ImmutableList.of(STATE, INPUT_CHANNEL, INPUT_CHANNEL));
    AggregationImplementation implementation2 = implementations.getSpecializedImplementations().get(1);
    assertTrue(implementation2.hasSpecializedTypeParameters());
    assertFalse(implementation2.hasSpecializedTypeParameters());
    assertEquals(implementation2.getInputParameterKinds(), ImmutableList.of(STATE, INPUT_CHANNEL, INPUT_CHANNEL));
    BoundSignature boundSignature = new BoundSignature(aggregation.getFunctionMetadata().getSignature().getName(), DoubleType.DOUBLE, ImmutableList.of(new ArrayType(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) ArrayType(io.trino.spi.type.ArrayType) 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) AggregationFunctionMetadata(io.trino.metadata.AggregationFunctionMetadata) Test(org.testng.annotations.Test)

Example 7 with BoundSignature

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

the class TestAnnotationEngineForAggregates method testNotAnnotatedAggregateStateAggregationParse.

@Test
public void testNotAnnotatedAggregateStateAggregationParse() {
    ParametricAggregation aggregation = getOnlyElement(parseFunctionDefinitions(NotAnnotatedAggregateStateAggregationFunction.class));
    AggregationImplementation implementation = getOnlyElement(aggregation.getImplementations().getExactImplementations().values());
    assertEquals(implementation.getInputParameterKinds(), ImmutableList.of(STATE, INPUT_CHANNEL));
    BoundSignature boundSignature = new BoundSignature(aggregation.getFunctionMetadata().getSignature().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) BoundSignature(io.trino.metadata.BoundSignature) ParametricAggregation(io.trino.operator.aggregation.ParametricAggregation) AggregationFunctionMetadata(io.trino.metadata.AggregationFunctionMetadata) Test(org.testng.annotations.Test)

Example 8 with BoundSignature

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

the class TestAnnotationEngineForAggregates method testMultiOutputAggregationParse.

@Test
public void testMultiOutputAggregationParse() {
    Signature expectedSignature1 = new Signature("multi_output_aggregate_1", DoubleType.DOUBLE.getTypeSignature(), ImmutableList.of(DoubleType.DOUBLE.getTypeSignature()));
    Signature expectedSignature2 = new Signature("multi_output_aggregate_2", DoubleType.DOUBLE.getTypeSignature(), ImmutableList.of(DoubleType.DOUBLE.getTypeSignature()));
    List<ParametricAggregation> aggregations = parseFunctionDefinitions(MultiOutputAggregationFunction.class);
    assertEquals(aggregations.size(), 2);
    ParametricAggregation aggregation1 = aggregations.stream().filter(aggregate -> aggregate.getFunctionMetadata().getSignature().getName().equals("multi_output_aggregate_1")).collect(toImmutableList()).get(0);
    assertEquals(aggregation1.getFunctionMetadata().getSignature(), expectedSignature1);
    assertEquals(aggregation1.getFunctionMetadata().getDescription(), "Simple multi output function aggregate specialized description");
    ParametricAggregation aggregation2 = aggregations.stream().filter(aggregate -> aggregate.getFunctionMetadata().getSignature().getName().equals("multi_output_aggregate_2")).collect(toImmutableList()).get(0);
    assertEquals(aggregation2.getFunctionMetadata().getSignature(), expectedSignature2);
    assertEquals(aggregation2.getFunctionMetadata().getDescription(), "Simple multi output function aggregate generic description");
    ParametricImplementationsGroup<AggregationImplementation> implementations1 = aggregation1.getImplementations();
    assertImplementationCount(implementations1, 1, 0, 0);
    ParametricImplementationsGroup<AggregationImplementation> implementations2 = aggregation2.getImplementations();
    assertImplementationCount(implementations2, 1, 0, 0);
    AggregationImplementation implementation = getOnlyElement(implementations1.getExactImplementations().values());
    assertEquals(implementation.getDefinitionClass(), MultiOutputAggregationFunction.class);
    assertDependencyCount(implementation, 0, 0, 0);
    assertFalse(implementation.hasSpecializedTypeParameters());
    assertEquals(implementation.getInputParameterKinds(), ImmutableList.of(STATE, INPUT_CHANNEL));
    BoundSignature boundSignature = new BoundSignature(aggregation1.getFunctionMetadata().getSignature().getName(), DoubleType.DOUBLE, ImmutableList.of(DoubleType.DOUBLE));
    AggregationFunctionMetadata aggregationMetadata = aggregation1.getAggregationMetadata();
    assertFalse(aggregationMetadata.isOrderSensitive());
    assertFalse(aggregationMetadata.getIntermediateTypes().isEmpty());
    aggregation1.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 9 with BoundSignature

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

the class TestAnnotationEngineForScalars method testWithNullableComplexArgScalarParse.

@Test
public void testWithNullableComplexArgScalarParse() {
    Signature expectedSignature = new Signature("scalar_with_nullable_complex", DOUBLE.getTypeSignature(), ImmutableList.of(DOUBLE.getTypeSignature(), DOUBLE.getTypeSignature()));
    List<SqlScalarFunction> functions = ScalarFromAnnotationsParser.parseFunctionDefinition(WithNullableComplexArgScalarFunction.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 nullable complex type");
    assertFalse(functionMetadata.getFunctionNullability().isArgumentNullable(0));
    assertTrue(functionMetadata.getFunctionNullability().isArgumentNullable(1));
    BoundSignature boundSignature = new BoundSignature(expectedSignature.getName(), DOUBLE, ImmutableList.of(DOUBLE, 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)

Example 10 with BoundSignature

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

the class TestAnnotationEngineForScalars method testWithNullablePrimitiveArgScalarParse.

@Test
public void testWithNullablePrimitiveArgScalarParse() {
    Signature expectedSignature = new Signature("scalar_with_nullable", DOUBLE.getTypeSignature(), ImmutableList.of(DOUBLE.getTypeSignature(), DOUBLE.getTypeSignature()));
    List<SqlScalarFunction> functions = ScalarFromAnnotationsParser.parseFunctionDefinition(WithNullablePrimitiveArgScalarFunction.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 nullable primitive");
    assertFalse(functionMetadata.getFunctionNullability().isArgumentNullable(0));
    assertTrue(functionMetadata.getFunctionNullability().isArgumentNullable(1));
    BoundSignature boundSignature = new BoundSignature(expectedSignature.getName(), DOUBLE, ImmutableList.of(DOUBLE, 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