use of io.trino.operator.aggregation.AggregationImplementation in project trino by trinodb.
the class TestAnnotationEngineForAggregates method testSimpleExplicitSpecializedAggregationParse.
// TODO this is not yet supported
@Test(enabled = false)
public void testSimpleExplicitSpecializedAggregationParse() {
Signature expectedSignature = new Signature("explicit_specialized_aggregate", ImmutableList.of(typeVariable("T")), ImmutableList.of(), new TypeSignature("T"), ImmutableList.of(new TypeSignature(ARRAY, TypeSignatureParameter.typeParameter(new TypeSignature("T")))), false);
ParametricAggregation aggregation = getOnlyElement(parseFunctionDefinitions(ExplicitSpecializedAggregationFunction.class));
assertEquals(aggregation.getFunctionMetadata().getDescription(), "Simple explicit specialized aggregate");
assertTrue(aggregation.getFunctionMetadata().isDeterministic());
assertEquals(aggregation.getFunctionMetadata().getSignature(), expectedSignature);
ParametricImplementationsGroup<AggregationImplementation> implementations = aggregation.getImplementations();
assertImplementationCount(implementations, 0, 1, 1);
AggregationImplementation implementation1 = implementations.getSpecializedImplementations().get(0);
assertTrue(implementation1.hasSpecializedTypeParameters());
assertFalse(implementation1.hasSpecializedTypeParameters());
assertEquals(implementation1.getInputParameterKinds(), ImmutableList.of(STATE, INPUT_CHANNEL));
AggregationImplementation implementation2 = implementations.getSpecializedImplementations().get(1);
assertTrue(implementation2.hasSpecializedTypeParameters());
assertFalse(implementation2.hasSpecializedTypeParameters());
assertEquals(implementation2.getInputParameterKinds(), ImmutableList.of(STATE, 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);
}
use of io.trino.operator.aggregation.AggregationImplementation 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);
}
use of io.trino.operator.aggregation.AggregationImplementation 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);
}
use of io.trino.operator.aggregation.AggregationImplementation 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.operator.aggregation.AggregationImplementation in project trino by trinodb.
the class TestAnnotationEngineForAggregates method testInjectTypeAggregateParse.
@Test
public void testInjectTypeAggregateParse() {
Signature expectedSignature = new Signature("inject_type_aggregate", ImmutableList.of(typeVariable("T")), ImmutableList.of(), new TypeSignature("T"), ImmutableList.of(new TypeSignature("T")), false);
ParametricAggregation aggregation = getOnlyElement(parseFunctionDefinitions(InjectTypeAggregateFunction.class));
assertEquals(aggregation.getFunctionMetadata().getDescription(), "Simple aggregate with type injected");
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(), InjectTypeAggregateFunction.class);
assertDependencyCount(implementation, 1, 1, 1);
assertTrue(implementation.getInputDependencies().get(0) instanceof TypeImplementationDependency);
assertTrue(implementation.getCombineDependencies().get(0) instanceof TypeImplementationDependency);
assertTrue(implementation.getOutputDependencies().get(0) instanceof TypeImplementationDependency);
assertFalse(implementation.hasSpecializedTypeParameters());
assertEquals(implementation.getInputParameterKinds(), ImmutableList.of(STATE, INPUT_CHANNEL));
BoundSignature boundSignature = new BoundSignature(aggregation.getFunctionMetadata().getSignature().getName(), DoubleType.DOUBLE, ImmutableList.of(DoubleType.DOUBLE));
specializeAggregationFunction(boundSignature, aggregation);
}
Aggregations