Search in sources :

Example 1 with FunctionProvider

use of io.crate.metadata.FunctionProvider in project crate by crate.

the class AbstractFunctionModule method register.

public void register(Signature signature, BiFunction<Signature, Signature, FunctionImplementation> factory) {
    List<FunctionProvider> functions = functionImplementations.computeIfAbsent(signature.getName(), k -> new ArrayList<>());
    var duplicate = functions.stream().filter(fr -> fr.getSignature().equals(signature)).findFirst();
    if (duplicate.isPresent()) {
        throw new IllegalStateException("A function already exists for signature = " + signature);
    }
    functions.add(new FunctionProvider(signature, factory));
}
Also used : List(java.util.List) FunctionImplementation(io.crate.metadata.FunctionImplementation) AbstractModule(org.elasticsearch.common.inject.AbstractModule) FunctionName(io.crate.metadata.FunctionName) Map(java.util.Map) BiFunction(java.util.function.BiFunction) FunctionProvider(io.crate.metadata.FunctionProvider) HashMap(java.util.HashMap) Signature(io.crate.metadata.functions.Signature) MapBinder(org.elasticsearch.common.inject.multibindings.MapBinder) TypeLiteral(org.elasticsearch.common.inject.TypeLiteral) ArrayList(java.util.ArrayList) FunctionProvider(io.crate.metadata.FunctionProvider)

Example 2 with FunctionProvider

use of io.crate.metadata.FunctionProvider in project crate by crate.

the class UserDefinedFunctionService method updateImplementations.

public void updateImplementations(String schema, Stream<UserDefinedFunctionMetadata> userDefinedFunctions, NodeContext nodeCtx) {
    final Map<FunctionName, List<FunctionProvider>> implementations = new HashMap<>();
    Iterator<UserDefinedFunctionMetadata> it = userDefinedFunctions.iterator();
    while (it.hasNext()) {
        UserDefinedFunctionMetadata udf = it.next();
        FunctionProvider resolver = buildFunctionResolver(udf);
        if (resolver == null) {
            continue;
        }
        var functionName = new FunctionName(udf.schema(), udf.name());
        var resolvers = implementations.computeIfAbsent(functionName, k -> new ArrayList<>());
        resolvers.add(resolver);
    }
    nodeCtx.functions().registerUdfFunctionImplementationsForSchema(schema, implementations);
}
Also used : FunctionName(io.crate.metadata.FunctionName) HashMap(java.util.HashMap) FunctionProvider(io.crate.metadata.FunctionProvider) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with FunctionProvider

use of io.crate.metadata.FunctionProvider in project crate by crate.

the class PgFunctionIsVisibleFunctionTest method test_system_function_visibility.

@Test
public void test_system_function_visibility() {
    assertEvaluate("pg_function_is_visible(0)", false);
    assertEvaluate("pg_function_is_visible(-14)", false);
    for (List<FunctionProvider> providers : sqlExpressions.nodeCtx.functions().functionResolvers().values()) {
        for (FunctionProvider sysFunc : providers) {
            Signature signature = sysFunc.getSignature();
            Integer funcOid = OidHash.functionOid(signature);
            assertEvaluate("pg_function_is_visible(" + funcOid + ")", true);
        }
    }
}
Also used : FunctionProvider(io.crate.metadata.FunctionProvider) Signature(io.crate.metadata.functions.Signature) Test(org.junit.Test)

Example 4 with FunctionProvider

use of io.crate.metadata.FunctionProvider in project crate by crate.

the class PgGetFunctionResultFunctionTest method test_system_function_result_type_text_representation.

@Test
public void test_system_function_result_type_text_representation() {
    for (List<FunctionProvider> providers : sqlExpressions.nodeCtx.functions().functionResolvers().values()) {
        for (FunctionProvider sysFunc : providers) {
            Signature signature = sysFunc.getSignature();
            Integer funcOid = OidHash.functionOid(signature);
            assertEvaluate("pg_get_function_result(" + funcOid + ")", signature.getReturnType().toString());
        }
    }
}
Also used : FunctionProvider(io.crate.metadata.FunctionProvider) Signature(io.crate.metadata.functions.Signature) Test(org.junit.Test)

Aggregations

FunctionProvider (io.crate.metadata.FunctionProvider)4 Signature (io.crate.metadata.functions.Signature)3 FunctionName (io.crate.metadata.FunctionName)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Test (org.junit.Test)2 FunctionImplementation (io.crate.metadata.FunctionImplementation)1 Map (java.util.Map)1 BiFunction (java.util.function.BiFunction)1 AbstractModule (org.elasticsearch.common.inject.AbstractModule)1 TypeLiteral (org.elasticsearch.common.inject.TypeLiteral)1 MapBinder (org.elasticsearch.common.inject.multibindings.MapBinder)1