Error loading udf (C# client)


#1

Hi,

I’m trying to scan over a secondary index and want to handle all records of which the secondary index is null or empty. Therefore I created the following lua script:

local function notNullOrEmpty(val)
    return val ~= nil and val ~= ''
end

function cid_filter(stream)
return stream : notNullOrEmpty(record.cid)
end

I registered the user defined function using the following command:

string udf = "scan_index.lua";
RegisterTask registerTask = client.Register(null, udf, udf, Language.LUA);
registerTask.Wait();

The registration seems to be ok and when I check the server the scan_index.lua file is in directory udf/lua

/opt/aerospike/usr/udf/lua$ dir
scan_index.lua

I execute the QueryAggregate method like this

Statement statement = new Statement();
statement.SetNamespace(ns);
statement.SetSetName(set);
statement.SetAggregateFunction(udf, filter);

using (ResultSet rs = client.QueryAggregate(null, statement)) { /*some logic here*/ }

And the following error occurs

2015-08-17 07:46:19     1       ERROR   Exception occurred while testing Aerospike. [Exception:
    Aerospike.Client.AerospikeException: Query Failed: Error Code 4: Failed to find 'scan_index.lua' in 'udf\?.lua' --->
    Aerospike.Client.AerospikeException: Error Code 4: Failed to find 'scan_index.lua' in ' udf\?.lua'
at Aerospike.Client.LuaInstance.FindFile(String packageName)
at Aerospike.Client.LuaInstance.LoadPackageFromFile(String packageName)
at Aerospike.Client.LuaInstance.LoadPackage(Statement statement)
at Aerospike.Client.QueryAggregateExecutor.Run(Object obj)
--- End of inner exception stack trace ---
at Aerospike.Client.QueryExecutor.CheckForException()
at Aerospike.Client.ResultSet.Next()
at BTTester.Program.ScanIndex(AerospikeClient client, String ns, String set, ProfileIndexTypes index)
at BTTester.Program.TestAerospike()]

Does anyone have an idea what the problem can be? I already tried to move the scan_index.lua on my client application into a subfolder /udf and /udf/lua but the problem still occurs.

Thanks in advance for any tips that can resolve my problem,

Erwin


#2

Hi,

After some experimenting and reading I found the solution for my problem. There where 2 issues:

  • My Lua scripts were not in the folder udf on my client machine. To fix this I had to either create an udf subfolder or set the Lua path using: LuaConfig.PackagePath = @".?.lua";
  • When calling the SetAggregateFunction method, I provided scan_index.lua as packageName but this had to be scan_index (without the extension)

Regards,

Erwin