use of com.facebook.presto.spi.function.Signature in project presto by prestodb.
the class TestAnnotationEngineForScalars method testConstructorInjectionScalarParse.
@Test
public void testConstructorInjectionScalarParse() {
Signature expectedSignature = new Signature(QualifiedObjectName.valueOf(DEFAULT_NAMESPACE, "parametric_scalar_inject_constructor"), FunctionKind.SCALAR, ImmutableList.of(typeVariable("T")), ImmutableList.of(), BIGINT.getTypeSignature(), ImmutableList.of(parseTypeSignature("array(T)")), false);
List<SqlScalarFunction> functions = ScalarFromAnnotationsParser.parseFunctionDefinition(ConstructorInjectionScalarFunction.class);
assertEquals(functions.size(), 1);
ParametricScalar scalar = (ParametricScalar) functions.get(0);
assertImplementationCount(scalar, 2, 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(), 0);
List<ImplementationDependency> constructorDependencies = parametricScalarImplementationChoices.get(0).getConstructorDependencies();
assertEquals(constructorDependencies.size(), 1);
assertTrue(constructorDependencies.get(0) instanceof TypeImplementationDependency);
assertEquals(scalar.getSignature(), expectedSignature);
assertTrue(scalar.isDeterministic());
assertEquals(scalar.getVisibility(), PUBLIC);
assertEquals(scalar.getDescription(), "Parametric scalar with type injected though constructor");
}
use of com.facebook.presto.spi.function.Signature in project presto by prestodb.
the class TestSignatureBinder method testBindParametricTypeParameterToUnknown.
@Test
public void testBindParametricTypeParameterToUnknown() {
Signature function = functionSignature().returnType(parseTypeSignature("T")).argumentTypes(parseTypeSignature("array(T)")).typeVariableConstraints(ImmutableList.of(typeVariable("T"))).build();
assertThat(function).boundTo("unknown").fails();
assertThat(function).withCoercion().boundTo("unknown").succeeds();
}
use of com.facebook.presto.spi.function.Signature in project presto by prestodb.
the class TestSignatureBinder method testBindUnknownToTypeParameter.
@Test
public void testBindUnknownToTypeParameter() {
Signature function = functionSignature().returnType(parseTypeSignature("T")).argumentTypes(parseTypeSignature("T")).typeVariableConstraints(ImmutableList.of(typeVariable("T"))).build();
assertThat(function).boundTo("unknown").withCoercion().produces(new BoundVariables(ImmutableMap.of("T", type("unknown")), ImmutableMap.of()));
}
use of com.facebook.presto.spi.function.Signature in project presto by prestodb.
the class TestSignatureBinder method testBindDoubleToBigint.
@Test
public void testBindDoubleToBigint() {
Signature function = functionSignature().returnType(parseTypeSignature(StandardTypes.BOOLEAN)).argumentTypes(parseTypeSignature(StandardTypes.DOUBLE), parseTypeSignature(StandardTypes.DOUBLE)).build();
assertThat(function).boundTo("double", "bigint").withCoercion().succeeds();
}
use of com.facebook.presto.spi.function.Signature in project presto by prestodb.
the class TestSignatureBinder method testBindToUnparametrizedVarcharIsImpossible.
@Test
public void testBindToUnparametrizedVarcharIsImpossible() {
Signature function = functionSignature().returnType(parseTypeSignature("boolean")).argumentTypes(parseTypeSignature("varchar")).build();
assertThat(function).boundTo("varchar(3)").withCoercion().succeeds();
assertThat(function).boundTo("unknown").withCoercion().succeeds();
}
Aggregations