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

**URL:** <https://discuss.aerospike.com/t/what-is-the-syntax-to-pass-2d-array-values-to-the-record-udf-using-aql/4378>\
**Category:** User Defined Functions (UDF)\
**Created:** [July 12, 2017, 7:26am UTC](https://discuss.aerospike.com/t/what-is-the-syntax-to-pass-2d-array-values-to-the-record-udf-using-aql/4378 "2017-07-12T07:26:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nikhil\_bandal](https://avatars.discourse-cdn.com/v4/letter/n/65b543/32.png) [@nikhil\_bandal](https://discuss.aerospike.com/u/nikhil_bandal)\
**Post date:** [July 12, 2017, 7:26am UTC](https://discuss.aerospike.com/t/what-is-the-syntax-to-pass-2d-array-values-to-the-record-udf-using-aql/4378/1 "2017-07-12T07:26:31Z")

</div>

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

```auto
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'

```

---

<div class="post-metadata">

**Author:** ![lucien](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/lucien/32/2065_2.png) [@lucien](https://discuss.aerospike.com/u/lucien)\
**Post date:** [July 12, 2017, 11:48pm UTC](https://discuss.aerospike.com/t/what-is-the-syntax-to-pass-2d-array-values-to-the-record-udf-using-aql/4378/2 "2017-07-12T23:48:17Z")

</div>

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:

> **[map | Developer](https://developer.aerospike.com/udf/api/map.html)**
>
> The Aerospike map module introduces the Map type and functions to Lua and provides an consistent interface for maps, which is not provided by Lua tables.

and

> **[list | Developer](https://developer.aerospike.com/udf/api/list.html)**
>
> Aerospike's list modules introduce a List type and functions to Lua for a consistent interface for working with a sequence of values, which is not provided by Lua Tables.

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)

```

---

<div class="post-metadata">

**Author:** ![nikhil\_bandal](https://avatars.discourse-cdn.com/v4/letter/n/65b543/32.png) [@nikhil\_bandal](https://discuss.aerospike.com/u/nikhil_bandal)\
**Post date:** [July 13, 2017, 5:31am UTC](https://discuss.aerospike.com/t/what-is-the-syntax-to-pass-2d-array-values-to-the-record-udf-using-aql/4378/3 "2017-07-13T05:31:37Z")

</div>

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](mailto:email%22,%22xyz@gmail.com)”,“T”],[“name”,“abc”,“F”],[“addr”,“pqr”,“T”]]’) on test.emp\_details where PK = ‘1’
