Can i send arrays to UDF in lua as argument?


#1

can i send arrays or maps to UDF in lua as argument?


How to pass in objects or arrays as parameters into UDF?
#2

Yes. You can pass them as arguments. Please refer to the following links for examples in C and Java:

C: https://docs.aerospike.com/pages/viewpa … Id=3810522

Java: https://github.com/aerospike/aerospike- … ction.java


#3

Can you help me that what is wrong with my code below and how to fix it?

Here is my java code. I wanted to make search like a sql such as “SELECT bin1, bin2 FROM set WHERE bin1 IN (val1, val2)”

...
ArrayList<Object> excludeList = new ArrayList<Object>();
excludeList.add(2L);
excludeList.add(5L);

ResultSet rs = client.queryAggregate(new QueryPolicy(), stmt, "finder", "find_by_fields_in", Value.getAsList(excludeList));

try {
   while (rs.next()) {
      // bla bla bla
   }
}
finally {
   rs.close();
}
...

And my lua code is like this

function find_by_fields_in(stream, values)
   local function filter_by_values(record)
      for value in list.iterator(values) do
         if record['bin1'] == value then
            return true
         end
      end
      return false
   end
   
   local function mapper(record)
      local out = map()
      out['bin1'] = record['bin1']
      out['bin2'] = record['bin2']
      return out
   end

   return stream : filter(filter_by_values) : map(mapper)
end

And the result is

Caused by: java.lang.IllegalArgumentException: nulls in array
   at org.luaj.vm2.Varargs$ArrayVarargs.<init>(Unknown Source)
   at org.luaj.vm2.LuaValue.varargsOf(Unknown Source)
   at org.luaj.vm2.LuaValue.invoke(Unknown Source)
   at com.aerospike.client.lua.LuaInstance.call(LuaInstance.java:113)
   at com.aerospike.client.query.QueryAggregateExecutor.runThreads(QueryAggregateExecutor.java:107)
   at com.aerospike.client.query.QueryAggregateExecutor.run(QueryAggregateExecutor.java:81)
   at java.lang.Thread.run(Thread.java:744)

I thought this exception caused by ListValue.getLuaValue() returns null.

I am using aerospike-client 3.0.22.

Any help would be much appreciated, thanks


#4

Refer to the example here : http://www.aerospike.com/docs/udf/developing_stream_udfs.html#extra-arguments