Search in sources :

Example 1 with FunctionArgumentDefinition

use of io.crate.analyze.FunctionArgumentDefinition in project crate by crate.

the class UserDefinedFunctionMetadata method toXContent.

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
    builder.startObject();
    builder.field("schema", schema);
    builder.field("name", name);
    builder.startArray("arguments");
    for (FunctionArgumentDefinition argument : arguments) {
        argument.toXContent(builder, params);
    }
    builder.endArray();
    builder.field("return_type");
    DataTypeXContent.toXContent(returnType, builder, params);
    builder.field("language", language);
    builder.field("definition", definition);
    builder.endObject();
    return builder;
}
Also used : FunctionArgumentDefinition(io.crate.analyze.FunctionArgumentDefinition)

Example 2 with FunctionArgumentDefinition

use of io.crate.analyze.FunctionArgumentDefinition in project crate by crate.

the class UserDefinedFunctionMetadata method writeTo.

@Override
public void writeTo(StreamOutput out) throws IOException {
    out.writeString(schema);
    out.writeString(name);
    out.writeVInt(arguments.size());
    for (FunctionArgumentDefinition argument : arguments) {
        argument.writeTo(out);
    }
    DataTypes.toStream(returnType, out);
    out.writeString(language);
    out.writeString(definition);
}
Also used : FunctionArgumentDefinition(io.crate.analyze.FunctionArgumentDefinition)

Example 3 with FunctionArgumentDefinition

use of io.crate.analyze.FunctionArgumentDefinition 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

FunctionArgumentDefinition (io.crate.analyze.FunctionArgumentDefinition)3 UserDefinedFunctionMetadata (io.crate.expression.udf.UserDefinedFunctionMetadata)1 FunctionName (io.crate.metadata.FunctionName)1 ScriptException (javax.script.ScriptException)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1