What is the Syntax to pass 2D array values to the record UDF using AQl

I developed Record UDF function which reads and manipulate 2D array values. Now i want to execute this function using AQL but at the time of argument passing it give me a error so how can i pass 2D array values to the record UDF function. I have tried

aql > execute val_up_using_idx.mul_bin_update("{{'emails','abc@gmail.com','T'}, {'name','pqr','F'}, {'addr','awe','T'}}") on test.list_demo_1 where PK = '1'

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}’))

  1. 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)
  1. 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)

Thanx for the reply this array list merge function will useful for me in the feature. For passing the 2D array i used following syntax.

aql > execute val_up_using_idx.mul_bin_update(‘JSON[[“email","xyz@gmail.com”,“T”],[“name”,“abc”,“F”],[“addr”,“pqr”,“T”]]’) on test.emp_details where PK = ‘1’