How to apply udf modules


#1

which software we need to run lua modules for aerospike python client. how to debug

Exception: (100L, "/opt/aerospike/usr/udf/lua/pooja.lua:3: bad argument #1 to 'append' (userdata expected, got string)", 'src/main/aerospike/as_command.c', 730)

#2

That message means that there’s a bug in your Lua code. Please provide a sample of your code.


#3
function list_append(rec, bin, value)
  local l = rec[bin]
  list.append(l, value)
  rec[bin] = l
  aerospike:update(rec)
  return 0
end

this is my lua code


#4

Hi Pooja,

The error message you’re seeing will come up whenever you try to perform list operations on a bin holding a value that is not a list. I’m starting out with a new record that has three bins, two hold integer values and one holds a list:

aql> select * from test.demo where PK='key2'
+---+----+----------+
| b | id | z        |
+---+----+----------+
| 2 | 2  | ["z", 2] |
+---+----+----------+
1 row in set (0.000 secs)

I call your script on the bin ‘z’ once:

client.apply(('test','demo','key2'), 'x', 'list_append', ['z',4])

Which results in:

aql> select * from test.demo where PK='key2'
+---+----+-------------+
| b | id | z           |
+---+----+-------------+
| 2 | 2  | ["z", 2, 4] |
+---+----+-------------+
1 row in set (0.000 secs)

Now I’ll try to invoke append_list on bin ‘b’ which is an integer:

client.apply(('test','demo','key2'), 'x', 'list_append', ['b',5])

And the following error is triggered:

Error (100L, "/opt/aerospike/usr/udf/lua/x.lua:3: bad argument #1 to 'append' (userdata expected, got number)", 'src/main/aerospike/as_command.c', 731)

So, I suggest adding a test for whether the operation is safe to perform inside the Lua module:

function list_append(rec, bin, value)
    local l = rec[bin]
    if type(l) == 'number' or type(l) == 'string' then
        return nil
    end
    if (tostring(getmetatable(rec[bin])) == tostring(getmetatable(list()))) then
        list.append(l, value)
        rec[bin] = l
        aerospike:update(rec)
        return l
    end
    return nil
end