use of com.facebook.presto.operator.aggregation.InternalAggregationFunction in project presto by prestodb.
the class TestAnnotationEngineForAggregates method testPartiallyFixedTypeParameterInjectionAggregateFunctionParse.
@Test
public void testPartiallyFixedTypeParameterInjectionAggregateFunctionParse() {
Signature expectedSignature = new Signature(QualifiedObjectName.valueOf(DEFAULT_NAMESPACE, "partially_fixed_type_parameter_injection"), FunctionKind.AGGREGATE, ImmutableList.of(typeVariable("T1"), typeVariable("T2")), ImmutableList.of(), DoubleType.DOUBLE.getTypeSignature(), ImmutableList.of(DoubleType.DOUBLE.getTypeSignature()), false);
ParametricAggregation aggregation = parseFunctionDefinition(PartiallyFixedTypeParameterInjectionAggregateFunction.class);
assertEquals(aggregation.getDescription(), "Simple aggregate with fixed parameter type injected");
assertTrue(aggregation.isDeterministic());
assertEquals(aggregation.getSignature(), expectedSignature);
ParametricImplementationsGroup<AggregationImplementation> implementations = aggregation.getImplementations();
assertImplementationCount(implementations, 0, 0, 1);
AggregationImplementation implementationDouble = implementations.getGenericImplementations().stream().filter(impl -> impl.getStateClass() == NullableDoubleState.class).collect(toImmutableList()).get(0);
assertFalse(implementationDouble.getStateSerializerFactory().isPresent());
assertEquals(implementationDouble.getDefinitionClass(), PartiallyFixedTypeParameterInjectionAggregateFunction.class);
assertDependencyCount(implementationDouble, 1, 1, 1);
assertFalse(implementationDouble.hasSpecializedTypeParameters());
List<AggregationMetadata.ParameterMetadata.ParameterType> expectedMetadataTypes = ImmutableList.of(AggregationMetadata.ParameterMetadata.ParameterType.STATE, AggregationMetadata.ParameterMetadata.ParameterType.INPUT_CHANNEL);
assertTrue(implementationDouble.getInputParameterMetadataTypes().equals(expectedMetadataTypes));
assertEquals(implementationDouble.getStateClass(), NullableDoubleState.class);
InternalAggregationFunction specialized = aggregation.specialize(BoundVariables.builder().setTypeVariable("T1", DoubleType.DOUBLE).setTypeVariable("T2", DoubleType.DOUBLE).build(), 1, FUNCTION_AND_TYPE_MANAGER);
assertEquals(specialized.getFinalType(), DoubleType.DOUBLE);
assertTrue(specialized.getParameterTypes().equals(ImmutableList.of(DoubleType.DOUBLE)));
assertTrue(specialized.isDecomposable());
assertEquals(specialized.name(), "partially_fixed_type_parameter_injection");
}
use of com.facebook.presto.operator.aggregation.InternalAggregationFunction in project presto by prestodb.
the class TestAnnotationEngineForAggregates method testCustomStateSerializerAggregationParse.
@Test
public void testCustomStateSerializerAggregationParse() {
ParametricAggregation aggregation = parseFunctionDefinition(CustomStateSerializerAggregationFunction.class);
AggregationImplementation implementation = getOnlyElement(aggregation.getImplementations().getExactImplementations().values());
assertTrue(implementation.getStateSerializerFactory().isPresent());
InternalAggregationFunction specialized = aggregation.specialize(BoundVariables.builder().build(), 1, FUNCTION_AND_TYPE_MANAGER);
AccumulatorStateSerializer<?> createdSerializer = getOnlyElement(((LazyAccumulatorFactoryBinder) specialized.getAccumulatorFactoryBinder()).getGenericAccumulatorFactoryBinder().getStateDescriptors()).getSerializer();
Class<?> serializerFactory = implementation.getStateSerializerFactory().get().type().returnType();
assertTrue(serializerFactory.isInstance(createdSerializer));
}
use of com.facebook.presto.operator.aggregation.InternalAggregationFunction in project presto by prestodb.
the class TestAnnotationEngineForAggregates method testSimpleImplicitSpecializedAggregationParse.
// @Test - this is not yet supported
public void testSimpleImplicitSpecializedAggregationParse() {
Signature expectedSignature = new Signature(QualifiedObjectName.valueOf(DEFAULT_NAMESPACE, "implicit_specialized_aggregate"), FunctionKind.AGGREGATE, ImmutableList.of(typeVariable("T")), ImmutableList.of(), parseTypeSignature("T"), ImmutableList.of(new TypeSignature(ARRAY, TypeSignatureParameter.of(parseTypeSignature("T"))), parseTypeSignature("T")), false);
ParametricAggregation aggregation = parseFunctionDefinition(ImplicitSpecializedAggregationFunction.class);
assertEquals(aggregation.getDescription(), "Simple implicit specialized aggregate");
assertTrue(aggregation.isDeterministic());
assertEquals(aggregation.getSignature(), expectedSignature);
ParametricImplementationsGroup<AggregationImplementation> implementations = aggregation.getImplementations();
assertImplementationCount(implementations, 0, 0, 2);
AggregationImplementation implementation1 = implementations.getSpecializedImplementations().get(0);
assertTrue(implementation1.hasSpecializedTypeParameters());
assertFalse(implementation1.hasSpecializedTypeParameters());
List<AggregationMetadata.ParameterMetadata.ParameterType> expectedMetadataTypes = ImmutableList.of(AggregationMetadata.ParameterMetadata.ParameterType.STATE, AggregationMetadata.ParameterMetadata.ParameterType.INPUT_CHANNEL, AggregationMetadata.ParameterMetadata.ParameterType.INPUT_CHANNEL);
assertTrue(implementation1.getInputParameterMetadataTypes().equals(expectedMetadataTypes));
AggregationImplementation implementation2 = implementations.getSpecializedImplementations().get(1);
assertTrue(implementation2.hasSpecializedTypeParameters());
assertFalse(implementation2.hasSpecializedTypeParameters());
assertTrue(implementation2.getInputParameterMetadataTypes().equals(expectedMetadataTypes));
InternalAggregationFunction specialized = aggregation.specialize(BoundVariables.builder().setTypeVariable("T", DoubleType.DOUBLE).build(), 1, FUNCTION_AND_TYPE_MANAGER);
assertEquals(specialized.getFinalType(), DoubleType.DOUBLE);
assertTrue(specialized.isDecomposable());
assertEquals(specialized.name(), "implicit_specialized_aggregate");
}
use of com.facebook.presto.operator.aggregation.InternalAggregationFunction in project presto by prestodb.
the class TestAnnotationEngineForAggregates method testInjectOperatorAggregateParse.
@Test
public void testInjectOperatorAggregateParse() {
Signature expectedSignature = new Signature(QualifiedObjectName.valueOf(DEFAULT_NAMESPACE, "inject_operator_aggregate"), FunctionKind.AGGREGATE, DoubleType.DOUBLE.getTypeSignature(), ImmutableList.of(DoubleType.DOUBLE.getTypeSignature()));
ParametricAggregation aggregation = parseFunctionDefinition(InjectOperatorAggregateFunction.class);
assertEquals(aggregation.getDescription(), "Simple aggregate with operator injected");
assertTrue(aggregation.isDeterministic());
assertEquals(aggregation.getSignature(), expectedSignature);
ParametricImplementationsGroup<AggregationImplementation> implementations = aggregation.getImplementations();
AggregationImplementation implementation = getOnlyElement(implementations.getExactImplementations().values());
assertTrue(implementation.getStateSerializerFactory().isPresent());
assertEquals(implementation.getDefinitionClass(), InjectOperatorAggregateFunction.class);
assertDependencyCount(implementation, 1, 1, 1);
assertEquals(implementation.getStateSerializerFactoryDependencies().size(), 1);
assertTrue(implementation.getInputDependencies().get(0) instanceof OperatorImplementationDependency);
assertTrue(implementation.getCombineDependencies().get(0) instanceof OperatorImplementationDependency);
assertTrue(implementation.getOutputDependencies().get(0) instanceof OperatorImplementationDependency);
assertTrue(implementation.getStateSerializerFactoryDependencies().get(0) instanceof OperatorImplementationDependency);
assertFalse(implementation.hasSpecializedTypeParameters());
List<AggregationMetadata.ParameterMetadata.ParameterType> expectedMetadataTypes = ImmutableList.of(AggregationMetadata.ParameterMetadata.ParameterType.STATE, AggregationMetadata.ParameterMetadata.ParameterType.INPUT_CHANNEL);
assertTrue(implementation.getInputParameterMetadataTypes().equals(expectedMetadataTypes));
InternalAggregationFunction specialized = aggregation.specialize(BoundVariables.builder().build(), 1, FUNCTION_AND_TYPE_MANAGER);
assertEquals(specialized.getFinalType(), DoubleType.DOUBLE);
assertTrue(specialized.isDecomposable());
assertEquals(specialized.name(), "inject_operator_aggregate");
}
use of com.facebook.presto.operator.aggregation.InternalAggregationFunction in project presto by prestodb.
the class TestAnnotationEngineForAggregates method testSimpleBlockInputAggregationParse.
@Test
public void testSimpleBlockInputAggregationParse() {
Signature expectedSignature = new Signature(QualifiedObjectName.valueOf(DEFAULT_NAMESPACE, "block_input_aggregate"), FunctionKind.AGGREGATE, DoubleType.DOUBLE.getTypeSignature(), ImmutableList.of(DoubleType.DOUBLE.getTypeSignature()));
ParametricAggregation aggregation = parseFunctionDefinition(BlockInputAggregationFunction.class);
assertEquals(aggregation.getDescription(), "Simple aggregate with @BlockPosition usage");
assertTrue(aggregation.isDeterministic());
assertEquals(aggregation.getSignature(), expectedSignature);
ParametricImplementationsGroup<AggregationImplementation> implementations = aggregation.getImplementations();
assertImplementationCount(implementations, 1, 0, 0);
AggregationImplementation implementation = getOnlyElement(implementations.getExactImplementations().values());
assertFalse(implementation.getStateSerializerFactory().isPresent());
assertEquals(implementation.getDefinitionClass(), BlockInputAggregationFunction.class);
assertDependencyCount(implementation, 0, 0, 0);
assertFalse(implementation.hasSpecializedTypeParameters());
List<AggregationMetadata.ParameterMetadata.ParameterType> expectedMetadataTypes = ImmutableList.of(AggregationMetadata.ParameterMetadata.ParameterType.STATE, AggregationMetadata.ParameterMetadata.ParameterType.BLOCK_INPUT_CHANNEL, AggregationMetadata.ParameterMetadata.ParameterType.BLOCK_INDEX);
assertEquals(implementation.getInputParameterMetadataTypes(), expectedMetadataTypes);
InternalAggregationFunction specialized = aggregation.specialize(BoundVariables.builder().build(), 1, FUNCTION_AND_TYPE_MANAGER);
assertEquals(specialized.getFinalType(), DoubleType.DOUBLE);
assertTrue(specialized.isDecomposable());
assertEquals(specialized.name(), "block_input_aggregate");
}
Aggregations