use of com.facebook.presto.operator.scalar.ScalarFunctionImplementation in project presto by prestodb.
the class TestPolymorphicScalarFunction method testSelectsFirstMethodBasedOnPredicate.
@Test
public void testSelectsFirstMethodBasedOnPredicate() throws Throwable {
SqlScalarFunction function = SqlScalarFunction.builder(TestMethods.class).signature(SIGNATURE).implementation(b -> b.methods("varcharToBigint").withPredicate(context -> true)).implementation(b -> b.methods("varcharToBigintReturnExtraParameter")).build();
ScalarFunctionImplementation functionImplementation = function.specialize(BOUND_VARIABLES, 1, TYPE_REGISTRY, REGISTRY);
assertEquals(functionImplementation.getMethodHandle().invoke(INPUT_SLICE), VARCHAR_TO_BIGINT_RETURN_VALUE);
}
use of com.facebook.presto.operator.scalar.ScalarFunctionImplementation in project presto by prestodb.
the class TestPolymorphicScalarFunction method testSameLiteralInArgumentsAndReturnValue.
@Test
public void testSameLiteralInArgumentsAndReturnValue() throws Throwable {
Signature signature = Signature.builder().name("foo").kind(SCALAR).returnType(parseTypeSignature("varchar(x)", ImmutableSet.of("x"))).argumentTypes(parseTypeSignature("varchar(x)", ImmutableSet.of("x"))).build();
SqlScalarFunction function = SqlScalarFunction.builder(TestMethods.class).signature(signature).implementation(b -> b.methods("varcharToVarchar")).build();
ScalarFunctionImplementation functionImplementation = function.specialize(BOUND_VARIABLES, 1, TYPE_REGISTRY, REGISTRY);
Slice slice = (Slice) functionImplementation.getMethodHandle().invoke(INPUT_SLICE);
assertEquals(slice, VARCHAR_TO_VARCHAR_RETURN_VALUE);
}
use of com.facebook.presto.operator.scalar.ScalarFunctionImplementation in project presto by prestodb.
the class TestPolymorphicScalarFunction method testSelectsMethodBasedOnReturnType.
@Test
public void testSelectsMethodBasedOnReturnType() throws Throwable {
SqlScalarFunction function = SqlScalarFunction.builder(TestMethods.class).signature(SIGNATURE).implementation(b -> b.methods("varcharToVarcharCreateSliceWithExtraParameterLength")).implementation(b -> b.methods("varcharToBigintReturnExtraParameter").withExtraParameters(context -> ImmutableList.of(42))).build();
ScalarFunctionImplementation functionImplementation = function.specialize(BOUND_VARIABLES, 1, TYPE_REGISTRY, REGISTRY);
assertEquals(functionImplementation.getMethodHandle().invoke(INPUT_SLICE), VARCHAR_TO_BIGINT_RETURN_VALUE);
}
Aggregations