on 07-28-2009 5:29 PM
Hi Experts ,
I am not sure if this can be dealt with in message mapping or do i have to write a UDF for it
if there is any1 who can help me with the UDF it would be great
the requirement is that i am receiving a string which is a combination of n strings seperated by @ as a delimiter
e.g
(abc@frgthj@234)
or (abc@frgthj)
or (abc@234)
my requirement is to pass the first part abc to one target element and the second part frgth to the other target element
basically strings could be 2 or 3 but maximum 4 in number but the seperator will be @ and the requirement is to just pick up the first string(coming of any length) and map it to target 1
the 2nd string of any length and map it to target2 i.e reading the string before @ and mapping to target structures
Can anyone help me build this UDF , m sure it can be a generic one
Thanks
Rohan
Hi,
Create generic UDF with following input "Value" "separator", "fieldplace"
So in your case separator = "@" and fieldplace will be either "1", "2" or n.
Write following code:
//==================
int index = Integer.parseInt(fieldplace);
for(int i = 1; i<=index ; i++)
{
Value = Value.subString(Value.indexOf("@"),Value.lenght());
}
return Value;
//====================
One UDF will be sufficient to decode any value with any delimiter for any number of field.
Disclaimer: check for syntax error and I have not tested it.
Regards,
Gourav
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Gaurav
Thanks , however I am getting an exception
" the length 0 of the array 'sortedFunctionKeys' is not equal to the number 1 of functions. "
also if I test it with the code u provided with an example
value =rohan@das
seperator=,
fieldplace=1
I am not getting the desired result as rohan
same if i change fieldplacefor 2 im not getting das
my requirement is simple
I will always get a string of maximum 2 or 3 fields(different lengths) seperated by a @
and i need to extract these individually , can you please help me
thanks
Rohan
Rohan,
Did you try the udfs I have given above. I tested on my system and they are working. You can give a try and if it doesnot work then somebody can help you. You can also try to combine the two udfs into one udf also.
For your question you may need to check @ with the function exists. If exists then you may need to do one logic else you may do other logic.
Regards,
---Satish
Yes Satish
thanks I am trying the same but unableto save the UDF's while mapping and it gives the errro as i mentioend above
Error while Executing Save
" the length 1 of the array 'sortedFunctionKeys' is not equal to the number 2 of functions "
which is why now i am unable to test unless this exception is resolved
Can any one please guide me how to deal with this mapping exception while trying to save the mapping ?
I am unable to save the UDFand it gives an error while trying to execute save
" the length 1 of the array 'sortedFunctionKeys' is not equal to the number 2 of functions "
if anyone has encountered the same before or knws what could be the reason please let me know
thanks
Rohan
No No Gaurav
It was a typo earlier i am using @ as the seperator as an input to the udf
my issue is the exception that i am receiving as mentioned
and i dont have any sortedFunctionKeys used anywhere in my functions and am unableto catch the cause of this exception
due to which i cant test the udf's in the mapping now
as mentioned by Satish i checked my udf's none use sortedFunctionKeys
Hi,
I've modified the code given by Santosh:
For the first node, do this mapping:
sourceNode --> UDF --> copyValue[0] --> targetNode (1)
For the second node, do this mapping:
sourceNode --> UDF --> copyValue[1] --> targetNode (2)
Here is the code, UDF type is CONTEXT Type
Argument is input
String b[] = input[0].split("@");
for (int a=0;a<b.length;a++){result.addValue(b[a]);}
Hope this helps,
public String SPLITUDF(String a, String b, Container container){
String flag="";
String c="";
String d="";
String first="";
String second="";
first=a.substring(0,a.indexOf("@"));
c=a.substring(a.indexOf("@")+1);
if (c.indexOf("@")==-1)
flag="Y";
else
flag="Z";
if (flag=="Y")
second=c.substring(a.indexOf("@")+1);
else
second=c.substring(0,c.indexOf("@"));
if (b == "1")
return first;
else if (b == "2")
return second;
}
Use the Same UDF for both different fields that is splitted based on constants.
input-------------> SplitUDF -------------> First
Constant(1)---->
input-------------> SplitUDF -------------> Second
Constant(2)---->
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
As you are saying it can vary then better to go for stringTokenizer class of java which will separate the strings based on the token provided ...
Google it if need more help and code for the same
Rajesh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You may use indexOf function to find the location of @. Then you may use substring to take the value before @ and after @. Then you may apply the same thing for the remaining string. You may check in second case that if @ is present, only then perform the same indexOf and substring.
Regards,
Prateek
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Rohan,
In your first example (abc@frgthj@234) abc will assigned to field1 and frgthj will be assigned to field2. Am I correct? If yes proceed like this:
For field1:
Create a value udf and take one input parameter 'a' and name as field1udf. Then add this code:
Imports: java.;*
int i = a.indexOf("@");
a = a.substring(0,i);
return(a);
Then map like this: source --> field1udf --> target (this will give the output as abc)
For field2:
Create a value udf and take three input parameter 'a' 'b' and 'c' and name as field2udf. Then add this code:
Imports: java.;*
int i = Integer.parseInt(a);
int j = Integer.parseInt(b);
String d = c.substring(j+1,i);
return(d);
Then map like this:
source --> length --> is the first input to field2udf
source-->indexof2 (text function) with constant @ is the second input to field2udf
source --> is the third input to field2udf
Then map the above to field2udf --> field1udf --> target. this will give the output as frgthj.
Regards,
---Satish
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.