Calculation with Lua on map bin


#1

I do have a set where one of the bins is a map and I need to run calculations on the map values.

Example: Map bin would contain:

{ 
  "Key1": 123,
  "Key2": 234,
  "Key3": 345
}

Now I’d like to run a calculation on for example Key3 / Key1 and return this result for all records that match my query.

Any help on how to create the corresponding UDF for this would be highly appreciated.

TIA


#2

Would look something like

 function div(rec, binName) 
     if aerospike:exists(rec) and rec[binName] ~= nil then
           local m = rec[binName]
           return m["key3"] / m["key1"]
     else
           return 0
end

HTH – R