I have a problem with my UDF lua file when I trying to compare 2 strings(one from record and another one from arguments). If I declare 2 variables and compare it I will get true as a result, but when I want to compare for example record[key] == value(where key and value are received as arguments, I get false)
From the info() when I are 2 identical strings, result of comparison is false.
Thank you very much
Here is my code:
local function my_email_filter(key, value)
return function(record)
info('RESULT is %s and %s', record[key] == value )
info('%s | %s', record[key], value)
if record[key] == value then
return true
else
return false
end
end
end
local function mapper(record)
local out = map()
out['email'] = record['email']
out['userId'] = record['userId']
return out
end
function count(stream, key, email)
local myfilter = my_email_filter(key, email)
return stream : filter(myfilter) : map(mapper)
end
I typically put my filter function inside the main function i am calling so i can pass my arguments to it without changing the signature of the filter function. If I recall, API says filter function can be passed only one argument - the record. So keen to know if your construct works.
I tried what you said but, in that info() call I have those strings identically. I change my function to this, and I have the same results. Stored bins of type string should convert to something or ? Result of the info(rec[key]) and info(email) are the same and evaluation of that is false.
local function mapper(record)
local out = map()
out['email'] = record['email']
out['userId'] = record['userId']
return out
end
function count(stream, key, email)
local function my_email_filter(rec)
if type(rec[key]) ~= 'string' then
return false
end
info('RESULT is %s', rec[key] == email )
info('%s | %s', rec[key], email)
if rec[key] == email then
return true
else
return false
end
end
return stream : filter(my_email_filter) : map(mapper)
end
Thank you very much for your effort.
It’s seems that problems comes from email because it’s contains non alpha chars like paul+test@gmail.com
I didn’t have a solution how to handle this type of strings to compare if it’s equals. if i look for paul@gmail.com it will compare as string but when I tried to look for paul+test@gmail.com it’s fail.