use of io.trino.metadata.Signature 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);
}
use of io.trino.metadata.Signature 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());
}
use of io.trino.metadata.Signature in project trino by trinodb.
the class TestAnnotationEngineForScalars method testComplexParametricScalarParse.
@Test
public void testComplexParametricScalarParse() {
Signature expectedSignature = new Signature("with_exact_scalar", ImmutableList.of(), ImmutableList.of(), BOOLEAN.getTypeSignature(), ImmutableList.of(arrayType(new TypeSignature("varchar", TypeSignatureParameter.typeVariable("x")))), false);
Signature exactSignature = new Signature("with_exact_scalar", ImmutableList.of(), ImmutableList.of(), BOOLEAN.getTypeSignature(), ImmutableList.of(arrayType(createVarcharType(17).getTypeSignature())), false);
List<SqlScalarFunction> functions = ScalarFromAnnotationsParser.parseFunctionDefinition(ComplexParametricScalarFunction.class);
assertEquals(functions.size(), 1);
ParametricScalar scalar = (ParametricScalar) functions.get(0);
assertImplementationCount(scalar.getImplementations(), 1, 0, 1);
assertEquals(getOnlyElement(scalar.getImplementations().getExactImplementations().keySet()), exactSignature);
FunctionMetadata functionMetadata = scalar.getFunctionMetadata();
assertEquals(functionMetadata.getSignature(), expectedSignature);
assertTrue(functionMetadata.isDeterministic());
assertFalse(functionMetadata.isHidden());
assertEquals(functionMetadata.getDescription(), "Parametric scalar with exact and generic implementations");
}
use of io.trino.metadata.Signature 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");
}
use of io.trino.metadata.Signature in project trino by trinodb.
the class TestAnnotationEngineForScalars method testFixedTypeParameterParse.
@Test
public void testFixedTypeParameterParse() {
Signature expectedSignature = new Signature("fixed_type_parameter_scalar_function", ImmutableList.of(), ImmutableList.of(), BIGINT.getTypeSignature(), ImmutableList.of(BIGINT.getTypeSignature()), false);
List<SqlScalarFunction> functions = ScalarFromAnnotationsParser.parseFunctionDefinition(FixedTypeParameterScalarFunction.class);
assertEquals(functions.size(), 1);
ParametricScalar scalar = (ParametricScalar) functions.get(0);
assertImplementationCount(scalar, 1, 0, 0);
FunctionMetadata functionMetadata = scalar.getFunctionMetadata();
assertEquals(functionMetadata.getSignature(), expectedSignature);
assertTrue(functionMetadata.isDeterministic());
assertFalse(functionMetadata.isHidden());
assertEquals(functionMetadata.getDescription(), "Parametric scalar that uses TypeParameter with fixed type");
}
Aggregations