Execution Error 2 and Failed Logging

Hi. I’m writing an aggregate UDF which I had originally working but seems to no longer work. The UDF code is below and the error message but one other issue I am having is the logging is not working either.

local function secondary_filter(bin_name, operator, value)
    return function(rec)
        if operator == '<' then
            if rec[bin_name] < value then
                return true
            end
        elseif operator == '=' then
            if rec[bin_name] == value then
                return true
            end
        elseif operator == '>' then
            if rec[bin_name] > value then
                return true
            end
        end
        return false
    end
end

local function countRequests(group_by_bin)
    return function(group, rec)
        -- Work out Total Statistics:
        group['total'] = (group['total'] or 0) + 1

        -- Count the amount of "field name" elements:
        if rec[group_by_bin] then
            local bin_name = rec[group_by_bin]
            group[bin_name] = (group[bin_name] or 0) + 1
        end
        return group
    end
end

-- /*
-- |----------------------------------------------------------------------------------------
-- | MAIN FUNCTIONS
-- |----------------------------------------------------------------------------------------
-- */

function group_by(stream, group_by_bin, filter_bin_name, filter_operator, filter_value)
    info("bollocks")
    if filter_bin_name and filter_operator and filter_value then
        local myfilter = secondary_filter(filter_bin_name, filter_operator, filter_value)
        return stream:filter(myfilter):aggregate(map {}, countRequests(group_by_bin)):reduce(reduce_groups)
    else
        return stream:aggregate(map {}, countRequests(group_by_bin)):reduce(reduce_groups)
    end
end

error message:

An error occurred while querying [100] UDF: Execution Error 2 : /opt/aerospike/client-php/sys-lua/stream_ops.lua:144: attempt to call upvalue 'f' (a nil value)

and as you can see, in it I have a logging function but it’s not outputting anything to the error log, despite all of the logging contexts being set accordingly.

any thoughts?

You’re missing your reducer, and the problem is probably there. Please add it, and I’ll check.

1 Like

GAH!! Thanks Ronen (for sorting my formatting firstly) and for pointing me in the right direction - I don’t know how I missed that! For some reason my reducer had been removed from the file - put it back in and boosh, we’re good to go - thanks mate!

Easiest discussion forum solution, yet. :sunglasses: