# UDF stream time series

**URL:** <https://discuss.aerospike.com/t/udf-stream-time-series/2071>\
**Category:** User Defined Functions (UDF)\
**Created:** [November 4, 2015, 5:23am UTC](https://discuss.aerospike.com/t/udf-stream-time-series/2071 "2015-11-04T05:23:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![styles](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/styles/32/400_2.png) [@styles](https://discuss.aerospike.com/u/styles)\
**Post date:** [November 4, 2015, 5:23am UTC](https://discuss.aerospike.com/t/udf-stream-time-series/2071/1 "2015-11-04T05:23:32Z")

</div>

I’m trying to break down how many interactions happen every minute. I have the following UDF. The issue is the reduce doesn’t seem to merge all the values. I get multiple results with the same keys. I’m unsure if it’s how I wrote this or if the time calculated isn’t accurate.

> local function toMinutes(time) return time - (time % 60000000000) end
> 
> local function add\_values(impMap, nextImp) local time = toMinutes(nextImp[“created”])
> 
> ```
> debug("time is %s", time)
> 
> local timeSet = impMap[time]
> 
> if timeSet == null then
> timeSet = map { count = 0 }
> end
> 
> ```
> 
> timeSet.count = timeSet.count + 1
> 
> ```
> impMap[time] = timeSet
> return impMap end
> 
> ```
> 
> local function merge(a, b) a.count = a.count + b.count return a end
> 
> local function reduce\_values(a, b) return map.merge(a, b, merge) end
> 
> function per\_minute(stream) return stream : aggregate(map(), add\_values) : reduce(reduce\_values) end

---

<div class="post-metadata">

**Author:** ![styles](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/styles/32/400_2.png) [@styles](https://discuss.aerospike.com/u/styles)\
**Post date:** [November 4, 2015, 6:56pm UTC](https://discuss.aerospike.com/t/udf-stream-time-series/2071/2 "2015-11-04T18:56:52Z")

</div>

I’ve been able to narrow it down to the reduce function not running. I get all my other debug messages but the reduce I’m doign this via AQL’s command line:

AGGREGATE imps-per-min.impressions\_per\_minute() on adserver.impressions WHERE created BETWEEN 1446611475911403870 AND 1446612075911403870
