Projection non-aggregate dimension of Aggregate Query


#1

Hi,

Suppose that I have a simple array

and that I want to compute the minimum value, group by dimension i. However, I want to return not only the minimum value, but also the j’s dimension that correspond to that minimum, so something like

although obviously this isn’t working since j is not an aggregate. Does any know of a clever way to do this in scidb?

Thank you,
Khoa


#2

Hi Khoa,

We consider this a case of “multi-argument aggregation” - something that’s on the roadmap but not in place yet. At the moment there are two ways to do this - the stock slow way and the UDA fast way:

  1. The slow way:
filter( cross_join(a1 as A, aggregate(a1, min(val) as mv, i) as B, A.i, B.i), A.val = B.mv)

The added bonus is that you get all j for which val = mv. But other than that, this is a 2N pass over the data; slower than it needs to be.

  1. The fast way is to write a custom UDA that does the job over, say, a string that stores a cast value,j pair:
aggregate( apply(a1, vj, string(val)+'_'+string(j) ), myMin(vj), i)

If you want to go this route, you can check out this example: viewtopic.php?f=18&t=1122
Make sense?
-Alex Poliakov