Exception using UDF


#1

Hi,

I’m getting an exception in java client, testing simple UDF.

This is my code:

try {
          WritePolicy policy = new WritePolicy();
          Key key = new Key("test", "myset", "mykey");
          Bin bin = new Bin("name", "MyName");
          client.put(policy, key, bin);

          Record record = client.get(policy, key);
          System.out.println("Rec: " + record);

          RegisterTask task = client.register(null, "udf/example.lua", "example.lua", Language.LUA);
          task.waitTillComplete();
          System.out.println("Registerd : " + task.isDone());

          String result = (String) client.execute(null, key, "example.lua", "readBin", Value.get("name"));
          System.out.println(result);

        } catch (Exception e) {
          e.printStackTrace();
        } finally {
            client.close();
        }

This is the lua code:

function readBin(r, name)
    return r[name]
end

This is the output of the program:

Rec: (gen:18),(exp:165158717),(bins:(name:MyName)) Registerd : true com.aerospike.client.AerospikeException: Error Code 100: UDF: Execution Error 1 at com.aerospike.client.command.ReadCommand.handleUdfError(ReadCommand.java:134) at com.aerospike.client.command.ReadCommand.parseResult(ReadCommand.java:106) at com.aerospike.client.command.SyncCommand.execute(SyncCommand.java:56) at com.aerospike.client.AerospikeClient.execute(AerospikeClient.java:848) at com.matomy.test.TestBackup.runTest(TestBackup.java:45) at com.matomy.test.TestBackup.main(TestBackup.java:16) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:483) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)

Any idea?


#2

This is the aerospike log:

Feb 25 2015 14:20:12 GMT: WARNING (udf): (src/main/mod_lua.c::585) Lua Create Error: module 'example.lua' not found:
        no field package.preload['example.lua']
        no file './example/lua.lua'
        no file '/usr/local/share/lua/5.1/example/lua.lua'
        no file '/usr/local/share/lua/5.1/example/lua/init.lua'
        no file '/usr/local/lib/lua/5.1/example/lua.lua'
        no file '/usr/local/lib/lua/5.1/example/lua/init.lua'
        no file '/home/noam/dev/aerospike-server/share/udf/lua/example/lua.lua'
        no file '/home/noam/dev/aerospike-server/share/udf/lua/external/example/lua.lua'
        no file '/home/noam/dev/aerospike-server/var/udf/lua/example/lua.lua'
        no file './example/lua.so'
        no file '/usr/local/lib/lua/5.1/example/lua.so'
        no file '/usr/local/lib/lua/5.1/loadall.so'
        no file '/home/noam/dev/aerospike-server/share/udf/lua/example/lua.so'
        no file '/home/noam/dev/aerospike-server/share/udf/lua/external/example/lua.so'
        no file '/home/noam/dev/aerospike-server/var/udf/lua/example/lua.so'
        no file './example.so'
        no file '/usr/local/lib/

#3

Please register your lua file

aql > register module 'example.lua'

before running test …

– R


#4

Well, in the code I do that…

I just played with it for a few seconds, and now it works when I’m using the following:

RegisterTask task = client.register(null, "udf/updateAlg.lua", "algo.lua", Language.LUA);

and call the function using:

client.execute(null, key, "algo", "readBin", Value.get("name"));