use of com.facebook.presto.spi.function.Signature in project presto by prestodb.
the class TestAnnotationEngineForAggregates method testSimpleExactAggregationParse.
@Test
public void testSimpleExactAggregationParse() {
Signature expectedSignature = new Signature(QualifiedObjectName.valueOf(DEFAULT_NAMESPACE, "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, FUNCTION_AND_TYPE_MANAGER);
assertEquals(specialized.getFinalType(), DoubleType.DOUBLE);
assertTrue(specialized.isDecomposable());
assertEquals(specialized.name(), "simple_exact_aggregate");
}
use of com.facebook.presto.spi.function.Signature in project presto by prestodb.
the class TestAnnotationEngineForAggregates method testInjectTypeAggregateParse.
@Test
public void testInjectTypeAggregateParse() {
Signature expectedSignature = new Signature(QualifiedObjectName.valueOf(DEFAULT_NAMESPACE, "inject_type_aggregate"), FunctionKind.AGGREGATE, ImmutableList.of(typeVariable("T")), ImmutableList.of(), parseTypeSignature("T"), ImmutableList.of(parseTypeSignature("T")), false);
ParametricAggregation aggregation = parseFunctionDefinition(InjectTypeAggregateFunction.class);
assertEquals(aggregation.getDescription(), "Simple aggregate with type injected");
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(), InjectTypeAggregateFunction.class);
assertDependencyCount(implementation, 1, 1, 1);
assertEquals(implementation.getStateSerializerFactoryDependencies().size(), 1);
assertTrue(implementation.getInputDependencies().get(0) instanceof TypeImplementationDependency);
assertTrue(implementation.getCombineDependencies().get(0) instanceof TypeImplementationDependency);
assertTrue(implementation.getOutputDependencies().get(0) instanceof TypeImplementationDependency);
assertTrue(implementation.getStateSerializerFactoryDependencies().get(0) instanceof TypeImplementationDependency);
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().setTypeVariable("T", DoubleType.DOUBLE).build(), 1, FUNCTION_AND_TYPE_MANAGER);
assertEquals(specialized.getFinalType(), DoubleType.DOUBLE);
assertTrue(specialized.isDecomposable());
assertEquals(specialized.name(), "inject_type_aggregate");
}
use of com.facebook.presto.spi.function.Signature in project presto by prestodb.
the class TestAnnotationEngineForScalars method testSimpleInjectionScalarParse.
@Test
public void testSimpleInjectionScalarParse() {
Signature expectedSignature = new Signature(QualifiedObjectName.valueOf(DEFAULT_NAMESPACE, "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());
assertEquals(scalar.getVisibility(), PUBLIC);
assertEquals(scalar.getDescription(), "Parametric scalar with literal injected");
}
use of com.facebook.presto.spi.function.Signature in project presto by prestodb.
the class TestAnnotationEngineForScalars method testWithNullablePrimitiveArgScalarParse.
@Test
public void testWithNullablePrimitiveArgScalarParse() {
Signature expectedSignature = new Signature(QualifiedObjectName.valueOf(DEFAULT_NAMESPACE, "scalar_with_nullable"), FunctionKind.SCALAR, DOUBLE.getTypeSignature(), ImmutableList.of(DOUBLE.getTypeSignature(), DOUBLE.getTypeSignature()));
List<SqlScalarFunction> functions = ScalarFromAnnotationsParser.parseFunctionDefinition(WithNullablePrimitiveArgScalarFunction.class);
assertEquals(functions.size(), 1);
ParametricScalar scalar = (ParametricScalar) functions.get(0);
assertEquals(scalar.getSignature(), expectedSignature);
assertTrue(scalar.isDeterministic());
assertEquals(scalar.getVisibility(), PUBLIC);
assertEquals(scalar.getDescription(), "Simple scalar with nullable primitive");
BuiltInScalarFunctionImplementation specialized = scalar.specialize(BoundVariables.builder().build(), 2, FUNCTION_AND_TYPE_MANAGER);
assertFalse(specialized.getInstanceFactory().isPresent());
assertEquals(specialized.getArgumentProperty(0), valueTypeArgumentProperty(RETURN_NULL_ON_NULL));
assertEquals(specialized.getArgumentProperty(1), valueTypeArgumentProperty(USE_NULL_FLAG));
}
use of com.facebook.presto.spi.function.Signature in project presto by prestodb.
the class TestAnnotationEngineForScalars method testComplexParametricScalarParse.
@Test
public void testComplexParametricScalarParse() {
Signature expectedSignature = new Signature(QualifiedObjectName.valueOf(DEFAULT_NAMESPACE, "with_exact_scalar"), FunctionKind.SCALAR, ImmutableList.of(), ImmutableList.of(), BOOLEAN.getTypeSignature(), ImmutableList.of(parseTypeSignature("array(varchar(x))", ImmutableSet.of("x"))), false);
Signature exactSignature = new Signature(QualifiedObjectName.valueOf(DEFAULT_NAMESPACE, "with_exact_scalar"), FunctionKind.SCALAR, ImmutableList.of(), ImmutableList.of(), BOOLEAN.getTypeSignature(), ImmutableList.of(parseTypeSignature("array(varchar(17))")), false);
List<SqlScalarFunction> functions = ScalarFromAnnotationsParser.parseFunctionDefinition(ComplexParametricScalarFunction.class);
assertEquals(functions.size(), 1);
ParametricScalar scalar = (ParametricScalar) functions.get(0);
assertImplementationCount(scalar.getImplementations(), 1, 0, 1);
assertEquals(getOnlyElement(scalar.getImplementations().getExactImplementations().keySet()), exactSignature);
assertEquals(scalar.getSignature(), expectedSignature);
assertTrue(scalar.isDeterministic());
assertEquals(scalar.getVisibility(), PUBLIC);
assertEquals(scalar.getDescription(), "Parametric scalar with exact and generic implementations");
}
Aggregations