Hi Raj,
Thanks for the reply. It really helped me to move forward. But now I am facing new problem with llist and map.
Here are the details:
As per your description above, if I have to add value {“a”: 10}, then I have to insert {“key”: “a”, “a”:10} into LLIST. To do this I have added below C code and it works fine:
as_error err;
as_error_reset(&err);
as_hashmap map;
as_map *m = (as_map *)as_hashmap_init(&map, 2);
as_stringmap_set_str(m, "key", "a");
as_stringmap_set_int64(m, "a", "10");
as_ldt llist;
as_ldt_init(&llist, "myllist", AS_LDT_LLIST, NULL)
aerospike_llist_add(&as, &err, NULL, &reckey, &llist, (as_val *)m);
This ({“a”: “10”}) map is successfully inserted to LLIST. I verified it using aql tool. If I do the llist.find(‘myllist’, ‘a’), then I get the map.
Now I have multiple such maps which I want to insert into LLIST.
Eg. [{“k1”: 1}, {“k2”: 2}, {“k3”: 3}…{“kn”: n}]
To add these map entries into LLIST I have to create below map structure:
[{“key”: “k1”, “k1”: 1}, {“key”: “k2”, “k2”: 2}, {“key”: “k3”, “k3”: 3}…{“key”: “kn”, “kn”: n}]
I have added below C code to do this:
as_error err;
as_error_reset(&err);
map_array[n] // This is my map array which is properly initialized with unique key and value
as_arraylist vals;
as_arraylist_inita(&vals, n);
for(int k = 0; k < n; ++k) {
as_hashmap map1;
as_map *m1 = (as_map *)as_hashmap_init(&map1, (2));
as_stringmap_set_str(m1, "key", map_array[k].key);
as_stringmap_set_int64(m1, map_array[k].key, map_array[k].value);
as_arraylist_append_map(&vals, m1);
}
if (aerospike_llist_add_all(&as, &err, NULL, &reckey, &llist, (as_list *)&vals) != AEROSPIKE_OK)
{
printf("aerospike_llist_add_all() returned %d - %s", err.code, err.message);
}
Ideally this code should insert all the map values to LLIST, but it fails with error message:
aerospike_llist_add_all() returned 100 - /opt/aerospike/sys/udf/lua/ldt/lib_llist.lua:5528: 1402:LDT-Unique Key or Value Violation
If I do single map add at time using aerospike_llist_add() then it works fine for all the map entries. But it will be performance hit to do it one by one. I want to do it in a single call to Aerospike Server
Can you please tell me why this error message is coming ? Or am I missing anything here? Or tell me the right way to do it.