Registering UDFs

Hi, Is there a way to put the UDF on the server and the Aerospike will register it automatically? if not, I was wondering what is the way to know if a UDF already registered? I guess re-registering is an expansive operation

Aerospike has two types of UDFs, record udfs that operate on a record and can modify a record, stream udfs that work on a set of records in a read only mode and can be used to aggreagate data from the records. I would consider UDFs on advanced level side but very useful tool in Aerospike to do creative custom manipulation of data.

You register UDFs once, unless you modify them and want to re-register. I would not put registration API in the production application. Read further below.

If you are using record UDF, you can use the AQL tool that comes with the server installation. Module is a lua file containing your user defined functions.

$aql aql>help → see register / show / remove module command and examples aql>exit

If you are using stream UDFs, register via client API, once, unless you modify it. For example, in python you can use udf_put(). You can also write a small standalone application to load / update your stream udfs. See detailed discussion on how stream udfs work and where they are located on server and client nodes in this thread:

Hi I am working on my first udf – helloworld ---- firstmodule.lua on my mac home folder. get the following on aql prompt— pls help—

aql> register module '~/firstmodule.lua'
Error: (2) Cannot open file ~/firstmodule.lua

what am I doing wrong… :face_exhaling: I have that file which is the helloworld example from aerospike docs.

 cybertron-aerospike-poc git: ✗ ls ~/firstmodule.lua
/Users/xxxx/firstmodule.lua

thx

Try using the full path instead of tilda.

aql> register module '~/c_or_u.lua'
Error: (2) Cannot open file ~/c_or_u.lua

aql> register module '/home/training/c_or_u.lua'
OK, 1 module added.

aql>

thx, I tried that as well No Luck :face_exhaling:

aql> register module '/users/rguron/firstmodule.lua'
Error: (2) Cannot open file /users/rguron/firstmodule.lua

where as the file exists it has 777 permissions

➜  ~ ls ~/firstmodule.lua
/Users/rguron/firstmodule.lua

/users/ → Uppercase … /Users

thx, It is still failing … but It will fail as AQL I am running is a docker container

… I beleive I should be using client-go to register as my use cases are aggregation