Search code examples
javaaerospike

Aerospike - Query with Multiple Filters


I'm trying to query aerospike using multiple filters taking reference from the below mentioned link ...

https://www.aerospike.com/community/labs/query_multiple_filters.html

In the example proposed in the above thread, aerospike-client version in use is 3.0.22 and I'm using version 3.0.0 in my project. I'm able to query the database and retrieve the desired data altering the mentioned example on the aerospike website but when I run the same code in my project no data is returned.

Are lua scripts and aggregate functions for data retrieval not supported in version 3.0.0? If they are, is there any other way to query the same with version 3.0.0?

Lua Script

local function map_order(record)
return map {key=record.key, mid=record.mid, orderId=record.orderId, amount=record.amount}
end

function filter_order(stream, mid)
  local function filter_mid(record)
    return record.mid == mid
  end

  return stream : filter(filter_mid) : map(map_order)

end

Data Retrieval Code

ResultSet resultSet = client.queryAggregate(null, stmt, "profile", "filter_order", Value.get("mid334"));

Edit: Getting this Exception

com.aerospike.client.AerospikeException: Failed to read file: /home/lalit/spring-suite/sts-bundle/sts-3.6.3.RELEASE/udf/profile.lua

when the file is located at /home/lalit/udf/profile.udf

code for registering the lua file

 LuaConfig.SourceDirectory = "udf";
 udfFile = new File("/home/lalit/udf/profile.lua");
 task = client.getAerospikeClient().register(null, udfFile.getPath(), udfFile.getName(), Language.LUA); 
 task.waitTillComplete();

Solution

  • Managed to solve it.

    run method of the QueryAggregateExecutor loads the lua functions from file system where it uses LuaConfig.SourceDirectory variable to locate the path to the script file.

    I was passing udf

    LuaConfig.SourceDirectory = "udf"
    

    which should have been /home/lalit/udf

    LuaConfig.SourceDirectory = "/home/lalit/udf"