Hi every body, I need to get all record between 2 value, so I find some example to using UDF like this:
local function range_filter(bin_name, substr_from, substr_to)
return function(record)
local val = record[bin_name]
if type(val) ~= 'string' then
return false
end
if val >= substr_from and val <= substr_to then
return true
else
return false
end
end
end
local function rec_to_map(record)
info(record.bin_names())
local xrec = map()
for i, bin_name in ipairs(record.bin_names(record)) do
xrec[bin_name] = xrec[bin_name]
end
return xrec
end
function str_between(stream, bin_name, substr_from, substr_to)
return stream:filter(range_filter(bin_name, substr_from, substr_to)):map(rec_to_map)
end
My data like this:
±-----------±-----±----±----------+ | datetime | code | age | address | ±-----------±-----±----±----------+ | 1480641211 | 18 | 2 | “80 abc” | | 1480641212 | 76 | 2 | “86 abc” | | 1480641211 | 7 | 2 | “4 abc” | | 1480641211 | 37 | 2 | “26 abc” | | 1480641211 | 91 | 2 | “5 abc” | | 1480641211 | 81 | 5 | “17 abc” | ±-----------±-----±----±----------+
When I try to run code of Go like this:
luaPath, _ := os.Getwd()
luaPath += "/queries/udf/"
as.SetLuaPath(luaPath)
filename := "range_filter"
regTask, err := client.RegisterUDFFromFile(nil, luaPath + filename + ".lua", filename + ".lua", as.LUA)
configs.PanicOnError(err)
configs.PanicOnError(<-regTask.OnComplete())
stm := as.NewStatement(input.DefaultNamespace, input.DefaultSet)
res, err := client.QueryAggregate(nil, stm, filename, "str_between", "age", 1, 100)
configs.PanicOnError(err)
vl := <-res.Results()
fmt.Println(vl);
But rserver serospike trurn data is nil. Some body help me! Thanks