use of io.prestosql.operator.annotations.LiteralImplementationDependency 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.annotations.LiteralImplementationDependency in project hetu-core by openlookeng.
the class TestAnnotationEngineForScalars method testSimpleInjectionScalarParse.
@Test
public void testSimpleInjectionScalarParse() {
Signature expectedSignature = new Signature(QualifiedObjectName.valueOfDefaultFunction("parametric_scalar_inject"), FunctionKind.SCALAR, ImmutableList.of(), ImmutableList.of(), BIGINT.getTypeSignature(), ImmutableList.of(parseTypeSignature("varchar(x)", ImmutableSet.of("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);
assertEquals(scalar.getSignature(), expectedSignature);
assertTrue(scalar.isDeterministic());
assertFalse(scalar.isHidden());
assertEquals(scalar.getDescription(), "Parametric scalar with literal injected");
}
Aggregations