Search in sources :

Example 6 with FunctionName

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

the class UserDefinedFunctionsIntegrationTest method test_pg_function_is_visible.

@Test
public void test_pg_function_is_visible() throws Exception {
    Signature signature = Signature.builder().kind(FunctionType.SCALAR).name(new FunctionName(Schemas.DOC_SCHEMA_NAME, "my_func")).argumentTypes(TypeSignature.parseTypeSignature("array(array(integer))"), TypeSignature.parseTypeSignature("integer"), TypeSignature.parseTypeSignature("text")).returnType(TypeSignature.parseTypeSignature("text")).build();
    int functionOid = OidHash.functionOid(signature);
    execute("select pg_function_is_visible(" + functionOid + ")");
    assertThat(response.rows()[0][0], is(false));
    execute("create function doc.my_func(array(array(integer)), integer, text) returns text language dummy_lang as '42'");
    execute("select pg_function_is_visible(" + functionOid + ")");
    assertThat(response.rows()[0][0], is(true));
    execute("drop function doc.my_func(array(array(integer)), integer, text)");
    execute("select pg_function_is_visible(" + functionOid + ")");
    assertThat(response.rows()[0][0], is(false));
}
Also used : FunctionName(io.crate.metadata.FunctionName) Signature(io.crate.metadata.functions.Signature) TypeSignature(io.crate.types.TypeSignature) Test(org.junit.Test)

Example 7 with FunctionName

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

the class JavascriptUserDefinedFunctionTest method registerUserDefinedFunction.

private void registerUserDefinedFunction(String name, DataType<?> returnType, List<DataType<?>> types, String definition) throws ScriptException {
    UserDefinedFunctionMetadata udf = new UserDefinedFunctionMetadata(Schemas.DOC_SCHEMA_NAME, name, types.stream().map(FunctionArgumentDefinition::of).collect(Collectors.toList()), returnType, JS, definition);
    String validation = udfService.getLanguage(JS).validate(udf);
    if (validation == null) {
        var functionName = new FunctionName(Schemas.DOC_SCHEMA_NAME, udf.name());
        var resolvers = functionImplementations.computeIfAbsent(functionName, k -> new ArrayList<>());
        resolvers.add(udfService.buildFunctionResolver(udf));
        sqlExpressions.nodeCtx.functions().registerUdfFunctionImplementationsForSchema(Schemas.DOC_SCHEMA_NAME, functionImplementations);
    } else {
        throw new ScriptException(validation);
    }
}
Also used : FunctionArgumentDefinition(io.crate.analyze.FunctionArgumentDefinition) FunctionName(io.crate.metadata.FunctionName) ScriptException(javax.script.ScriptException) UserDefinedFunctionMetadata(io.crate.expression.udf.UserDefinedFunctionMetadata) Matchers.containsString(org.hamcrest.Matchers.containsString)

Aggregations

FunctionName (io.crate.metadata.FunctionName)7 Signature (io.crate.metadata.functions.Signature)4 TypeSignature (io.crate.types.TypeSignature)3 Test (org.junit.Test)3 FunctionProvider (io.crate.metadata.FunctionProvider)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 ScriptException (javax.script.ScriptException)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 FunctionArgumentDefinition (io.crate.analyze.FunctionArgumentDefinition)1 ParamTypeHints (io.crate.analyze.ParamTypeHints)1 ExpressionAnalysisContext (io.crate.analyze.expressions.ExpressionAnalysisContext)1 ExpressionAnalyzer (io.crate.analyze.expressions.ExpressionAnalyzer)1 TableReferenceResolver (io.crate.analyze.expressions.TableReferenceResolver)1 VisibleForTesting (io.crate.common.annotations.VisibleForTesting)1 Lists2 (io.crate.common.collections.Lists2)1 TimeValue (io.crate.common.unit.TimeValue)1 UserDefinedFunctionAlreadyExistsException (io.crate.exceptions.UserDefinedFunctionAlreadyExistsException)1 UserDefinedFunctionUnknownException (io.crate.exceptions.UserDefinedFunctionUnknownException)1