Can someone help me to make query with multiple filters but return entire stream and not only the first result?
In UDF lua file i apply a filter function and a map function, but the result is only one not multiple.
Thank you
Can someone help me to make query with multiple filters but return entire stream and not only the first result?
In UDF lua file i apply a filter function and a map function, but the result is only one not multiple.
Thank you
@sticeap Can you provide a code snippet on what it is that you are trying, and what are your expected results?
Yes, here is the code from UDF file.
local function filterBySecondBin(key, value)
return function(rec)
local val = rec[key]
if val == value then
return true
else
return false
end
end
end
local function mapper(record)
return map {
userId = record.userId,
companyId = record.companyId
}
end
function getUsers(stream, key, value)
local myfilter = filterBySecondBin(key, value)
return stream : filter(myfilter) : map(mapper)
end
I tried to made a query and filter results by range from Aerospike filter and by companyId as a second filter from UDF.
Thank you
Currently you are returning one map{userId=xx, companyId=yy}. You need to aggregate into a list and then reduce. See this example below of a single property map:
local function collect_tweets(tweetsMap,rec)
list.append(tweetsMap.tweets,rec.tweet)
return tweetsMap
end
local function merge_tweets(a,b)
a.tweets = a.tweets + b.tweets
return a
end
function recent_tweets(stream)
return stream : aggregate(map{tweets=list()},collect_tweets) : reduce(merge_tweets)
end
Also, if you are testing on a multi-node cluster, final reduce happens on the client node. Read this for more info. Another UDF Error 100 debugging - #3 by ofiedler