on 01-03-2011 3:17 PM
Hi Experts,
I have a source message structure as below
<Node>
<element1>1</element1>
<element2>33</element2>
<element3>43</element3>
</Node>
<Node>
<element1>2</element1>
<element2>35</element2>
</Node>
<Node>
<element1>3</element1>
<element2>34</element2>
</Node>
Target Is as below
<Node>
<element1>value</element1>
</Node>
Where value has to be 123 (value in each occurence)
Can this be done by standard functions?? do I have to use a UDF? queue or context??
Pls share ur thoughts
Edited by: Ravindra Teja on Jan 3, 2011 4:17 PM
Edited by: Ravindra Teja on Jan 3, 2011 4:20 PM
This is very simple & could be done using standard functions itself.
-
Srikanth Srinivasan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Ravindra,
You can achive this by using standard functions also. Use arithmatic function "add" and also change the context of Source node to the topmost node, so that it will appeare as a single queue. The function will add all the values in the queue.
Thanks,
Sunil Singh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
>>>> Where value has to be 123 (value in each occurence)
>>>> Can this be done by standard functions?? do I have to use a UDF? queue or context??
Please go through this link ... I already answered here....
If you dont want decimal in your value then use just below code...
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();
}
}
result.addValue(new String().valueOf(sum));}
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 |
---|---|
87 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.