Large Ordered List Unique Key Bug


#1

I am inserting a map datatype into a Large Ordered List in a LUA function, the map has a field named ‘key’, so by default this should theoretically be picked up and used as the key field.

This sequence of aql commands illustrates the problem:

aql> insert into test.demo (PK, bin) values ('key', 'value')
OK, 1 record affected.

aql> execute llist.add('mylist','JSON{"key":12345,"value":"item"}') on test.demo where PK='key'
+-----+
| add |
+-----+
| 0   |
+-----+
1 row in set (0.000 secs)

aql> execute llist.scan('mylist') on test.demo where PK='key'
+---------------------------------+
| scan                            |
+---------------------------------+
| [{"value":"item", "key":12345}] |
+---------------------------------+
1 row in set (0.000 secs)

aql> execute llist.range('mylist', 12345, 12345) on test.demo where PK='key'
+---------------------------------+
| range                           |
+---------------------------------+
| [{"value":"item", "key":12345}] |
+---------------------------------+
1 row in set (0.000 secs)

aql> execute llist.find('mylist', 12345) on test.demo where PK='key'
Error: (100) /opt/aerospike/sys/udf/lua/ldt/lib_llist.lua:1347: 1433:LDT-Key (Unique) Function Not Found

aql> execute llist.remove('mylist', 12345) on test.demo where PK='key'
Error: (100) /opt/aerospike/sys/udf/lua/ldt/lib_llist.lua:1347: 1433:LDT-Key (Unique) Function Not Found

So from the above, you can see llist.range works as expected and the ‘key’ field is extracted correctly, but the llist.find and llist.remove commands do not work as expected.

I am developing on OS X with your vagrant Aerospike Community Edition build 3.4.1 image.


#2

memunix,

Acknowledged. This is inconsistency between how the key is picked in API. Thanks for reporting, this will be fixed !! Work around for now would be

aql > execute llist.find('mylist', 'JSON{"key":12345}') on test.demo where PK='key'

aql> execute llist.remove('mylist', 'JSON{"key":12345}'} on test.demo where PK='key'

Thanks

– Raj


#3

Great, thanks for your help Raj.

Your workaround works perfectly in AQL, but I am actually working in a LUA module where it does not appear to work i.e. this throws the same error:

local keyJSON = 'JSON{"key":12345}'
local status = llist.remove(rec, "mylist", keyJSON)

I presume this is because the key is being taken literally rather than the JSON being parsed.

Perhaps I need to specify an explicit Key extraction function in a ‘userModule’ to ensure this works correctly prior to the bugfix or is there another workaround you can think of?


#4

Use

 local searchMap  = map();
 searchMap["key"] = 12345;
 local status = llist.remove(rec, "mylist", searchMap);

This should work for you.

In lua world you can use map itself. No need for JSON circus :smile:

HTH

– Raj


#5

Works perfectly thank you Raj !


#6

@memunix,

Thank you for posting about LDTs in our forum. Please see the LDT Feature Guide for current LDT recommendations and best practices.


#7

@memunix,

Effective immediately, we will no longer actively support the LDT feature and will eventually remove the API. The exact deprecation and removal timeline will depend on customer and community requirements. Instead of LDTs, we advise that you use our newer List and SortedMap APIs, which are now available in all Aerospike-supported clients at the General Availability level. Read our blog post for details.