Search in sources :

Example 1 with PUBLIC

use of com.facebook.presto.spi.function.SqlFunctionVisibility.PUBLIC in project presto by prestodb.

the class TestAnnotationEngineForScalars method testMultiScalarParse.

@Test
public void testMultiScalarParse() {
    Signature expectedSignature1 = new Signature(QualifiedObjectName.valueOf(DEFAULT_NAMESPACE, "static_method_scalar_1"), FunctionKind.SCALAR, DOUBLE.getTypeSignature(), ImmutableList.of(DOUBLE.getTypeSignature()));
    Signature expectedSignature2 = new Signature(QualifiedObjectName.valueOf(DEFAULT_NAMESPACE, "static_method_scalar_2"), FunctionKind.SCALAR, BIGINT.getTypeSignature(), ImmutableList.of(BIGINT.getTypeSignature()));
    Signature expectedSignature3 = new Signature(QualifiedObjectName.valueOf(DEFAULT_NAMESPACE, "static_method_scalar_3"), FunctionKind.SCALAR, BIGINT.getTypeSignature(), ImmutableList.of(BIGINT.getTypeSignature()));
    List<SqlScalarFunction> functions = ScalarFromAnnotationsParser.parseFunctionDefinitions(MultiScalarFunction.class);
    assertEquals(functions.size(), 3);
    ParametricScalar scalar1 = (ParametricScalar) functions.stream().filter(signature -> signature.getSignature().equals(expectedSignature1)).collect(toImmutableList()).get(0);
    ParametricScalar scalar2 = (ParametricScalar) functions.stream().filter(signature -> signature.getSignature().equals(expectedSignature2)).collect(toImmutableList()).get(0);
    ParametricScalar scalar3 = (ParametricScalar) functions.stream().filter(signature -> signature.getSignature().equals(expectedSignature3)).collect(toImmutableList()).get(0);
    assertImplementationCount(scalar1, 1, 0, 0);
    assertImplementationCount(scalar2, 1, 0, 0);
    assertEquals(scalar1.getSignature(), expectedSignature1);
    assertTrue(scalar1.isDeterministic());
    assertEquals(scalar1.getVisibility(), PUBLIC);
    assertEquals(scalar1.getDescription(), "Simple scalar with single implementation based on method 1");
    assertEquals(scalar2.getSignature(), expectedSignature2);
    assertFalse(scalar2.isDeterministic());
    assertEquals(scalar2.getVisibility(), HIDDEN);
    assertEquals(scalar2.getDescription(), "Simple scalar with single implementation based on method 2");
    assertEquals(scalar3.getSignature(), expectedSignature3);
    assertFalse(scalar3.isDeterministic());
    assertEquals(scalar3.getVisibility(), EXPERIMENTAL);
    assertEquals(scalar3.getDescription(), "Simple scalar with single implementation based on method 3");
}
Also used : FunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager) EXPERIMENTAL(com.facebook.presto.spi.function.SqlFunctionVisibility.EXPERIMENTAL) StandardTypes(com.facebook.presto.common.type.StandardTypes) TypeParameter(com.facebook.presto.spi.function.TypeParameter) FunctionKind(com.facebook.presto.spi.function.FunctionKind) Slice(io.airlift.slice.Slice) ParametricScalar(com.facebook.presto.operator.scalar.ParametricScalar) ParametricScalarImplementationChoice(com.facebook.presto.operator.scalar.annotations.ParametricScalarImplementation.ParametricScalarImplementationChoice) TypeImplementationDependency(com.facebook.presto.operator.annotations.TypeImplementationDependency) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) FunctionAndTypeManager.createTestFunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager.createTestFunctionAndTypeManager) DEFAULT_NAMESPACE(com.facebook.presto.metadata.BuiltInTypeAndFunctionNamespaceManager.DEFAULT_NAMESPACE) Signature.typeVariable(com.facebook.presto.spi.function.Signature.typeVariable) ImmutableList(com.google.common.collect.ImmutableList) Description(com.facebook.presto.spi.function.Description) QualifiedObjectName(com.facebook.presto.common.QualifiedObjectName) BOOLEAN(com.facebook.presto.common.type.BooleanType.BOOLEAN) LiteralParameters(com.facebook.presto.spi.function.LiteralParameters) RETURN_NULL_ON_NULL(com.facebook.presto.operator.scalar.ScalarFunctionImplementationChoice.NullConvention.RETURN_NULL_ON_NULL) Assert.assertFalse(org.testng.Assert.assertFalse) Type(com.facebook.presto.common.type.Type) LiteralParameter(com.facebook.presto.type.LiteralParameter) BuiltInScalarFunctionImplementation(com.facebook.presto.operator.scalar.BuiltInScalarFunctionImplementation) BIGINT(com.facebook.presto.common.type.BigintType.BIGINT) ImmutableSet(com.google.common.collect.ImmutableSet) BoundVariables(com.facebook.presto.metadata.BoundVariables) DOUBLE(com.facebook.presto.common.type.DoubleType.DOUBLE) SqlScalarFunction(com.facebook.presto.metadata.SqlScalarFunction) HIDDEN(com.facebook.presto.spi.function.SqlFunctionVisibility.HIDDEN) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) USE_BOXED_TYPE(com.facebook.presto.operator.scalar.ScalarFunctionImplementationChoice.NullConvention.USE_BOXED_TYPE) USE_NULL_FLAG(com.facebook.presto.operator.scalar.ScalarFunctionImplementationChoice.NullConvention.USE_NULL_FLAG) Iterables.getOnlyElement(com.google.common.collect.Iterables.getOnlyElement) ArgumentProperty.valueTypeArgumentProperty(com.facebook.presto.operator.scalar.ScalarFunctionImplementationChoice.ArgumentProperty.valueTypeArgumentProperty) PUBLIC(com.facebook.presto.spi.function.SqlFunctionVisibility.PUBLIC) List(java.util.List) TypeSignature.parseTypeSignature(com.facebook.presto.common.type.TypeSignature.parseTypeSignature) ScalarFromAnnotationsParser(com.facebook.presto.operator.scalar.annotations.ScalarFromAnnotationsParser) IsNull(com.facebook.presto.spi.function.IsNull) SqlNullable(com.facebook.presto.spi.function.SqlNullable) Signature(com.facebook.presto.spi.function.Signature) Assert.assertTrue(org.testng.Assert.assertTrue) Block(com.facebook.presto.common.block.Block) ImplementationDependency(com.facebook.presto.operator.annotations.ImplementationDependency) LiteralImplementationDependency(com.facebook.presto.operator.annotations.LiteralImplementationDependency) ScalarFunction(com.facebook.presto.spi.function.ScalarFunction) SqlType(com.facebook.presto.spi.function.SqlType) TypeSignature.parseTypeSignature(com.facebook.presto.common.type.TypeSignature.parseTypeSignature) Signature(com.facebook.presto.spi.function.Signature) ParametricScalar(com.facebook.presto.operator.scalar.ParametricScalar) SqlScalarFunction(com.facebook.presto.metadata.SqlScalarFunction) Test(org.testng.annotations.Test)

Example 2 with PUBLIC

use of com.facebook.presto.spi.function.SqlFunctionVisibility.PUBLIC in project presto by prestodb.

the class TestFunctionAndTypeManager method testDuplicateFunctions.

@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "\\QFunction already registered: presto.default.custom_add(bigint,bigint):bigint\\E")
public void testDuplicateFunctions() {
    List<SqlFunction> functions = new FunctionListBuilder().scalars(CustomFunctions.class).getFunctions().stream().filter(input -> input.getSignature().getNameSuffix().equals("custom_add")).collect(toImmutableList());
    FunctionAndTypeManager functionAndTypeManager = createTestFunctionAndTypeManager();
    functionAndTypeManager.registerBuiltInFunctions(functions);
    functionAndTypeManager.registerBuiltInFunctions(functions);
}
Also used : Parameter(com.facebook.presto.spi.function.Parameter) CAST(com.facebook.presto.common.function.OperatorType.CAST) Test(org.testng.annotations.Test) SqlInvokedFunction(com.facebook.presto.spi.function.SqlInvokedFunction) TypeSignature(com.facebook.presto.common.type.TypeSignature) Signature.typeVariable(com.facebook.presto.spi.function.Signature.typeVariable) Map(java.util.Map) QualifiedObjectName(com.facebook.presto.common.QualifiedObjectName) FunctionAndTypeManager.qualifyObjectName(com.facebook.presto.metadata.FunctionAndTypeManager.qualifyObjectName) Assert.assertFalse(org.testng.Assert.assertFalse) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Collections.nCopies(java.util.Collections.nCopies) MethodHandles(java.lang.invoke.MethodHandles) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) LiteralEncoder.getMagicLiteralFunctionSignature(com.facebook.presto.sql.planner.LiteralEncoder.getMagicLiteralFunctionSignature) EXPERIMENTAL_FUNCTIONS_ENABLED(com.facebook.presto.SystemSessionProperties.EXPERIMENTAL_FUNCTIONS_ENABLED) SATURATED_FLOOR_CAST(com.facebook.presto.common.function.OperatorType.SATURATED_FLOOR_CAST) TINY_SCHEMA_NAME(com.facebook.presto.tpch.TpchMetadata.TINY_SCHEMA_NAME) SCALAR(com.facebook.presto.spi.function.FunctionKind.SCALAR) String.format(java.lang.String.format) CustomFunctions(com.facebook.presto.operator.scalar.CustomFunctions) SqlFunctionVisibility(com.facebook.presto.spi.function.SqlFunctionVisibility) ArgumentProperty.valueTypeArgumentProperty(com.facebook.presto.operator.scalar.ScalarFunctionImplementationChoice.ArgumentProperty.valueTypeArgumentProperty) List(java.util.List) TypeSignatureProvider(com.facebook.presto.sql.analyzer.TypeSignatureProvider) Optional(java.util.Optional) SqlType(com.facebook.presto.spi.function.SqlType) QualifiedName(com.facebook.presto.sql.tree.QualifiedName) StandardTypes(com.facebook.presto.common.type.StandardTypes) TIMESTAMP_WITH_TIME_ZONE(com.facebook.presto.common.type.TimestampWithTimeZoneType.TIMESTAMP_WITH_TIME_ZONE) Assert.assertEquals(org.testng.Assert.assertEquals) Lists.transform(com.google.common.collect.Lists.transform) HYPER_LOG_LOG(com.facebook.presto.common.type.HyperLogLogType.HYPER_LOG_LOG) FunctionAndTypeManager.createTestFunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager.createTestFunctionAndTypeManager) TEST_SESSION(com.facebook.presto.SessionTestUtils.TEST_SESSION) ImmutableList(com.google.common.collect.ImmutableList) ADD(com.facebook.presto.sql.tree.ArithmeticBinaryExpression.Operator.ADD) TypeSignatureProvider.fromTypeSignatures(com.facebook.presto.sql.analyzer.TypeSignatureProvider.fromTypeSignatures) FunctionResolution(com.facebook.presto.sql.relational.FunctionResolution) SqlFunction(com.facebook.presto.spi.function.SqlFunction) RETURN_NULL_ON_NULL(com.facebook.presto.operator.scalar.ScalarFunctionImplementationChoice.NullConvention.RETURN_NULL_ON_NULL) RoutineCharacteristics(com.facebook.presto.spi.function.RoutineCharacteristics) BuiltInScalarFunctionImplementation(com.facebook.presto.operator.scalar.BuiltInScalarFunctionImplementation) BIGINT(com.facebook.presto.common.type.BigintType.BIGINT) TypeVariableConstraint(com.facebook.presto.spi.function.TypeVariableConstraint) Session(com.facebook.presto.Session) OperatorType.tryGetOperatorType(com.facebook.presto.common.function.OperatorType.tryGetOperatorType) Assert.fail(org.testng.Assert.fail) TestingSession.testSessionBuilder(com.facebook.presto.testing.TestingSession.testSessionBuilder) OperatorType(com.facebook.presto.common.function.OperatorType) PUBLIC(com.facebook.presto.spi.function.SqlFunctionVisibility.PUBLIC) Collectors.toList(java.util.stream.Collectors.toList) SqlFunctionId(com.facebook.presto.spi.function.SqlFunctionId) TypeSignature.parseTypeSignature(com.facebook.presto.common.type.TypeSignature.parseTypeSignature) FunctionVersion.notVersioned(com.facebook.presto.spi.function.FunctionVersion.notVersioned) Signature(com.facebook.presto.spi.function.Signature) FunctionHandle(com.facebook.presto.spi.function.FunctionHandle) GREATER_THAN(com.facebook.presto.sql.tree.ComparisonExpression.Operator.GREATER_THAN) Assert.assertTrue(org.testng.Assert.assertTrue) ScalarFunction(com.facebook.presto.spi.function.ScalarFunction) FunctionAndTypeManager.createTestFunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager.createTestFunctionAndTypeManager) SqlFunction(com.facebook.presto.spi.function.SqlFunction) Test(org.testng.annotations.Test)

Aggregations

QualifiedObjectName (com.facebook.presto.common.QualifiedObjectName)2 BIGINT (com.facebook.presto.common.type.BigintType.BIGINT)2 StandardTypes (com.facebook.presto.common.type.StandardTypes)2 TypeSignature.parseTypeSignature (com.facebook.presto.common.type.TypeSignature.parseTypeSignature)2 FunctionAndTypeManager.createTestFunctionAndTypeManager (com.facebook.presto.metadata.FunctionAndTypeManager.createTestFunctionAndTypeManager)2 BuiltInScalarFunctionImplementation (com.facebook.presto.operator.scalar.BuiltInScalarFunctionImplementation)2 ArgumentProperty.valueTypeArgumentProperty (com.facebook.presto.operator.scalar.ScalarFunctionImplementationChoice.ArgumentProperty.valueTypeArgumentProperty)2 RETURN_NULL_ON_NULL (com.facebook.presto.operator.scalar.ScalarFunctionImplementationChoice.NullConvention.RETURN_NULL_ON_NULL)2 ScalarFunction (com.facebook.presto.spi.function.ScalarFunction)2 Signature (com.facebook.presto.spi.function.Signature)2 Signature.typeVariable (com.facebook.presto.spi.function.Signature.typeVariable)2 PUBLIC (com.facebook.presto.spi.function.SqlFunctionVisibility.PUBLIC)2 SqlType (com.facebook.presto.spi.function.SqlType)2 Session (com.facebook.presto.Session)1 TEST_SESSION (com.facebook.presto.SessionTestUtils.TEST_SESSION)1 EXPERIMENTAL_FUNCTIONS_ENABLED (com.facebook.presto.SystemSessionProperties.EXPERIMENTAL_FUNCTIONS_ENABLED)1 Block (com.facebook.presto.common.block.Block)1 OperatorType (com.facebook.presto.common.function.OperatorType)1 CAST (com.facebook.presto.common.function.OperatorType.CAST)1 SATURATED_FLOOR_CAST (com.facebook.presto.common.function.OperatorType.SATURATED_FLOOR_CAST)1