on 12-17-2010 4:42 PM
Hi All,
could any1 plz send me the udf that will calculate the sum of a column in the incoming file. plz do not give any reference to blogs/forum. I have gone through all. we cannot go for the SP 18 upgrade now. so looking for a workaround till then as the standard function --SUM has a bug summing all values with decimals.
i have checked the bolg forum below also, got few hints but did not help.
/people/thorsten.nordholmsbirk/blog/2006/04/03/never-ever-use-xis-built-in-arithmetic-functions
thanks.
rajib
Please do the following. Here is the UDF. This will count all the values of context.
public void sumValue(ResultList result, String[] value, Container container) throws StreamTransformationException{
double sum = 0.0;
for(int count =0; count<value.length; count++){
if(value[count]!=null && value[count].length() > 0){
sum = sum + new Double(value[count]).doubleValue();
}
}
BigDecimal bd1 = new BigDecimal(sum);
BigDecimal bd2 = bd1.setScale(2, BigDecimal.ROUND_HALF_DOWN);
result.addValue(bd2.toString());
}
Dont forget to add import statements
java.math.*
java.lang.*
This UDF takes care even if the input file misses value on the input side ....
Note: use square bracket before and after [count] in if block. This editor deleting it.
Baskar
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.