on 09-15-2015 3:09 AM
Hi,
We have a source and target structure of same format like below.
<item>
<key></key>
<Value><Value>
</item>
But while mapping to target. The Value field after first occurrence of key ZZ. Should be sent as X. Help to advice in achieving this.
Ex: Source Structure
<item>
<key>10</key>
<Value>2<Value>
</item>
<item>
<key>10</key>
<Value>2<Value>
</item>
<item>
<key>ZZ</key>
<Value>2<Value>
</item>
<item>
<key>10</key>
<Value>2<Value>
</item>
<key>10</key>
<Value>2<Value>
</item>
Target Structure
<item>
<key>10</key>
<Value>2<Value>
</item>
<item>
<key>10</key>
<Value>2<Value>
</item>
<item>
<key>ZZ</key>
<Value>2<Value>
</item>
<item>
<key>10</key>
<Value>X<Value>
</item>
<key>10</key>
<Value>X<Value>
</item>
Hi Praveen,
Try the below udf and check the outcome. Make sure you use remove context for both before passing the inputs key and value to the udf.
Code Snippet:
int flag=0;
for(int i=0,j=0;i<key.length;i++)
{
if((flag==1) && (j==1))
result.addValue("X");
else
result.addValue(value[i]);
if(key[i].equals("ZZ"))
{
flag=1;
j++;
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi
Praveen,
do a one to one mapping for key field.
1)argument 1: key
2)argument 2: value
3) result of type ResultList
execution type: all values of a context
use remove context for both the arguments before passing them to target udf
use the below udf
boolean flag = false;
for(int i=0; i<key.length; i++)
{
if(key[i].equalsIgnoreCase("ZZ") && flag == false)
{
result.addValue(value[i]);
flag = true;
}
else if(flag == true)
result.addValue("X");
else
result.addValue(value[i]);
}
//it handles cases when there are more than one ZZ
source
10
2
ZZ
2
10
2
ZZ
3
10
4
target
10 2, ZZ 2, 10 X, ZZ X, 10 X
all the ZZ after the first ZZ too will have X
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Praveen,
Did you tried sort and sortbykey functions?
regards,
Harish
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
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.