Execute_udf_on_query does not give any data

#1

Hi, I am trying to stream some data but if I use execute_udf_on_query before the query, I always get 0 entries.

task = $client.register_udf_from_file("as_lua/ordermaker.lua", "ordermaker.lua", language=Aerospike::Language::LUA, options={})

stmt = Statement.new(Rails.application.config.aerospikeNS, "orders")
stmt.filters << Filter.Equal('tokenAddress', tokenAddress)
task = $client.execute_udf_on_query(stmt, 'ordermaker', 'from_maker', [makeraddress])
task.wait_till_completed

rs = $client.query(stmt,options = {})

rs.each { |rec| puts rec.bins.inspect }

I am not sure what am I doing wrong? when in aql I got ok data and if I left out execute_udf_on_query I also get results.

Thank you

#2

The Client#execute_udf_on_query function unfortunately modifies the query statement that you pass in as an argument:

    def execute_udf_on_query(statement, package_name, function_name, function_args=[], options = nil)
      ...
      statement.set_aggregate_function(package_name, function_name, function_args, false)
      ...
    end

Hence when you reuse the statement in the next query, it will again execute your UDF and not return the expected results.

For now, please create a new query statement for the 2nd query.

I’ve filed a ticket against the client to not modify the passed in statement here: https://github.com/aerospike/aerospike-client-ruby/issues/79. But I don’t intend to release a new client version for this immediately.

#3

Thank you, so what would look like execute_udf_on_query statement? something like this?

stmt = Statement.new(Rails.application.config.aerospikeNS, "orders")
task = $client.execute_udf_on_query(stmt, 'ordermaker', 'from_maker', [makeraddress])
task.wait_till_completed

rs = $client.query(stmt,options = {})
rs.each { |rec| puts rec.bins.inspect }
#4

The statement can be the same as before. You just have to create a new Statement instance for the 2nd query and cannot reuse the instance you passed to the execute_udf_on_query method:

stmt = Statement.new(Rails.application.config.aerospikeNS, "orders")
stmt.filters << Filter.Equal('tokenAddress', tokenAddress)
task = $client.execute_udf_on_query(stmt, 'ordermaker', 'from_maker', [makeraddress])
task.wait_till_completed

stmt = Statement.new(Rails.application.config.aerospikeNS, "orders")
stmt.filters << Filter.Equal('tokenAddress', tokenAddress)
rs = $client.query(stmt)
rs.each { |rec| puts rec.bins.inspect }
#5

Thank you, but it does not seems to work, as only the second filter is applied (udf filter is not applied). Maybe the problem is that result of udf filter is map? MAP(’{“maker”:"…"})

#6

I’m not sure what you mean.

The client.execute_udf_on_query() command applies a Record UDF to each record that matches the query statement filter. It is meant to update/create records as a background operation on the server. This command does not return any data. See https://www.aerospike.com/docs/guide/record_udf.html.

The second client.query() command should match the same set of records as the first command (since the same query filter is applied), and return the data to the application. There is no UDF filter applied in this command.