尝试调用方法“map”(一个空值),Aerospike UDF 出现错误。

我的 Lua 代码来自于官方网站的例子:

local function one(rec) 
    info("lalalalal %s",rec['id']) 
    return 1 
end 
local function add(a, b) 
    return a + b 
end 
function mycount(stream) 
    return stream : map(one) : reduce(add); 
end 

当我使用 aql 命令时:

在日志中会报错,如下所示:

May 20 2015 07:12:07 GMT: DEBUG (udf): (udf_rw.c:send_result:515) FAILURE when calling stream_udf mycount /opt/aerospike/usr/udf/lua/stream_udf.lua:10: attempt to call method 'map' (a nil value) May 20 2015 07:12:07 GMT: DEBUG (udf): (udf_rw.c:send_udf_failure:403) Non-special LDT or General UDF Error(/opt/aerospike/usr/udf/lua/stream_udf.lua:10: attempt to call method 'map' (a nil value))

如何解决它? 谢谢

点赞
用户582436
用户582436

那是 Lua 的一个问题,它不会自动将 nil 转换为字符串,而像 print 和 info() 这样的函数则期望该类型。将您的行更改为

info("lalalalal  %s", tostring(rec['id']))
2015-05-21 17:07:24