# Execution Error 2 and Failed Logging

**URL:** <https://discuss.aerospike.com/t/execution-error-2-and-failed-logging/2876>\
**Category:** User Defined Functions (UDF)\
**Created:** [April 27, 2016, 1:40pm UTC](https://discuss.aerospike.com/t/execution-error-2-and-failed-logging/2876 "2016-04-27T13:40:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Crags](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/crags/32/309_2.png) [@Crags](https://discuss.aerospike.com/u/Crags)\
**Post date:** [April 27, 2016, 1:40pm UTC](https://discuss.aerospike.com/t/execution-error-2-and-failed-logging/2876/1 "2016-04-27T13:40:54Z")

</div>

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.

```nohighlight
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?

---

<div class="post-metadata">

**Author:** ![rbotzer](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/rbotzer/32/2114_2.png) [@rbotzer](https://discuss.aerospike.com/u/rbotzer)\
**Post date:** [April 27, 2016, 1:56pm UTC](https://discuss.aerospike.com/t/execution-error-2-and-failed-logging/2876/2 "2016-04-27T13:56:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Crags](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/crags/32/309_2.png) [@Crags](https://discuss.aerospike.com/u/Crags)\
**Post date:** [April 27, 2016, 1:58pm UTC](https://discuss.aerospike.com/t/execution-error-2-and-failed-logging/2876/3 "2016-04-27T13:58:51Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![rbotzer](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/rbotzer/32/2114_2.png) [@rbotzer](https://discuss.aerospike.com/u/rbotzer)\
**Post date:** [April 27, 2016, 2:17pm UTC](https://discuss.aerospike.com/t/execution-error-2-and-failed-logging/2876/4 "2016-04-27T14:17:07Z")

</div>

Easiest discussion forum solution, yet. 🕶
