Search in sources :

Example 6 with SqlFunction

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

the class AbstractTestFunctions method registerScalar.

protected void registerScalar(Class<?> clazz) {
    Metadata metadata = functionAssertions.getMetadata();
    List<SqlFunction> functions = new FunctionListBuilder().scalars(clazz).getFunctions();
    metadata.getFunctionAndTypeManager().registerBuiltInFunctions(functions);
}
Also used : Metadata(com.facebook.presto.metadata.Metadata) FunctionListBuilder(com.facebook.presto.metadata.FunctionListBuilder) SqlFunction(com.facebook.presto.spi.function.SqlFunction)

Example 7 with SqlFunction

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

the class AbstractTestFunctions method registerParametricScalar.

protected void registerParametricScalar(Class<?> clazz) {
    Metadata metadata = functionAssertions.getMetadata();
    List<SqlFunction> functions = new FunctionListBuilder().scalar(clazz).getFunctions();
    metadata.getFunctionAndTypeManager().registerBuiltInFunctions(functions);
}
Also used : Metadata(com.facebook.presto.metadata.Metadata) FunctionListBuilder(com.facebook.presto.metadata.FunctionListBuilder) SqlFunction(com.facebook.presto.spi.function.SqlFunction)

Example 8 with SqlFunction

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

the class FunctionSignatureMatcher method identifyApplicableFunctions.

private List<ApplicableFunction> identifyApplicableFunctions(Collection<? extends SqlFunction> candidates, List<TypeSignatureProvider> actualParameters, boolean allowCoercion) {
    ImmutableList.Builder<ApplicableFunction> applicableFunctions = ImmutableList.builder();
    for (SqlFunction function : candidates) {
        Signature declaredSignature = function.getSignature();
        Optional<Signature> boundSignature = new SignatureBinder(functionAndTypeManager, declaredSignature, allowCoercion).bind(actualParameters);
        if (boundSignature.isPresent()) {
            applicableFunctions.add(new ApplicableFunction(declaredSignature, boundSignature.get(), function.isCalledOnNullInput()));
        }
    }
    return applicableFunctions.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Signature(com.facebook.presto.spi.function.Signature) SqlFunction(com.facebook.presto.spi.function.SqlFunction)

Example 9 with SqlFunction

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

the class TestFunctionAndTypeManager method testListingVisibilityBetaFunctionsDisabled.

@Test
public void testListingVisibilityBetaFunctionsDisabled() {
    FunctionAndTypeManager functionAndTypeManager = createTestFunctionAndTypeManager();
    List<SqlFunction> functions = functionAndTypeManager.listFunctions(TEST_SESSION, Optional.empty(), Optional.empty());
    List<String> names = transform(functions, input -> input.getSignature().getNameSuffix());
    assertTrue(names.contains("length"), "Expected function names " + names + " to contain 'length'");
    assertTrue(names.contains("stddev"), "Expected function names " + names + " to contain 'stddev'");
    assertTrue(names.contains("rank"), "Expected function names " + names + " to contain 'rank'");
    assertFalse(names.contains("quantiles_at_values"), "Expected function names " + names + " not to contain 'quantiles_at_values'");
    assertFalse(names.contains("like"), "Expected function names " + names + " not to contain 'like'");
    assertFalse(names.contains("$internal$sum_data_size_for_stats"), "Expected function names " + names + " not to contain '$internal$sum_data_size_for_stats'");
    assertFalse(names.contains("$internal$max_data_size_for_stats"), "Expected function names " + names + " not to contain '$internal$max_data_size_for_stats'");
}
Also used : FunctionAndTypeManager.createTestFunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager.createTestFunctionAndTypeManager) SqlFunction(com.facebook.presto.spi.function.SqlFunction) Test(org.testng.annotations.Test)

Example 10 with SqlFunction

use of com.facebook.presto.spi.function.SqlFunction 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

SqlFunction (com.facebook.presto.spi.function.SqlFunction)11 FunctionAndTypeManager.createTestFunctionAndTypeManager (com.facebook.presto.metadata.FunctionAndTypeManager.createTestFunctionAndTypeManager)5 Test (org.testng.annotations.Test)5 OperatorType (com.facebook.presto.common.function.OperatorType)4 OperatorType.tryGetOperatorType (com.facebook.presto.common.function.OperatorType.tryGetOperatorType)4 TypeSignature (com.facebook.presto.common.type.TypeSignature)4 TypeSignature.parseTypeSignature (com.facebook.presto.common.type.TypeSignature.parseTypeSignature)4 Signature (com.facebook.presto.spi.function.Signature)4 ImmutableList (com.google.common.collect.ImmutableList)3 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)3 Session (com.facebook.presto.Session)2 FunctionListBuilder (com.facebook.presto.metadata.FunctionListBuilder)2 Metadata (com.facebook.presto.metadata.Metadata)2 PrestoException (com.facebook.presto.spi.PrestoException)2 Parameter (com.facebook.presto.spi.function.Parameter)2 SqlInvokedFunction (com.facebook.presto.spi.function.SqlInvokedFunction)2 TypeSignatureProvider (com.facebook.presto.sql.analyzer.TypeSignatureProvider)2 ArrayList (java.util.ArrayList)2 TEST_SESSION (com.facebook.presto.SessionTestUtils.TEST_SESSION)1 EXPERIMENTAL_FUNCTIONS_ENABLED (com.facebook.presto.SystemSessionProperties.EXPERIMENTAL_FUNCTIONS_ENABLED)1