Search in sources :

Example 1 with VARCHAR_TO_BIGINT_RETURN_VALUE

use of io.prestosql.metadata.TestPolymorphicScalarFunction.TestMethods.VARCHAR_TO_BIGINT_RETURN_VALUE in project hetu-core by openlookeng.

the class TestPolymorphicScalarFunction method testSelectsMethodBasedOnReturnType.

@Test
public void testSelectsMethodBasedOnReturnType() throws Throwable {
    SqlScalarFunction function = SqlScalarFunction.builder(TestMethods.class).signature(SIGNATURE).deterministic(true).calledOnNullInput(FOO_IS_CALL_ON_NUL_INPUT).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, METADATA.getFunctionAndTypeManager());
    assertEquals(functionImplementation.getMethodHandle().invoke(INPUT_SLICE), VARCHAR_TO_BIGINT_RETURN_VALUE);
}
Also used : ADD(io.prestosql.spi.function.OperatorType.ADD) BuiltInScalarFunctionImplementation(io.prestosql.spi.function.BuiltInScalarFunctionImplementation) BLOCK_AND_POSITION(io.prestosql.spi.function.BuiltInScalarFunctionImplementation.NullConvention.BLOCK_AND_POSITION) Slice(io.airlift.slice.Slice) StandardTypes(io.prestosql.spi.type.StandardTypes) SCALAR(io.prestosql.spi.function.FunctionKind.SCALAR) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) VARCHAR_TO_BIGINT_RETURN_VALUE(io.prestosql.metadata.TestPolymorphicScalarFunction.TestMethods.VARCHAR_TO_BIGINT_RETURN_VALUE) LongArrayBlock(io.prestosql.spi.block.LongArrayBlock) TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) ImmutableList(com.google.common.collect.ImmutableList) Arrays.asList(java.util.Arrays.asList) Slices(io.airlift.slice.Slices) USE_NULL_FLAG(io.prestosql.spi.function.BuiltInScalarFunctionImplementation.NullConvention.USE_NULL_FLAG) Math.toIntExact(java.lang.Math.toIntExact) Signature(io.prestosql.spi.function.Signature) Signature.comparableWithVariadicBound(io.prestosql.spi.function.Signature.comparableWithVariadicBound) Assert.assertFalse(org.testng.Assert.assertFalse) Block(io.prestosql.spi.block.Block) VARCHAR(io.prestosql.spi.type.StandardTypes.VARCHAR) ImmutableSet(com.google.common.collect.ImmutableSet) BOOLEAN(io.prestosql.spi.type.StandardTypes.BOOLEAN) ImmutableMap(com.google.common.collect.ImmutableMap) MetadataManager.createTestMetadataManager(io.prestosql.metadata.MetadataManager.createTestMetadataManager) IS_DISTINCT_FROM(io.prestosql.spi.function.OperatorType.IS_DISTINCT_FROM) MAX_SHORT_PRECISION(io.prestosql.spi.type.Decimals.MAX_SHORT_PRECISION) ArgumentProperty.valueTypeArgumentProperty(io.prestosql.spi.function.BuiltInScalarFunctionImplementation.ArgumentProperty.valueTypeArgumentProperty) Optional(java.util.Optional) Assert.assertTrue(org.testng.Assert.assertTrue) VARCHAR_TO_VARCHAR_RETURN_VALUE(io.prestosql.metadata.TestPolymorphicScalarFunction.TestMethods.VARCHAR_TO_VARCHAR_RETURN_VALUE) TypeSignature(io.prestosql.spi.type.TypeSignature) Collections(java.util.Collections) BuiltInScalarFunctionImplementation(io.prestosql.spi.function.BuiltInScalarFunctionImplementation) Test(org.testng.annotations.Test)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Slice (io.airlift.slice.Slice)1 Slices (io.airlift.slice.Slices)1 MetadataManager.createTestMetadataManager (io.prestosql.metadata.MetadataManager.createTestMetadataManager)1 VARCHAR_TO_BIGINT_RETURN_VALUE (io.prestosql.metadata.TestPolymorphicScalarFunction.TestMethods.VARCHAR_TO_BIGINT_RETURN_VALUE)1 VARCHAR_TO_VARCHAR_RETURN_VALUE (io.prestosql.metadata.TestPolymorphicScalarFunction.TestMethods.VARCHAR_TO_VARCHAR_RETURN_VALUE)1 Block (io.prestosql.spi.block.Block)1 LongArrayBlock (io.prestosql.spi.block.LongArrayBlock)1 BuiltInScalarFunctionImplementation (io.prestosql.spi.function.BuiltInScalarFunctionImplementation)1 ArgumentProperty.valueTypeArgumentProperty (io.prestosql.spi.function.BuiltInScalarFunctionImplementation.ArgumentProperty.valueTypeArgumentProperty)1 BLOCK_AND_POSITION (io.prestosql.spi.function.BuiltInScalarFunctionImplementation.NullConvention.BLOCK_AND_POSITION)1 USE_NULL_FLAG (io.prestosql.spi.function.BuiltInScalarFunctionImplementation.NullConvention.USE_NULL_FLAG)1 SCALAR (io.prestosql.spi.function.FunctionKind.SCALAR)1 ADD (io.prestosql.spi.function.OperatorType.ADD)1 IS_DISTINCT_FROM (io.prestosql.spi.function.OperatorType.IS_DISTINCT_FROM)1 Signature (io.prestosql.spi.function.Signature)1 Signature.comparableWithVariadicBound (io.prestosql.spi.function.Signature.comparableWithVariadicBound)1 MAX_SHORT_PRECISION (io.prestosql.spi.type.Decimals.MAX_SHORT_PRECISION)1