UDF aggregation error in NodeJS aerodynamics

I created an aggregate function that works in an aerosystem that works in AQL:

AGGREGATE filter2.check_teamId('123', 0, 1456499994597) ON analytics.tracking WHERE teamId = '123' 

This returns the results. Then I try to use the same UDF in NodeJS:

 var statement = { aggregationUDF: {module: 'filter2', funcname: 'check_teamId', arg:['123', 0, 1456499994597]} }; var query = client.query('analytics', 'tracking', statement); var stream = query.execute(); 

The result is a seemingly uninformative error:

 { code: 100, message: 'UDF: Execution Error 1', func: 'as_query_aggregate', file: 'src/main/aerospike/aerospike_query.c', line: 903 } 

Server Log Status:

February 28, 2016 22:33:58 GMT: INFO (scan): (scan.c :: 933), starting the aggregation task 1201452721893048027 {analytics: tracking} priority 2

February 28, 2016 22:33:58 GMT: INFO (scan): (scan.c :: 1026) completed aggregation scan job 1201452721893048027 (0)

Does anyone have any tips on getting UDF to work with NodeJS? Or any ideas how to diagnose a bug?

I set the UDF user location in the config, which does not affect the result.

UPDATE: Here is the lua code:

 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 
+5
source share
1 answer

The most likely reason you get a UDF runtime error (code: 100) is because the system and / or user path for the LUA subsystem is not configured correctly. If you enable debug logging for the client, you will see one or both of these error messages:

 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 

If the client cannot determine the correct path automatically, you need to transfer the path to the system / user in the configuration. (See below.)

But there is another problem with your UDF call in the Node.js client. Arguments for UDF must be passed in the args element of the aggregationUDF , not arg .

Here is a complete example that works for me:

 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() }) }) 

Note that this example uses the client version of aerospike@2.0.0-alpha.1 , which was just released . But setting up and running the UDF request is identical to the v1.x client.

I also added this example to Github here . This Gist also includes a setup.js script to create some sample entries based on the expected map_profile function.

Feel free to follow this in our user forum , I would love to hear if you have this to work on your application. (Or any other Aerospike Node.js customer reviews!)

+3
source

Source: https://habr.com/ru/post/1244069/


All Articles