Aerospike NodeJS UDF聚合错误
我创build了一个在AQL中起作用的集合函数:
AGGREGATE filter2.check_teamId('123', 0, 1456499994597) ON analytics.tracking WHERE teamId = '123'
这返回结果。 然后我试图在NodeJS中使用相同的UDF:
var statement = { aggregationUDF: {module: 'filter2', funcname: 'check_teamId', arg:['123', 0, 1456499994597]} }; var query = client.query('analytics', 'tracking', statement); var stream = query.execute();
结果是一个看似无意义的错误:
{ code: 100, message: 'UDF: Execution Error 1', func: 'as_query_aggregate', file: 'src/main/aerospike/aerospike_query.c', line: 903 }
服务器日志状态:
Feb 28 2016 22:33:58 GMT:INFO(扫描):(scan.c :: 933)开始聚合扫描作业1201452721893048027 {analytics:tracking} priority 2
Feb 28 2016 22:33:58 GMT:INFO(扫描):(scan.c :: 1026)完成聚合扫描作业1201452721893048027(0)
有没有人有任何提示让UDF与NodeJS一起工作? 或者有什么想法如何诊断错误?
我已经在configuration中设置了用户UDF位置,不影响结果。
更新:这里是卢阿代码:
local function map_profile(record) return map {interaction=record.interaction, teamId=record.teamId, datetime=record.datetime, timestamp=record.timestamp, version=record.version, interactions=record.interactions} end function check_teamId(stream, teamId, startDate, endDate) local function filter_teamId(record) return record.teamId == teamId and record.timestamp >= startDate and record.timestamp <= endDate end return stream : filter(filter_teamId) : map(map_profile) end
获取UDF执行错误(代码:100)的最可能的原因是LUA子系统的系统和/或用户path未正确设置。 如果打开客户端的debugging日志logging,则可能会看到以下一条或两条错误消息:
Apr 04 2016 08:15:19 UTC: DEBUG(45951) [conversions.cc:248] [config_from_jsobject] - Could not find a valid LUA system path ./aerospike-client-c/package/usr/local/aerospike/client/sys/udf/lua/ Apr 04 2016 08:15:19 UTC: DEBUG(45951) [conversions.cc:273] [config_from_jsobject] - Could not find valid LUA user path ./aerospike-client-c/package/usr/local/aerospike/client/usr/udf/lua
如果客户端无法自动确定正确的path,则必须在configuration中传递系统/用户path。 (见下文。)
但是在Node.js客户端中,您的UDF调用还有另外一个问题。 UDF的参数应该在aggregationUDF
对象的args
元素中传递,而不是在arg
。
这是一个完整的例子,适合我:
const Aerospike = require('aerospike') const config = { hosts: '192.168.33.10:3000', log: { level: 5 }, modlua: { userPath: './', systemPath: './node_modules/aerospike/aerospike-client-c/lua/' } } Aerospike.connect(config, (error, client) => { if (error) throw error var statement = { aggregationUDF: { module: 'agg', funcname: 'check_teamId', args: ['123', 0, 1456499994597] } } var query = client.query('test', 'tracking', statement) var stream = query.execute() var count = 0 stream.on('error', (error) => console.error('error:', error)) stream.on('data', (result) => { count++ console.log('result:', result) }) stream.on('end', () => { console.log('found %d records', count) client.close() }) })
请注意,此示例使用刚发布的aerospike@2.0.0-alpha.1
客户端版本。 但是,UDF查询的设置和执行与v1.x客户端完全相同。
我也在这里上传了这个例子到Github。 这个Gist还包括一个setup.js
脚本,根据你的map_profile
函数的预期来创build一些示例logging。
请在我们的用户论坛上随时关注此事。 我很想听听你是否有这个工作,为您的应用程序。 (或者有关Aerospike Node.js客户端的其他反馈!)