Distinct rows in multi-attribute 1-dim array


#1

Hi everybody,

I would like to get only the distinct rows in a multi-attribute one-dimensional array, whereas the original array looks like this:

{0} ‘p1ws1’,‘ws1’
{1} ‘p1ws1’,‘ws1’
{2} ‘p1ws1’,‘ws1’
{3} ‘p2ws1’,‘ws1’
{4} ‘p2ws1’,‘ws1’
{5} ‘p2ws1’,‘ws1’
{6} ‘p3ws1’,‘ws1’
{7} ‘p3ws1’,‘ws1’
{8} ‘p3ws1’,‘ws1’

…and the final array should look like this:

{0} ‘p1ws1’,‘ws1’
{1} ‘p2ws1’,‘ws1’
{2} ‘p3ws1’,‘ws1’

I have seen that there is the uniq operator, however it only works on single attribute arrays. Can anybody help me with this?

Thank you!
-Ivan


#2

One way to do it is with grouped_aggregate:

grouped_aggregate(input, count(*), attribute1, attribute2)

#3

That worked for me.
I now stored the the results in a new 1-dimensional array (without the ‘count attribute’ as follows:
store(project(unpack(grouped_aggregate(inputArray, count(*), attr1, attr2),i),attr1,attr2),outputArray);

Thanks a lot,
-Ivan