as lmap doesn’t have a “exists” or “contains_key” function, I tried to do it on my own to check the existing key before certain operation. The code is as follows:
function testPut(rec, key, val)
local lmap = require('ldt/lib_lmap')
if rec['_map']~=null and pcall(function() return lmap.get(rec,'_map',key)~=nil end) then
info("testPut() - old: %s", tostring(lmap.get(rec,'_map',key)))
lmap.put(rec,'_map',key,val)
else
lmap.put(rec,'_map',key,val)
end
end
Then invoke it as follows:
execute testModule.testPut('a',1) on test.map where pk ='_'
execute lmap.scan('_map') on test.map where pk ='_'
execute testModule.testPut('a',2) on test.map where pk ='_'
execute lmap.scan('_map') on test.map where pk ='_'
execute testModule.testPut('a',3) on test.map where pk ='_'
execute lmap.scan('_map') on test.map where pk ='_'
The lmap.scan indicate data are stored correctly, the value is updated from 1 to 2 to 3.
However, the info log files that is run in the 2nd and 3rd testPut() are as follows:
testPut() - old: {"a":1}
testPut() - old: {"a":1}
the first one is correct as it changed from 1 to 2, it print out old as 1. However, for the 3rd invoke/2nd info log, the old value remains as 1. And any subsequent invoke will never change the old value.
Is it a bug that the data is cached somewhere in the Lua engine?