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

**URL:** <https://discuss.aerospike.com/t/failed-to-run-lua-multi-module-aggregation-function-using-java-client-module-not-found-error/9080>\
**Category:** Aggregation\
**Tags:** query, java, error\
**Created:** [December 14, 2021, 11:18pm UTC](https://discuss.aerospike.com/t/failed-to-run-lua-multi-module-aggregation-function-using-java-client-module-not-found-error/9080 "2021-12-14T23:18:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sleshJdev](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/sleshjdev/32/1783_2.png) [@sleshJdev](https://discuss.aerospike.com/u/sleshJdev)\
**Post date:** [December 14, 2021, 11:18pm UTC](https://discuss.aerospike.com/t/failed-to-run-lua-multi-module-aggregation-function-using-java-client-module-not-found-error/9080/1 "2021-12-14T23:18:46Z")

</div>

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](https://github.com/sleshJdev/as-demo) 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](https://docs.aerospike.com/docs/udf/examples/proto_rb.html) and Implementing SQL Operations: Aggregates ([Part 1](https://developer.aerospike.com/docs/tutorials/java/sql_aggregates_1), [Part 2](https://developer.aerospike.com/docs/tutorials/java/sql_aggregates_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](https://github.com/sleshJdev/as-demo/blob/master/src/test/java/org/example/AppTest.java#L74) test case passed? I want it to be work the same as aql version [testAqlIsAbleToCallLuaFuncToConvertDecodeProtoDigestAndReturnJson](https://github.com/sleshJdev/as-demo/blob/master/src/test/java/org/example/AppTest.java#L58).

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.

---

<div class="post-metadata">

**Author:** ![neelp](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/neelp/32/1369_2.png) [@neelp](https://discuss.aerospike.com/u/neelp)\
**Post date:** [December 17, 2021, 6:07pm UTC](https://discuss.aerospike.com/t/failed-to-run-lua-multi-module-aggregation-function-using-java-client-module-not-found-error/9080/2 "2021-12-17T18:07:22Z")

</div>

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](https://developer.aerospike.com/docs/tutorials/java/sql_aggregates_1#register-udf) 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](https://developer.aerospike.com/docs/tutorials/java/sql_aggregates_1#execution-model-for-processing-aggregates). 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.

---

<div class="post-metadata">

**Author:** ![sleshJdev](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/sleshjdev/32/1783_2.png) [@sleshJdev](https://discuss.aerospike.com/u/sleshJdev)\
**Post date:** [December 20, 2021, 2:02pm UTC](https://discuss.aerospike.com/t/failed-to-run-lua-multi-module-aggregation-function-using-java-client-module-not-found-error/9080/3 "2021-12-20T14:02:57Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![neelp](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/neelp/32/1369_2.png) [@neelp](https://discuss.aerospike.com/u/neelp)\
**Post date:** [December 21, 2021, 4:46pm UTC](https://discuss.aerospike.com/t/failed-to-run-lua-multi-module-aggregation-function-using-java-client-module-not-found-error/9080/4 "2021-12-21T16:46:16Z")

</div>

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.
