on 09-21-2011 6:42 PM
Hi All,
I am having a mapping requirement. A comma separated string is coming in the source field and i have to split the value
and map the target fields.
For example:
Source:
<Row>123,BOFA,Success,True</Row>
Output
<Target>
<A>123</A>
<B>BOFA</B>
<C>Success</C>
<D>True</D>
</Target>
I am using UDF for the same but getting an exception.
Please help.
Thanks!!
ur example doesnt seems to be very much clear...but what i understood from ur query is that u want to split the incoming string
BTW whats the exception u r getting and can u plz paste ur code over here??
In the meantime chk this:
Input will be var1, var2
Execution type : single value
String [] temp= var1.split(",");
return temp[var2];
mapping:
Row----
-
UDF----First Field
Constant(0)---
Row----
-
UDF----Second Field
Constant(1)---
in the same way for the rest of the fields....
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Are there only one row or multiple rows in source XML? Then mapping the root is also necessary. Secondly if we look at this XML
<Target>
123 BOFA <C>Success</C>
<D>True</D>
</Target>
The value "123 BOFA" is expected to be within XML tag as shown below
<Target>
<A>123 BOFA</A>
<C>Success</C>
<D>True</D>
</Target>
Could you please kindly mention the version of PI you are working in.
Anyways you can use the following UDF to meet your requirements. For each field in target, u need separete UDF. The value of variable "i" is only to be altered for each target field.
public String UDF(String a,Container container)
{
String s[]=new String[3];
int i=0;
try
{
String tgt[]=a.split(",");
//first field value
s[0]=tgt[0]+" "+tgt[1];
//second field ("C") value
s[1]=tgt[2];
//third field ("D") value
s[2]=tgt[3];
}
catch(Exception e)
{
e.printStackTrace();
}
//value of i decides which field you want to populate for first field i=0 so on and so forth
i=0;
return s<i>;
}
Hope this solves your problem.
regards
Anupam
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
i like to add some on top of the code, where instead of creating the different UDF's you can get a value as input and pass it to UDF and display the output as below ;
String s[]=new String[3];
int i= Integer.parseInt(b);
try
{
String tgt[]=a.split(",");
//first field value
s[0]=tgt[0]+" "+tgt[1];
//second field ("C") value
s[1]=tgt[2];
//third field ("D") value
s[2]=tgt[3];
}
catch(Exception e)
{
e.printStackTrace();
}
return s<i>;
The mapping will be like
Source & Value to be sent to target -- UDF --- Target
Hi Anu,
What is the total length of that field and how much values will be sent in that field.
You can also give a try with substring.
-Muru
Edited by: Murugavel Singaravel on Sep 21, 2011 11:05 PM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
wirte a java UDF using string Tokenizer for "," to acheive your requirement.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
90 | |
10 | |
10 | |
10 | |
7 | |
7 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.