use of io.prestosql.operator.aggregation.AggregationImplementation in project hetu-core by openlookeng.
the class TestAnnotationEngineForAggregates method testNotAnnotatedAggregateStateAggregationParse.
@Test
public void testNotAnnotatedAggregateStateAggregationParse() {
ParametricAggregation aggregation = parseFunctionDefinition(NotAnnotatedAggregateStateAggregationFunction.class);
AggregationImplementation implementation = getOnlyElement(aggregation.getImplementations().getExactImplementations().values());
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, METADATA.getFunctionAndTypeManager());
assertEquals(specialized.getFinalType(), DoubleType.DOUBLE);
assertTrue(specialized.isDecomposable());
assertEquals(specialized.name(), "no_aggregation_state_aggregate");
}
use of io.prestosql.operator.aggregation.AggregationImplementation in project hetu-core by openlookeng.
the class TestAnnotationEngineForAggregates method testSimpleGenericAggregationFunctionParse.
@Test
public void testSimpleGenericAggregationFunctionParse() {
Signature expectedSignature = new Signature(QualifiedObjectName.valueOfDefaultFunction("simple_generic_implementations"), FunctionKind.AGGREGATE, ImmutableList.of(typeVariable("T")), ImmutableList.of(), parseTypeSignature("T"), ImmutableList.of(parseTypeSignature("T")), false);
ParametricAggregation aggregation = parseFunctionDefinition(GenericAggregationFunction.class);
assertEquals(aggregation.getDescription(), "Simple aggregate with two generic implementations");
assertTrue(aggregation.isDeterministic());
assertEquals(aggregation.getSignature(), expectedSignature);
ParametricImplementationsGroup<AggregationImplementation> implementations = aggregation.getImplementations();
assertImplementationCount(implementations, 0, 0, 2);
AggregationImplementation implementationDouble = implementations.getGenericImplementations().stream().filter(impl -> impl.getStateClass() == NullableDoubleState.class).collect(toImmutableList()).get(0);
assertFalse(implementationDouble.getStateSerializerFactory().isPresent());
assertEquals(implementationDouble.getDefinitionClass(), GenericAggregationFunction.class);
assertDependencyCount(implementationDouble, 0, 0, 0);
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);
AggregationImplementation implementationLong = implementations.getGenericImplementations().stream().filter(impl -> impl.getStateClass() == NullableLongState.class).collect(toImmutableList()).get(0);
assertFalse(implementationLong.getStateSerializerFactory().isPresent());
assertEquals(implementationLong.getDefinitionClass(), GenericAggregationFunction.class);
assertDependencyCount(implementationLong, 0, 0, 0);
assertFalse(implementationLong.hasSpecializedTypeParameters());
assertTrue(implementationLong.getInputParameterMetadataTypes().equals(expectedMetadataTypes));
assertEquals(implementationLong.getStateClass(), NullableLongState.class);
InternalAggregationFunction specialized = aggregation.specialize(BoundVariables.builder().setTypeVariable("T", DoubleType.DOUBLE).build(), 1, METADATA.getFunctionAndTypeManager());
assertEquals(specialized.getFinalType(), DoubleType.DOUBLE);
assertTrue(specialized.getParameterTypes().equals(ImmutableList.of(DoubleType.DOUBLE)));
assertTrue(specialized.isDecomposable());
assertEquals(specialized.name(), "simple_generic_implementations");
}
use of io.prestosql.operator.aggregation.AggregationImplementation in project hetu-core by openlookeng.
the class TestAnnotationEngineForAggregates method testInjectLiteralAggregateParse.
@Test
public void testInjectLiteralAggregateParse() {
Signature expectedSignature = new Signature(QualifiedObjectName.valueOfDefaultFunction("inject_literal_aggregate"), FunctionKind.AGGREGATE, parseTypeSignature("varchar(x)", ImmutableSet.of("x")), ImmutableList.of(parseTypeSignature("varchar(x)", ImmutableSet.of("x"))));
ParametricAggregation aggregation = parseFunctionDefinition(InjectLiteralAggregateFunction.class);
assertEquals(aggregation.getDescription(), "Simple aggregate with type literal");
assertTrue(aggregation.isDeterministic());
assertEquals(aggregation.getSignature(), expectedSignature);
ParametricImplementationsGroup<AggregationImplementation> implementations = aggregation.getImplementations();
assertEquals(implementations.getGenericImplementations().size(), 1);
AggregationImplementation implementation = implementations.getGenericImplementations().get(0);
assertTrue(implementation.getStateSerializerFactory().isPresent());
assertEquals(implementation.getDefinitionClass(), InjectLiteralAggregateFunction.class);
assertDependencyCount(implementation, 1, 1, 1);
assertEquals(implementation.getStateSerializerFactoryDependencies().size(), 1);
assertTrue(implementation.getInputDependencies().get(0) instanceof LiteralImplementationDependency);
assertTrue(implementation.getCombineDependencies().get(0) instanceof LiteralImplementationDependency);
assertTrue(implementation.getOutputDependencies().get(0) instanceof LiteralImplementationDependency);
assertTrue(implementation.getStateSerializerFactoryDependencies().get(0) instanceof LiteralImplementationDependency);
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().setLongVariable("x", 17L).build(), 1, METADATA.getFunctionAndTypeManager());
assertEquals(specialized.getFinalType(), VarcharType.createVarcharType(17));
assertTrue(specialized.isDecomposable());
assertEquals(specialized.name(), "inject_literal_aggregate");
}
use of io.prestosql.operator.aggregation.AggregationImplementation in project hetu-core by openlookeng.
the class TestAnnotationEngineForAggregates method testSimpleExactAggregationParse.
@Test
public void testSimpleExactAggregationParse() {
Signature expectedSignature = new Signature(QualifiedObjectName.valueOfDefaultFunction("simple_exact_aggregate"), FunctionKind.AGGREGATE, DoubleType.DOUBLE.getTypeSignature(), ImmutableList.of(DoubleType.DOUBLE.getTypeSignature()));
ParametricAggregation aggregation = parseFunctionDefinition(ExactAggregationFunction.class);
assertEquals(aggregation.getDescription(), "Simple exact aggregate description");
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(), ExactAggregationFunction.class);
assertDependencyCount(implementation, 0, 0, 0);
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, METADATA.getFunctionAndTypeManager());
assertEquals(specialized.getFinalType(), DoubleType.DOUBLE);
assertTrue(specialized.isDecomposable());
assertEquals(specialized.name(), "simple_exact_aggregate");
}
use of io.prestosql.operator.aggregation.AggregationImplementation in project hetu-core by openlookeng.
the class TestAnnotationEngineForAggregates method testSimpleExplicitSpecializedAggregationParse.
// TODO this is not yet supported
@Test(enabled = false)
public void testSimpleExplicitSpecializedAggregationParse() {
Signature expectedSignature = new Signature(QualifiedObjectName.valueOfDefaultFunction("explicit_specialized_aggregate"), FunctionKind.AGGREGATE, ImmutableList.of(typeVariable("T")), ImmutableList.of(), parseTypeSignature("T"), ImmutableList.of(new TypeSignature(ARRAY, TypeSignatureParameter.of(parseTypeSignature("T")))), false);
ParametricAggregation aggregation = parseFunctionDefinition(ExplicitSpecializedAggregationFunction.class);
assertEquals(aggregation.getDescription(), "Simple explicit specialized aggregate");
assertTrue(aggregation.isDeterministic());
assertEquals(aggregation.getSignature(), expectedSignature);
ParametricImplementationsGroup<AggregationImplementation> implementations = aggregation.getImplementations();
assertImplementationCount(implementations, 0, 1, 1);
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);
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, METADATA.getFunctionAndTypeManager());
assertEquals(specialized.getFinalType(), DoubleType.DOUBLE);
assertTrue(specialized.isDecomposable());
assertEquals(specialized.name(), "implicit_specialized_aggregate");
}
Aggregations