User Defined Aggregates


I am wanting to develop some user Defined Aggregates, and I read in the documentation that it is something that you are planning on implementing.

  1. is it implemented now?
    a) if yes, is there documentation/examples for creating them? or some advice on how to do it?
    b) if no, what advice can be offered if I wanted to add this functionality? What code should I look at?

Thank you,


Hi Alan,

Glad you asked. I did some work in this area.
In 11.06 there is no notion of an “aggregate” as a separate structure. There are only “operators” which accept an array and return another array. There are, of course, ops like sum() and avg() that take an array and return a single value - so you could call those aggregates.

In the upcoming release (what used to be 11.10 and is now likely going to be 11.12 :smile:) we actually treat aggregates as a separate class of objects and allow them to be user defined. We then create higher-level ops that apply aggregates to arrays in various ways. Here are some examples out of 11.12:

AFL% show(test_arr);
[("test_arr<val:int64 NOT NULL> [y=1:4,4,0,x=1:4,4,0]")]
AFL% scan(test_arr);

--These few aggregates come canned with the system:
AFL% list('aggregates');

-- Here are various ops that apply aggregates:
AFL% aggregate(test_arr, sum(val));

-- group by dimension:
AFL% aggregate(test_arr, sum(val), x);
AFL% aggregate(test_arr, sum(val), y);

-- regrid:
AFL% regrid(test_arr, 2, 2, sum(val));

-- window:
AFL% window(test_arr, 2, 2, sum(val));

-- redimension (the cool stuff) - this query calculates sum of even and odd numbers in the array:
AFL% redimension( apply( test_arr, even_or_odd, iif(val % 2 = 0, 1, 0)), <vsum:int64 null, empty_tag:indicator> [even_or_odd=0:1,1,0], sum(val) as vsum);

So if you can wait for 11.12 to come out, which should be pretty soon, you can pretty easily add your own aggs (like sum) to the mix. Or you can always define your own operators to do the job as well.

Hope it helps.


Just a follow up on this.
Looks like the new way of making aggregates have been implemented long time ago. Is there any documentation on how to make a new aggregate?




Doc is currently overloaded and the UDA API is still fluid. The best I can give you at the moment is a toy example - see: viewtopic.php?f=18&t=1122