Aerospike:update(r) doesn’t work in UDF

Database record is not updated

   function updateMap(r,a,b,c)
      if not aerospike:exists(r) then 
        local ret = map()
        ret['status'] = 'DOES NOT EXIST'
        return ret
      end

      if r.void2 == nil then
        r.void2 = map()
      end

      if r.void2[a] == nil then
        r.void2[a] = map()
      end

      if r.void2[a][b] == nil then
        r.void2[a][b] = map()
      end

      if r.void2[a][b][c] == nil then
        r.void2[a][b][c] = list{1, os.time(os.date("!*t"))}
        return r.void2[a]
      end

      r.void2[a][b][c][1] = r.void2[a][b][c][1] + 1
      r.void2[a][b][c][2] = os.time(os.date("!*t"))

      aerospike:update(r)
      return r.void2[a]
    end

execute example.updateMap(‘55’,‘540’,‘30’) on test.testing where PK=‘xyz’

+---------------------------------------+
| updateMap                             |
+---------------------------------------+
| MAP('{"540":{"30":[2, 1620664860]}}') |
+---------------------------------------+
1 row in set (0.001 secs)

One of my colleagues mentioned (and verified) that cloning the map does the trick to have it updated in a UDF:

r.void2 = map.clone(r.void2)
aerospike:update(r)

Having said that, I also did get feedback on the fact that you may be able to do similar things directly with CDT operations, without the need of a UDF, which would be more efficient.

1 Like
© 2021 Copyright Aerospike, Inc. | All rights reserved. Creators of the Aerospike Database.