on 12-21-2011 12:41 PM
Hi,
Can i remove duplicate values from a queu, but still keep the existing context changes?
Is it possible with graphical mapping (node functions) to go from this queue
<null>
[aaaa]
[aaaa]
[aaaa]
[aaaa]
[bbbb]
[bbbb]
[bbbb]
[contextchange]
[cccc]
[cccc]
[dddd]
[dddd]
[dddd]
[dddd]
[contextchange]
[eeee]
[eeee]
END OF QUEUE
to this queu:
<null>
[aaaa]
[bbbb]
[contextchange]
[cccc]
[dddd]
[contextchange]
[eeee]
END OF QUEUE
The number of times that a value occurs is variable, as is the number of values within a context, as is the number of context changes in the queue.
So, once more, question is how to remove the duplicates while keeping the context changes as they are.
Thx for advice
Kr
Robert
Hi,
It'll be little difficult removing duplicates and keeping the context as it is with exixting standard functions. Removing duplicates irrespective of context changes, we can do with available functions. Please try with this UDF code which may help you...
source>sort>UDF-->Target
execution type of UDF is Allvalues of a context.
public void UDF(String[] var1, ResultList result, Container container) throws StreamTransformationException{
ArrayList aList = new ArrayList();
aList.add(var1(0));
result.addValue(var1(0));
for(int i=1; i<var1.length; i++){
if(aList.contains(var1(i)))
continue;
else{
aList.add(var1(i));
result.addValue(var1(i));
}
}
}
Regards,
Priyanka
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try this.
public void UDF(String[] a, ResultList result, Container container) {
String b = "";
b = a[0];
result.addValue(a[0]);
for(int i=1; i<a.length; i++){
if(a(i).equals(b))
continue;
else{
b = a(i);
result.addValue(a(i));
}
}
}
Replace a(i) with square brackets.
Edited by: VaasPal on Dec 21, 2011 2:44 PM
use HashSet ..as it contains only unique values...
execution type: All values of a context..
Input will be var1
// duplicate values will get deleted
Set hashSet = new HashSet(Arrays.asList(var1));
String[] var2 = (String[]) hashSet.toArray(new String[hashSet.size()]);
Arrays.sort(var2);
for (int i = 0; i < var2.length; i++)
result.addValue(var2<i>);
http://forums.sdn.sap.com/thread.jspa?threadID=2009591&tstart=0
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi.
just one observation about Amitsri solution .
Becareful with HashSet implementation because as said on java documentation :
+ It makes no guarantees as to the iteration order of the set; in particular, it does not guarantee that the order will remain constant over time.+
http://docs.oracle.com/javase/6/docs/api/java/util/HashSet.html
Regards.
>So, once more, question is how to remove the duplicates while keeping the context changes as they are.
Use standard node function splitbyvalue (value change).
http://help.sap.com/saphelp_dimp50/helpdata/en/21/3bb8c495125e4eb5969f0377885fe0/content.htm
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
@bhavanisankar:
your solution gave the following queue
<null>
[aaaa]
[contextchange]
[bbbb]
[contextchange]
[cccc]
[contextchange]
[dddd]
[contextchange]
[eeee]
[end of queue]
@baskar:
your solution doesn't remove the duplicate values from the queue, it only adds contextchanges after a change in value.
kr
RObert
hi ,
question is how to remove the duplicates while keeping the context changes as they are.
try this below logic
Source field -> remove context -> sort-> split by value (value change) -> colapsecontext -> split by value (each value) -> target field
thanks,
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 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
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.