Search in sources :

Example 11 with Signature

use of io.prestosql.spi.function.Signature in project hetu-core by openlookeng.

the class TestPolymorphicScalarFunction method testSelectsMultipleChoiceWithBlockPosition.

@Test
public void testSelectsMultipleChoiceWithBlockPosition() throws Throwable {
    Signature signature = Signature.builder().kind(SCALAR).operatorType(IS_DISTINCT_FROM).argumentTypes(DECIMAL_SIGNATURE, DECIMAL_SIGNATURE).returnType(parseTypeSignature(BOOLEAN)).build();
    SqlScalarFunction function = SqlScalarFunction.builder(TestMethods.class).signature(signature).deterministic(true).calledOnNullInput(IS_DISTINCT_FROM.isCalledOnNullInput()).choice(choice -> choice.argumentProperties(valueTypeArgumentProperty(USE_NULL_FLAG), valueTypeArgumentProperty(USE_NULL_FLAG)).implementation(methodsGroup -> methodsGroup.methods("shortShort", "longLong"))).choice(choice -> choice.argumentProperties(valueTypeArgumentProperty(BLOCK_AND_POSITION), valueTypeArgumentProperty(BLOCK_AND_POSITION)).implementation(methodsGroup -> methodsGroup.methodWithExplicitJavaTypes("blockPositionLongLong", asList(Optional.of(Slice.class), Optional.of(Slice.class))).methodWithExplicitJavaTypes("blockPositionShortShort", asList(Optional.of(long.class), Optional.of(long.class))))).build();
    BuiltInScalarFunctionImplementation functionImplementation = function.specialize(SHORT_DECIMAL_BOUND_VARIABLES, 2, METADATA.getFunctionAndTypeManager());
    assertEquals(functionImplementation.getAllChoices().size(), 2);
    assertEquals(functionImplementation.getAllChoices().get(0).getArgumentProperties(), Collections.nCopies(2, valueTypeArgumentProperty(USE_NULL_FLAG)));
    assertEquals(functionImplementation.getAllChoices().get(1).getArgumentProperties(), Collections.nCopies(2, valueTypeArgumentProperty(BLOCK_AND_POSITION)));
    Block block1 = new LongArrayBlock(0, Optional.empty(), new long[0]);
    Block block2 = new LongArrayBlock(0, Optional.empty(), new long[0]);
    assertFalse((boolean) functionImplementation.getAllChoices().get(1).getMethodHandle().invoke(block1, 0, block2, 0));
    functionImplementation = function.specialize(LONG_DECIMAL_BOUND_VARIABLES, 2, METADATA.getFunctionAndTypeManager());
    assertTrue((boolean) functionImplementation.getAllChoices().get(1).getMethodHandle().invoke(block1, 0, block2, 0));
}
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) LongArrayBlock(io.prestosql.spi.block.LongArrayBlock) BuiltInScalarFunctionImplementation(io.prestosql.spi.function.BuiltInScalarFunctionImplementation) TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) Signature(io.prestosql.spi.function.Signature) TypeSignature(io.prestosql.spi.type.TypeSignature) LongArrayBlock(io.prestosql.spi.block.LongArrayBlock) Block(io.prestosql.spi.block.Block) Test(org.testng.annotations.Test)

Example 12 with Signature

use of io.prestosql.spi.function.Signature in project hetu-core by openlookeng.

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).deterministic(true).calledOnNullInput(FOO_IS_CALL_ON_NUL_INPUT).choice(choice -> choice.implementation(methodsGroup -> methodsGroup.methods("varcharToVarchar"))).build();
    BuiltInScalarFunctionImplementation functionImplementation = function.specialize(BOUND_VARIABLES, 1, METADATA.getFunctionAndTypeManager());
    Slice slice = (Slice) functionImplementation.getMethodHandle().invoke(INPUT_SLICE);
    assertEquals(slice, VARCHAR_TO_VARCHAR_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) Slice(io.airlift.slice.Slice) TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) Signature(io.prestosql.spi.function.Signature) TypeSignature(io.prestosql.spi.type.TypeSignature) Test(org.testng.annotations.Test)

Example 13 with Signature

use of io.prestosql.spi.function.Signature in project hetu-core by openlookeng.

the class TestPolymorphicScalarFunction method testSetsHiddenToTrueForOperators.

@Test
public void testSetsHiddenToTrueForOperators() {
    Signature signature = Signature.builder().operatorType(ADD).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).calledOnNullInput(ADD.isCalledOnNullInput()).deterministic(true).choice(choice -> choice.implementation(methodsGroup -> methodsGroup.methods("varcharToVarchar"))).build();
    BuiltInScalarFunctionImplementation functionImplementation = function.specialize(BOUND_VARIABLES, 1, METADATA.getFunctionAndTypeManager());
}
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) TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) Signature(io.prestosql.spi.function.Signature) TypeSignature(io.prestosql.spi.type.TypeSignature) Test(org.testng.annotations.Test)

Example 14 with Signature

use of io.prestosql.spi.function.Signature in project hetu-core by openlookeng.

the class TestPolymorphicScalarFunction method testTypeParameters.

@Test
public void testTypeParameters() throws Throwable {
    Signature signature = Signature.builder().name("foo").kind(SCALAR).typeVariableConstraints(comparableWithVariadicBound("V", VARCHAR)).returnType(parseTypeSignature("V")).argumentTypes(parseTypeSignature("V")).build();
    SqlScalarFunction function = SqlScalarFunction.builder(TestMethods.class).signature(signature).deterministic(true).calledOnNullInput(FOO_IS_CALL_ON_NUL_INPUT).choice(choice -> choice.implementation(methodsGroup -> methodsGroup.methods("varcharToVarchar"))).build();
    BuiltInScalarFunctionImplementation functionImplementation = function.specialize(BOUND_VARIABLES, 1, METADATA.getFunctionAndTypeManager());
    Slice slice = (Slice) functionImplementation.getMethodHandle().invoke(INPUT_SLICE);
    assertEquals(slice, VARCHAR_TO_VARCHAR_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) Slice(io.airlift.slice.Slice) TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) Signature(io.prestosql.spi.function.Signature) TypeSignature(io.prestosql.spi.type.TypeSignature) Test(org.testng.annotations.Test)

Example 15 with Signature

use of io.prestosql.spi.function.Signature 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

Signature (io.prestosql.spi.function.Signature)230 Test (org.testng.annotations.Test)186 TypeSignature.parseTypeSignature (io.prestosql.spi.type.TypeSignature.parseTypeSignature)184 TypeSignature (io.prestosql.spi.type.TypeSignature)93 InternalAggregationFunction (io.prestosql.operator.aggregation.InternalAggregationFunction)69 BuiltInFunctionHandle (io.prestosql.spi.function.BuiltInFunctionHandle)41 CallExpression (io.prestosql.spi.relation.CallExpression)35 Type (io.prestosql.spi.type.Type)23 RowExpression (io.prestosql.spi.relation.RowExpression)20 Block (io.prestosql.spi.block.Block)18 ArrayList (java.util.ArrayList)17 ImmutableList (com.google.common.collect.ImmutableList)15 SqlScalarFunction (io.prestosql.metadata.SqlScalarFunction)15 MapType (io.prestosql.spi.type.MapType)14 ImmutableSet (com.google.common.collect.ImmutableSet)12 Slice (io.airlift.slice.Slice)12 ParametricAggregation (io.prestosql.operator.aggregation.ParametricAggregation)11 BuiltInScalarFunctionImplementation (io.prestosql.spi.function.BuiltInScalarFunctionImplementation)11 AggregationImplementation (io.prestosql.operator.aggregation.AggregationImplementation)10 AggregationMetadata (io.prestosql.operator.aggregation.AggregationMetadata)10