on 05-17-2017 10:20 AM
InputField is - TEXT1|TEXT2|TEXT3|TEXT4
Please provide UDF to get output in 4 fields. | is the separator here.
Output should be -
Segment A value should come TEXT1
Segment B value should come TEXT2
Segment C value should come TEXT3
Segment D value should come TEXT4
Hi Vijay,
If I understood requirement correctly, fields in the target structure to which values are assigned, shall have different names, correct? If so, as one of solutions in achieving the requirement, you can use custom function to make splitting of the input value (from the source message) into array of substrings based on the given delimiter symbol, and then assign individual array entries to corresponding fields (of the target message). Here is example how this can be implemented...
UDF - note that it is possible to specify any arbitrary separator symbol (for example, if it will be not a pipe symbol next time), and it is required to specify which delimited chunk of the the input value needs to be assigned to the target field:
String[] values = value.split("[" + separator + "]");
if (position > values.length) {
throw new StreamTransformationException("Position of requested field exceeds available fields found in input value");
}
return values[position - 1];
Mapping rule for the first of target fields:
Mapping rule for the second of target fields, etc.:
Sample test of the mapping:
Regards,
Vadim
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Vijay!
I can't check it right now but UDF should look like this:
String[] parts = in.split("[|]");
for (int i = 0; i < parts.length; i++)
result.add(parts[i].trim());
Regards, Evgeniy.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I don't have a PI or PO system at my disposal at the moment but you would use a StringTokenizer to split your string by the pipe delimiter and then assign the first token to Segment A, the second to Segment B etc. You will probably want to create a generic UDF that accepts the input string and an integer denoting the exact token you want returned) and use the same UDF with different token number on all four segments.
If you need to dynamically create segments according to the number of elements in your source string, you can create a UDF that loops through your StringTokenizer and adds a new result to the function for every available token (with the value of that token).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
91 | |
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.