use of io.trino.metadata.TestPolymorphicScalarFunction.TestMethods.VARCHAR_TO_VARCHAR_RETURN_VALUE in project trino by trinodb.
the class TestPolymorphicScalarFunction method testSameLiteralInArgumentsAndReturnValue.
@Test
public void testSameLiteralInArgumentsAndReturnValue() throws Throwable {
Signature signature = Signature.builder().name("foo").returnType(new TypeSignature("varchar", typeVariable("x"))).argumentTypes(new TypeSignature("varchar", typeVariable("x"))).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(), createVarcharType(INPUT_VARCHAR_LENGTH), ImmutableList.of(createVarcharType(INPUT_VARCHAR_LENGTH)));
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.metadata.TestPolymorphicScalarFunction.TestMethods.VARCHAR_TO_VARCHAR_RETURN_VALUE 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);
}
Aggregations