use of io.trino.spi.type.TypeSignature in project trino by trinodb.
the class TestSignatureBinder method testBindParametricTypeParameterToUnknown.
@Test
public void testBindParametricTypeParameterToUnknown() {
Signature function = functionSignature().returnType(new TypeSignature("T")).argumentTypes(arrayType(new TypeSignature("T"))).typeVariableConstraints(ImmutableList.of(typeVariable("T"))).build();
assertThat(function).boundTo(UNKNOWN).fails();
assertThat(function).withCoercion().boundTo(UNKNOWN).succeeds();
}
use of io.trino.spi.type.TypeSignature in project trino by trinodb.
the class TestSignatureBinder method testBindMixedLiteralAndTypeVariables.
@Test
public void testBindMixedLiteralAndTypeVariables() {
Signature function = functionSignature().returnType(BOOLEAN.getTypeSignature()).typeVariableConstraints(ImmutableList.of(typeVariable("T"))).argumentTypes(arrayType(new TypeSignature("T")), arrayType(new TypeSignature("decimal", TypeSignatureParameter.typeVariable("p"), TypeSignatureParameter.typeVariable("s")))).build();
assertThat(function).boundTo(new ArrayType(createDecimalType(2, 1)), new ArrayType(createDecimalType(3, 1))).withCoercion().produces(new BoundVariables().setTypeVariable("T", createDecimalType(2, 1)).setLongVariable("p", 3L).setLongVariable("s", 1L));
}
use of io.trino.spi.type.TypeSignature in project trino by trinodb.
the class TestPolymorphicScalarFunction method testTypeParameters.
@Test
public void testTypeParameters() throws Throwable {
Signature signature = Signature.builder().name("foo").typeVariableConstraints(comparableWithVariadicBound("V", "ROW")).returnType(new TypeSignature("V")).argumentTypes(new TypeSignature("V")).build();
SqlScalarFunction function = new PolymorphicScalarFunctionBuilder(TestMethods.class).signature(signature).deterministic(true).choice(choice -> choice.implementation(methodsGroup -> methodsGroup.methods("varcharToVarchar"))).build();
BoundSignature boundSignature = new BoundSignature(signature.getName(), VARCHAR, ImmutableList.of(VARCHAR));
ChoicesScalarFunctionImplementation functionImplementation = (ChoicesScalarFunctionImplementation) function.specialize(boundSignature, new FunctionDependencies(FUNCTION_MANAGER::getScalarFunctionInvoker, ImmutableMap.of(), ImmutableSet.of()));
Slice slice = (Slice) functionImplementation.getChoices().get(0).getMethodHandle().invoke(INPUT_SLICE);
assertEquals(slice, VARCHAR_TO_VARCHAR_RETURN_VALUE);
}
use of io.trino.spi.type.TypeSignature in project trino by trinodb.
the class TestSignatureBinder method testBasic.
@Test
public void testBasic() {
Signature function = functionSignature().typeVariableConstraints(ImmutableList.of(typeVariable("T"))).returnType(new TypeSignature("T")).argumentTypes(new TypeSignature("T")).build();
assertThat(function).boundTo(BIGINT).produces(new BoundVariables().setTypeVariable("T", BIGINT));
assertThat(function).boundTo(VARCHAR).produces(new BoundVariables().setTypeVariable("T", VARCHAR));
assertThat(function).boundTo(VARCHAR, BIGINT).fails();
assertThat(function).boundTo(new ArrayType(BIGINT)).produces(new BoundVariables().setTypeVariable("T", new ArrayType(BIGINT)));
}
use of io.trino.spi.type.TypeSignature in project trino by trinodb.
the class TestSignatureBinder method testVariadic.
@Test
public void testVariadic() {
Signature rowVariadicBoundFunction = functionSignature().returnType(BIGINT.getTypeSignature()).argumentTypes(new TypeSignature("T")).typeVariableConstraints(ImmutableList.of(withVariadicBound("T", "row"))).build();
assertThat(rowVariadicBoundFunction).boundTo(RowType.anonymous(ImmutableList.of(BIGINT, BIGINT))).produces(new BoundVariables().setTypeVariable("T", RowType.anonymous(ImmutableList.of(BIGINT, BIGINT))));
assertThat(rowVariadicBoundFunction).boundTo(new ArrayType(BIGINT)).fails();
assertThat(rowVariadicBoundFunction).boundTo(new ArrayType(BIGINT)).withCoercion().fails();
assertThatThrownBy(() -> withVariadicBound("T", "array")).isInstanceOf(IllegalArgumentException.class).hasMessage("variadicBound must be row but is array");
assertThatThrownBy(() -> withVariadicBound("T", "map")).isInstanceOf(IllegalArgumentException.class).hasMessage("variadicBound must be row but is map");
assertThatThrownBy(() -> withVariadicBound("T", "decimal")).isInstanceOf(IllegalArgumentException.class).hasMessage("variadicBound must be row but is decimal");
}
Aggregations