use of io.trino.metadata.Signature in project trino by trinodb.
the class TestAnnotationEngineForAggregates method testPartiallyFixedTypeParameterInjectionAggregateFunctionParse.
@Test
public void testPartiallyFixedTypeParameterInjectionAggregateFunctionParse() {
Signature expectedSignature = new Signature("partially_fixed_type_parameter_injection", ImmutableList.of(typeVariable("T1"), typeVariable("T2")), ImmutableList.of(), DoubleType.DOUBLE.getTypeSignature(), ImmutableList.of(new TypeSignature("T1"), new TypeSignature("T2")), false);
ParametricAggregation aggregation = getOnlyElement(parseFunctionDefinitions(PartiallyFixedTypeParameterInjectionAggregateFunction.class));
assertEquals(aggregation.getFunctionMetadata().getDescription(), "Simple aggregate with fixed parameter type injected");
assertTrue(aggregation.getFunctionMetadata().isDeterministic());
assertEquals(aggregation.getFunctionMetadata().getSignature(), expectedSignature);
assertEquals(aggregation.getStateClass(), NullableDoubleState.class);
ParametricImplementationsGroup<AggregationImplementation> implementations = aggregation.getImplementations();
assertImplementationCount(implementations, 0, 0, 1);
AggregationImplementation implementationDouble = getOnlyElement(implementations.getGenericImplementations());
assertEquals(implementationDouble.getDefinitionClass(), PartiallyFixedTypeParameterInjectionAggregateFunction.class);
assertDependencyCount(implementationDouble, 1, 1, 1);
assertFalse(implementationDouble.hasSpecializedTypeParameters());
assertEquals(implementationDouble.getInputParameterKinds(), ImmutableList.of(STATE, INPUT_CHANNEL, INPUT_CHANNEL));
BoundSignature boundSignature = new BoundSignature(aggregation.getFunctionMetadata().getSignature().getName(), DoubleType.DOUBLE, ImmutableList.of(DoubleType.DOUBLE, DoubleType.DOUBLE));
specializeAggregationFunction(boundSignature, aggregation);
}
use of io.trino.metadata.Signature in project trino by trinodb.
the class TestAnnotationEngineForAggregates method testSimpleBlockInputAggregationParse.
@Test
public void testSimpleBlockInputAggregationParse() {
Signature expectedSignature = new Signature("block_input_aggregate", DoubleType.DOUBLE.getTypeSignature(), ImmutableList.of(DoubleType.DOUBLE.getTypeSignature()));
ParametricAggregation aggregation = getOnlyElement(parseFunctionDefinitions(BlockInputAggregationFunction.class));
assertEquals(aggregation.getFunctionMetadata().getDescription(), "Simple aggregate with @BlockPosition usage");
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(), BlockInputAggregationFunction.class);
assertDependencyCount(implementation, 0, 0, 0);
assertFalse(implementation.hasSpecializedTypeParameters());
assertEquals(implementation.getInputParameterKinds(), ImmutableList.of(STATE, BLOCK_INPUT_CHANNEL, BLOCK_INDEX));
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);
}
use of io.trino.metadata.Signature in project trino by trinodb.
the class TestAnnotationEngineForAggregates method testStateOnDifferentThanFirstPositionAggregationParse.
@Test
public void testStateOnDifferentThanFirstPositionAggregationParse() {
Signature expectedSignature = new Signature("simple_exact_aggregate_aggregation_state_moved", DoubleType.DOUBLE.getTypeSignature(), ImmutableList.of(DoubleType.DOUBLE.getTypeSignature()));
ParametricAggregation aggregation = getOnlyElement(parseFunctionDefinitions(StateOnDifferentThanFirstPositionAggregationFunction.class));
assertEquals(aggregation.getFunctionMetadata().getSignature(), expectedSignature);
AggregationImplementation implementation = getOnlyElement(aggregation.getImplementations().getExactImplementations().values());
assertEquals(implementation.getDefinitionClass(), StateOnDifferentThanFirstPositionAggregationFunction.class);
assertEquals(implementation.getInputParameterKinds(), ImmutableList.of(INPUT_CHANNEL, STATE));
}
use of io.trino.metadata.Signature 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);
}
use of io.trino.metadata.Signature in project trino by trinodb.
the class TestAnnotationEngineForScalars method testStaticMethodScalarParse.
@Test
public void testStaticMethodScalarParse() {
Signature expectedSignature = new Signature("static_method_scalar", DOUBLE.getTypeSignature(), ImmutableList.of(DOUBLE.getTypeSignature()));
List<SqlScalarFunction> functions = ScalarFromAnnotationsParser.parseFunctionDefinitions(StaticMethodScalarFunction.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 method");
}
Aggregations