Search in sources :

Example 1 with VARCHAR_TO_BIGINT_RETURN_VALUE

use of com.facebook.presto.metadata.TestPolymorphicScalarFunction.TestMethods.VARCHAR_TO_BIGINT_RETURN_VALUE in project presto by prestodb.

the class TestPolymorphicScalarFunction method testSelectsSecondMethodBasedOnPredicate.

@Test
public void testSelectsSecondMethodBasedOnPredicate() throws Throwable {
    SqlScalarFunction function = SqlScalarFunction.builder(TestMethods.class).signature(SIGNATURE).implementation(b -> b.methods("varcharToBigintReturnExtraParameter").withPredicate(context -> false)).implementation(b -> b.methods("varcharToBigint")).build();
    ScalarFunctionImplementation functionImplementation = function.specialize(BOUND_VARIABLES, 1, TYPE_REGISTRY, REGISTRY);
    assertEquals(functionImplementation.getMethodHandle().invoke(INPUT_SLICE), VARCHAR_TO_BIGINT_RETURN_VALUE);
}
Also used : TypeSignature(com.facebook.presto.spi.type.TypeSignature) ImmutableSet(com.google.common.collect.ImmutableSet) Slice(io.airlift.slice.Slice) ImmutableMap(com.google.common.collect.ImmutableMap) TypeRegistry(com.facebook.presto.type.TypeRegistry) Assert.assertEquals(org.testng.Assert.assertEquals) ScalarFunctionImplementation(com.facebook.presto.operator.scalar.ScalarFunctionImplementation) Test(org.testng.annotations.Test) Signature.comparableWithVariadicBound(com.facebook.presto.metadata.Signature.comparableWithVariadicBound) FeaturesConfig(com.facebook.presto.sql.analyzer.FeaturesConfig) SCALAR(com.facebook.presto.metadata.FunctionKind.SCALAR) VARCHAR(com.facebook.presto.spi.type.StandardTypes.VARCHAR) ImmutableList(com.google.common.collect.ImmutableList) VARCHAR_TO_BIGINT_RETURN_VALUE(com.facebook.presto.metadata.TestPolymorphicScalarFunction.TestMethods.VARCHAR_TO_BIGINT_RETURN_VALUE) Slices(io.airlift.slice.Slices) TypeSignature.parseTypeSignature(com.facebook.presto.spi.type.TypeSignature.parseTypeSignature) StandardTypes(com.facebook.presto.spi.type.StandardTypes) Math.toIntExact(java.lang.Math.toIntExact) VARCHAR_TO_VARCHAR_RETURN_VALUE(com.facebook.presto.metadata.TestPolymorphicScalarFunction.TestMethods.VARCHAR_TO_VARCHAR_RETURN_VALUE) BlockEncodingManager(com.facebook.presto.block.BlockEncodingManager) ADD(com.facebook.presto.spi.function.OperatorType.ADD) ScalarFunctionImplementation(com.facebook.presto.operator.scalar.ScalarFunctionImplementation) Test(org.testng.annotations.Test)

Example 2 with VARCHAR_TO_BIGINT_RETURN_VALUE

use of com.facebook.presto.metadata.TestPolymorphicScalarFunction.TestMethods.VARCHAR_TO_BIGINT_RETURN_VALUE 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);
}
Also used : TypeSignature(com.facebook.presto.spi.type.TypeSignature) ImmutableSet(com.google.common.collect.ImmutableSet) Slice(io.airlift.slice.Slice) ImmutableMap(com.google.common.collect.ImmutableMap) TypeRegistry(com.facebook.presto.type.TypeRegistry) Assert.assertEquals(org.testng.Assert.assertEquals) ScalarFunctionImplementation(com.facebook.presto.operator.scalar.ScalarFunctionImplementation) Test(org.testng.annotations.Test) Signature.comparableWithVariadicBound(com.facebook.presto.metadata.Signature.comparableWithVariadicBound) FeaturesConfig(com.facebook.presto.sql.analyzer.FeaturesConfig) SCALAR(com.facebook.presto.metadata.FunctionKind.SCALAR) VARCHAR(com.facebook.presto.spi.type.StandardTypes.VARCHAR) ImmutableList(com.google.common.collect.ImmutableList) VARCHAR_TO_BIGINT_RETURN_VALUE(com.facebook.presto.metadata.TestPolymorphicScalarFunction.TestMethods.VARCHAR_TO_BIGINT_RETURN_VALUE) Slices(io.airlift.slice.Slices) TypeSignature.parseTypeSignature(com.facebook.presto.spi.type.TypeSignature.parseTypeSignature) StandardTypes(com.facebook.presto.spi.type.StandardTypes) Math.toIntExact(java.lang.Math.toIntExact) VARCHAR_TO_VARCHAR_RETURN_VALUE(com.facebook.presto.metadata.TestPolymorphicScalarFunction.TestMethods.VARCHAR_TO_VARCHAR_RETURN_VALUE) BlockEncodingManager(com.facebook.presto.block.BlockEncodingManager) ADD(com.facebook.presto.spi.function.OperatorType.ADD) ScalarFunctionImplementation(com.facebook.presto.operator.scalar.ScalarFunctionImplementation) Test(org.testng.annotations.Test)

Example 3 with VARCHAR_TO_BIGINT_RETURN_VALUE

use of com.facebook.presto.metadata.TestPolymorphicScalarFunction.TestMethods.VARCHAR_TO_BIGINT_RETURN_VALUE in project presto by prestodb.

the class TestPolymorphicScalarFunction method testSelectsMethodBasedOnReturnType.

@Test
public void testSelectsMethodBasedOnReturnType() throws Throwable {
    SqlScalarFunction function = SqlScalarFunction.builder(TestMethods.class).signature(SIGNATURE).deterministic(true).calledOnNullInput(false).choice(choice -> choice.implementation(methodsGroup -> methodsGroup.methods("varcharToVarcharCreateSliceWithExtraParameterLength")).implementation(methodsGroup -> methodsGroup.methods("varcharToBigintReturnExtraParameter").withExtraParameters(context -> ImmutableList.of(42)))).build();
    BuiltInScalarFunctionImplementation functionImplementation = function.specialize(BOUND_VARIABLES, 1, FUNCTION_AND_TYPE_MANAGER);
    assertEquals(functionImplementation.getMethodHandle().invoke(INPUT_SLICE), VARCHAR_TO_BIGINT_RETURN_VALUE);
}
Also used : StandardTypes(com.facebook.presto.common.type.StandardTypes) Slice(io.airlift.slice.Slice) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) IS_DISTINCT_FROM(com.facebook.presto.common.function.OperatorType.IS_DISTINCT_FROM) FunctionAndTypeManager.createTestFunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager.createTestFunctionAndTypeManager) TypeSignature(com.facebook.presto.common.type.TypeSignature) MAX_SHORT_PRECISION(com.facebook.presto.common.type.Decimals.MAX_SHORT_PRECISION) ADD(com.facebook.presto.common.function.OperatorType.ADD) ImmutableList(com.google.common.collect.ImmutableList) Arrays.asList(java.util.Arrays.asList) Slices(io.airlift.slice.Slices) Math.toIntExact(java.lang.Math.toIntExact) VARCHAR_TO_VARCHAR_RETURN_VALUE(com.facebook.presto.metadata.TestPolymorphicScalarFunction.TestMethods.VARCHAR_TO_VARCHAR_RETURN_VALUE) Assert.assertFalse(org.testng.Assert.assertFalse) BOOLEAN(com.facebook.presto.common.type.StandardTypes.BOOLEAN) BuiltInScalarFunctionImplementation(com.facebook.presto.operator.scalar.BuiltInScalarFunctionImplementation) ImmutableSet(com.google.common.collect.ImmutableSet) Signature.comparableWithVariadicBound(com.facebook.presto.spi.function.Signature.comparableWithVariadicBound) ImmutableMap(com.google.common.collect.ImmutableMap) LongArrayBlock(com.facebook.presto.common.block.LongArrayBlock) BLOCK_AND_POSITION(com.facebook.presto.operator.scalar.ScalarFunctionImplementationChoice.NullConvention.BLOCK_AND_POSITION) USE_NULL_FLAG(com.facebook.presto.operator.scalar.ScalarFunctionImplementationChoice.NullConvention.USE_NULL_FLAG) SCALAR(com.facebook.presto.spi.function.FunctionKind.SCALAR) VARCHAR(com.facebook.presto.common.type.StandardTypes.VARCHAR) ArgumentProperty.valueTypeArgumentProperty(com.facebook.presto.operator.scalar.ScalarFunctionImplementationChoice.ArgumentProperty.valueTypeArgumentProperty) TypeSignature.parseTypeSignature(com.facebook.presto.common.type.TypeSignature.parseTypeSignature) VARCHAR_TO_BIGINT_RETURN_VALUE(com.facebook.presto.metadata.TestPolymorphicScalarFunction.TestMethods.VARCHAR_TO_BIGINT_RETURN_VALUE) Signature(com.facebook.presto.spi.function.Signature) Optional(java.util.Optional) Assert.assertTrue(org.testng.Assert.assertTrue) Block(com.facebook.presto.common.block.Block) Collections(java.util.Collections) BuiltInScalarFunctionImplementation(com.facebook.presto.operator.scalar.BuiltInScalarFunctionImplementation) Test(org.testng.annotations.Test)

Aggregations

VARCHAR_TO_BIGINT_RETURN_VALUE (com.facebook.presto.metadata.TestPolymorphicScalarFunction.TestMethods.VARCHAR_TO_BIGINT_RETURN_VALUE)3 VARCHAR_TO_VARCHAR_RETURN_VALUE (com.facebook.presto.metadata.TestPolymorphicScalarFunction.TestMethods.VARCHAR_TO_VARCHAR_RETURN_VALUE)3 ImmutableList (com.google.common.collect.ImmutableList)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 ImmutableSet (com.google.common.collect.ImmutableSet)3 Slice (io.airlift.slice.Slice)3 Slices (io.airlift.slice.Slices)3 Math.toIntExact (java.lang.Math.toIntExact)3 Assert.assertEquals (org.testng.Assert.assertEquals)3 Test (org.testng.annotations.Test)3 BlockEncodingManager (com.facebook.presto.block.BlockEncodingManager)2 SCALAR (com.facebook.presto.metadata.FunctionKind.SCALAR)2 Signature.comparableWithVariadicBound (com.facebook.presto.metadata.Signature.comparableWithVariadicBound)2 ScalarFunctionImplementation (com.facebook.presto.operator.scalar.ScalarFunctionImplementation)2 ADD (com.facebook.presto.spi.function.OperatorType.ADD)2 StandardTypes (com.facebook.presto.spi.type.StandardTypes)2 VARCHAR (com.facebook.presto.spi.type.StandardTypes.VARCHAR)2 TypeSignature (com.facebook.presto.spi.type.TypeSignature)2 TypeSignature.parseTypeSignature (com.facebook.presto.spi.type.TypeSignature.parseTypeSignature)2 FeaturesConfig (com.facebook.presto.sql.analyzer.FeaturesConfig)2