use of io.crate.metadata.functions.Signature in project crate by crate.
the class BaseImplementationSymbolVisitor method visitFunction.
@Override
public Input<?> visitFunction(Function function, C context) {
Signature signature = function.signature();
FunctionImplementation functionImplementation = nodeCtx.functions().getQualified(function, txnCtx.sessionSettings().searchPath());
assert functionImplementation != null : "Function implementation not found using full qualified lookup";
if (functionImplementation instanceof Scalar<?, ?>) {
List<Symbol> arguments = function.arguments();
Scalar<?, ?> scalarImpl = ((Scalar) functionImplementation).compile(arguments);
Input[] argumentInputs = new Input[arguments.size()];
int i = 0;
for (Symbol argument : function.arguments()) {
argumentInputs[i++] = argument.accept(this, context);
}
return new FunctionExpression<>(txnCtx, nodeCtx, scalarImpl, argumentInputs);
} else {
throw new UnsupportedFeatureException(String.format(Locale.ENGLISH, "Function %s(%s) is not a scalar function.", signature.getName(), Lists2.joinOn(", ", function.arguments(), x -> x.valueType().getName())));
}
}
use of io.crate.metadata.functions.Signature in project crate by crate.
the class DocSchemaInfoTest method setup.
@Before
public void setup() throws Exception {
nodeCtx = createNodeContext();
udfService = new UserDefinedFunctionService(clusterService, nodeCtx);
udfService.registerLanguage(new UDFLanguage() {
@Override
public Scalar createFunctionImplementation(UserDefinedFunctionMetadata metadata, Signature signature) throws ScriptException {
String error = validate(metadata);
if (error != null) {
throw new ScriptException("this is not Burlesque");
}
return new Scalar<>() {
@Override
public Object evaluate(TransactionContext txnCtx, NodeContext nodeCtx, Input[] args) {
return null;
}
@Override
public Signature signature() {
return signature;
}
@Override
public Signature boundSignature() {
return signature;
}
};
}
@Override
@Nullable
public String validate(UserDefinedFunctionMetadata metadata) {
if (!metadata.definition().equals("\"Hello, World!\"Q")) {
return "this is not Burlesque";
}
return null;
}
@Override
public String name() {
return "burlesque";
}
});
docSchemaInfo = new DocSchemaInfo("doc", clusterService, nodeCtx, udfService, (ident, state) -> null, new TestingDocTableInfoFactory(Map.of()));
}
Aggregations