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;
}
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);
}
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);
}
}
Aggregations