How to use RegisterUdfString and Excute?


#1

I can see this in the documentation:

public ExecuteTask Execute(WritePolicy policy, Statement statement, string packageName, string functionName, params Value[] functionArgs)

and this:

public RegisterTask RegisterUdfString( Policy policy, string code, string serverPath, Language language )

I register the UDF function in this way:

var removeRecordFunction =
$@"function deleteRecord(r)
    aerospike: remove(r)
end";
        
Client.RegisterUdfString(null, removeRecordFunction, RemoveRecordUdfName, Language.LUA);

and I want to use it:

Client.Execute(null, statement, packageName, RemoveRecordUdfName);
  1. What is packageName (server package where user defined function resides) ??
  2. What happens when I register the function other the first time? Is it overwritten?
  3. Why “remove-record” is an invalid file name ??

#2
  1. Yes. The server uses packageName to find the path of the lua file on the server’s filesystem.

    server lua file path = {lua user-path}/{packageName}.lua

    Default user-path = /opt/aerospike/usr/udf/lua

  2. Yes. The previous lua file will be overwritten.

  3. I don’t think it’s an invalid file name. I changed “record_example” to “record-example” in the AerospikeDemo QueryExecute example and it worked for me.


#3

I now see the problem with “remove-record”. This argument is the serverFileName. The server requires that UDF file names have an extension. Just pass in “remove-record.lua” to RegisterUdfString().

var removeRecordFunction =
$@"function deleteRecord(r)
    aerospike: remove(r)
end";
        
Client.RegisterUdfString(null, removeRecordFunction, "remove-record.lua", Language.LUA);

Client.Execute(null, statement, "remove-record",  "deleteRecord");

#4

This topic was automatically closed 6 days after the last reply. New replies are no longer allowed.