If using CDT data type bins in your records you could pass the array data as either a map or a list
I believe you would need to use the lua load or loadstring lua functions to create a lua table from the UDF parameter passed from aql.
Please see:
and
Here is an example for both passing a LIST and a MAP.
aql> INSERT INTO test.demo (PK, foo, bar) VALUES (‘key1’, LIST(‘[1, 2, 3]’), MAP(‘{“a”: 1, “b”: 2}’))
- Example with LIST data type using the array list merge function:
Lua file
testmerge.lua:
function merge ( rec , t )
local l = list()
-- Need to use load or loadstring lua functions to create a lua table from t
t = load("return "..t)()
-- converting table to list
for k,v in pairs(t) do list.append(l, v) end
-- Output debug info into aerospike.log
info("Passed Lua List Parameter %s", tostring(l))
-- Merge list in bin "foo"
rec["foo"] = list.merge(rec["foo"],l)
status = aerospike:update( rec )
end
aql commands:
$ aql
Aerospike Query Client
Version 3.13.0.1
C Client Version 4.1.6
Copyright 2012-2016 Aerospike. All rights reserved.
aql> select * from test.demo
+--------------------------------------+------------------------+
| foo | bar |
+--------------------------------------+------------------------+
| LIST('[1, 2, 3, 1, 2, 3, 1, 2, 3]') | MAP('{"a":1, "b":2}') |
+--------------------------------------+------------------------+
1 row in set (0.355 secs)
aql> execute testmerge.merge('{5, 6, 7}') on test.demo where PK='key1'
+-------+
| merge |
+-------+
| |
+-------+
1 row in set (0.001 secs)
aql> select * from test.demo
+-----------------------------------------------+------------------------+
| foo | bar |
+-----------------------------------------------+------------------------+
| LIST('[1, 2, 3, 1, 2, 3, 1, 2, 3, 5, 6, 7]') | MAP('{"a":1, "b":2}') |
+-----------------------------------------------+------------------------+
1 row in set (0.357 secs)
- Example with MAP data type using merge function and callback:
Lua file testmapmerge.lua:
function mapmerge ( rec , t )
-- Need to use load or loadstring lua functions to create a lua table from t
t = load("return "..t)()
local m = map(t)
-- Merge list in bin "bar"
rec["bar"] = map.merge(rec["bar"], m, function (v1, v2) return v1 + v2 end)
status = aerospike:update( rec )
end
aql commands :
aql> select * from test.demo
+-----------------------------------------------+------------------------+
| foo | bar |
+-----------------------------------------------+------------------------+
| LIST('[1, 2, 3, 1, 2, 3, 1, 2, 3, 5, 6, 7]') | MAP('{"a":1, "b":2}') |
+-----------------------------------------------+------------------------+
1 row in set (0.352 secs)
aql> execute testmapmerge.mapmerge('{a = 1, b = 2}') on test.demo where PK='key1'
+----------+
| mapmerge |
+----------+
| |
+----------+
1 row in set (0.002 secs)
aql> select * from test.demo
+-----------------------------------------------+------------------------+
| foo | bar |
+-----------------------------------------------+------------------------+
| LIST('[1, 2, 3, 1, 2, 3, 1, 2, 3, 5, 6, 7]') | MAP('{"a":2, "b":4}') |
+-----------------------------------------------+------------------------+
1 row in set (0.351 secs)
aql> execute testmapmerge.mapmerge('{a = 1, b = 2, c=4}') on test.demo where PK='key1'
+----------+
| mapmerge |
+----------+
| |
+----------+
1 row in set (0.001 secs)
aql> select * from test.demo
+-----------------------------------------------+-------------------------------+
| foo | bar |
+-----------------------------------------------+-------------------------------+
| LIST('[1, 2, 3, 1, 2, 3, 1, 2, 3, 5, 6, 7]') | MAP('{"a":3, "b":6, "c":4}') |
+-----------------------------------------------+-------------------------------+
1 row in set (0.360 secs)