on 04-17-2009 9:33 PM
Can any one please let me know, what does the following UDF
public void UDF1 (String[] a,String[] b,ResultList result,Container container)
{
//write your code here
try {
for(int i=0;i<(a.length);i++){
if((a<i>.equals("ABC")))
{ result.addValue(b<i>);
}
}
} catch(ArrayIndexOutOfBoundsException e) {
}
Regards
Hi Vamsi,
Yes u can acheive using STANDARD FUNCTIONS
compare a with constant "ABC" using standard function equals then use ifWithoutelse and map b to teh target field
Here I have assumed a , b and target field occurence is 1 to unbounded
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
public void UDF1 (String] a,String[ b,ResultList result,Container container)
{
//write your code here
try {
for(int i=0;i<(a.length);i++){
if((a.equals("ABC")))
{ result.addValue(b);
}
}
} catch(ArrayIndexOutOfBoundsException e) {
}
above code should have been like given below
public void UDF1 (String[] a,String[] b,ResultList result,Container container)
{
//write your code here
try
{
for(int i=0;i<a.length;i++)
{
if((a<i>.equals("ABC")))
{
result.addValue(b<i>);
}
}
}
catch(ArrayIndexOutOfBoundsException e)
{
}
}
the above UDF has three inputs
2 r of type String array and third input comes only if u select Context or Queue while creating the UDF(the UDF is called advanced in this case)
ResultList object is used in advanced user-defined functions to return the result of the function. use this object to either return a queue or to return the context of a queue.
then u r using for loop to read all the values within the context
each and every value is checked with the constant String "ABC" IF they are equal it returns true else false.
If it returns true then ur adding the value to the result
if u use ur own UDF ur r not writing any code to handle the exception raised in the try block
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Vamsi,
Please see the below explanation.
Since you have choosen the UDF Cache as Queue
Let's consider Input a will have the below values in the Queue(array)
123, 678, 1244, 456, ABC, 135, 987
Let's consider Input b will have the below values in the Queue(array)
demo1, demo2, demo3, demo4, demo5, demo6, demo7
Then the below UDF will return demo5 as the output.
The UDF has been written in assumption that length of array a and b will be the same.
public void UDF1 (String[] a,String[] b,ResultList result,Container container)
{
try {
for(int i=0;i<(a.length);i++){
if((a<i>.equals("ABC")))
{
result.addValue(b);
}
}
} catch(ArrayIndexOutOfBoundsException e) {
}
Hope it helps!
Thanks,
raj.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Vamsi,
Let me make clear myself. You just want to replace the UDF with Standard functions, am I right?
If yes then follow the below logic.
Field1 --> Change context to higher node --> IF THEN Without Else -->Collapse Context --> Target Field
In the above THEN block map Field2(Change Context to higher node)
So, if there are any "ABC" in Field1 ,then you will get the corresponding element from Field2. If there are no "ABC" in Field2 then you will get blank value.
Hope it helps!
Thanks,
raj.
>>Can any one please let me know, what does the following UDF
I m not really sure what you mean by above sentence.
It is an advanced UDF which takes 2 inputs(a and b),if any occurence of input a ="ABC" then value of b is added to the resultlist and eventually resultlist is returned from the UDF.
i think you need to replace if((a.equals("ABC"))) with if(a<i>.equals("ABC")) as well.
Thanx
Aamir
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
87 | |
10 | |
10 | |
9 | |
7 | |
6 | |
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.