Calculate row Sum.
Hi!
I wrote UDScalar Function on C++ if any one need to calculate sum of row.
Any feedback would be greatly appreciated!
Exmaple
Data:
daniel=> select * from eldj ; col | m01 | m02 | m03 | m04 | m05 ------+-----+-----+-----+-----+----- key1 | 0 | 0 | 1 | 0 | 0 key2 | 1 | 1 | 0 | 1 | 1 key3 | 0 | 0 | 0 | 0 | 1 key4 | 0 | 0 | 1 | 1 | 1 key5 | 1 | 1 | 0 | 0 | 0 key6 | 0 | 1 | 0 | 0 | 0 (6 rows)
Usage:
daniel=> select col, rowsum(* using parameters exclude='col') as 'SUM_TRUE' from eldj; col | SUM_TRUE ------+---------- key1 | 1 key2 | 4 key3 | 1 key4 | 3 key5 | 2 key6 | 1 (6 rows)
0
Comments
I would try to move the exclude check into the setup() function - compute the column indexes to ignore in the processBlock function. That way you avoid string comparison for every row/column.
Hi @Ben_Vandiver!
I wanted to do it, but if nobody needs it then I'm not going to invest in it.
So far its just a concept, there are a couple things I need to do:
^C
should work fine in this case)Thnx for your feedback.
Thanks for sharing this @sKwa!