Failed to run lua multi module aggregation function using java client. Module not found error

Hi

Let’s just cat to the chase. I want to create mini LUA framework(set of UDF) allowing us to run different aggregations on the aerospike. Here you may find toy project which demonstrates it. Everything works fine while I run my function using aql. But when I want to call my func from the java application using com.aerospike.client.AerospikeClient#queryAggregate(com.aerospike.client.policy.QueryPolicy, com.aerospike.client.query.Statement) I start getting errors like org.luaj.vm2.LuaError: demo:1 module 'person_pb' not found: person_pb. This demo app is mostly inspired by Protobuf Module Example and Implementing SQL Operations: Aggregates (Part 1, Part 2), I just combined them together. I tried different workaround to provide all the required modules but it always failes because next required module missing.

When I try to provide missing moduel(just put it near to module I am calling) it starts compaining aboud missing module protobuf. I also tried to use com.aerospike.client.IAerospikeClient#register(com.aerospike.client.policy.Policy, java.lang.String, java.lang.String, com.aerospike.client.Language), play with com.aerospike.client.lua.LuaConfig#SourceDirectory - nothing works to me. So, literally to get it working I need to pull all the source of lua modules from AS server to my local machine.

Could someone please take a look at the demo project and help me/explain how to get testJavaAerospikeClient test case passed? I want it to be work the same as aql version testAqlIsAbleToCallLuaFuncToConvertDecodeProtoDigestAndReturnJson.

Also, I’d appropriate if for explanation, why java client cannot make call lua module on AS side remotely and get the result. Why so much ceremony with loading/compiling lua code on the client side? Is there any way how to skip this step and ask client just call remote function and get the result?

I’ll highly appreciate for any advice in solving problem. Thanks in advance.

Please try registering the stream (aggregation) UDF module with a client API call and also setting LuaConfig.SourceDirectory if the client side module location is not ./udf. Please see the code in this code cell in the tutorial SQL Operations: Aggregates (Part 1).

You must register a stream UDF module on the client before calling the stream UDF function as a stream function is executed both on the server side and the client side. The execution model is explained in the tutorial here. For a record UDF (which is executed only on the server side), a client registration is not required if the module is already registered on the server.

Does it mean, if one of my modules requires protobuf, it should be in LuaConfig.SourceDirectory on client side? Literally, all the code I am going to run, should be available on the client side, not just on the server?

You could remove dependencies in the client-side code on the protobuf module (and other modules) by only keeping dummy definitions of the “server-side only” stream functions. Clearly all modules required for client-side stream processing must be present. For record UDFs, no client resident code should be required.