Is udf lua list a sorted list?

Hi.

Please can you confirm that the aerospike udf lua list is not sorted list?

https://www.aerospike.com/docs/udf/api/list.html

For example please can you confirm that the following lua code that adds a list of strings (and removes dups) will not produce a sorted list.

function populate(rec, bin, val)
 local l = rec[bin]
 if l == nil then 
  l = list()
 end
 list.concat(l, val)
 
 local hash = {}
 local res = list()
 for elem in list.iterator(l) do
  if (not hash[elem]) then
   list.append(res, elem)
   hash[elem] = true
  end
 end
    
 rec[bin] = res
 return create_or_update(rec)
end

Thank you for your help

mlabour,

No it will not. if you insert 1,4,2,5,3. List is 1,4,2,5,3 it is NOT 1,2,3,4,5

– R

Hi raj, Thank you for your response. Do you guys plan on adding Set to the datatypes? https://www.aerospike.com/docs/guide/data-types.html Cheers -matthieu

mlabour,

There is map internally implement as hashmap available in lua which can used to store set of items. example set.lua file which implements Redis like API would look something like

function sadd(rec, bin, member)
     set = rec[bin]
     if (set == nil) then
          set = map.new(1)
     end
     
     set[member] = 1
     rec[bin] = set

     if (aerospike:exists(rec)) then
          aerospike:update(rec)
     else
          aerospike:create(rec)
     end
end

function scard(rec, bin)
    set = rec[bin]
    if (set == nil) then
        return 0
    end

    if (type(set) ~= type(map())) then
        return -1
    end
    return #set
end

function sismember(rec, bin, member)
    set = rec[bin]
    if (set == nil) then
        return 0
    end

    if (type(set) ~= type(map())) then
         return 0
    end
    if (not set[member]) then
        return 0
    else
        return 1
    end
end

function sscan(rec, bin, member)
    set = rec[bin]
    if (set == nil) then
        return nil
    end

    if (type(set) ~= type(map())) then
        return nil
    end

    result = list.new(#set)
    for k,v in map.iterator(set) do
        list.append(result, k)
    end
    return result
 end

– R

mlabour,

Ofcourse set may show up in due course but not very soon …

– R