cancel
Showing results for 
Search instead for 
Did you mean: 

Need clarification on UDF

Former Member
0 Kudos

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

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

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

Former Member
0 Kudos

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

justin_santhanam
Active Contributor
0 Kudos

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.

Former Member
0 Kudos

Hi,

We can Achive this thing by standard Functions also right??

by placing the If then Else condition...

Regards

justin_santhanam
Active Contributor
0 Kudos

Vamsi,

Can you tell me how to write using standard functions? I mean I want to see the logic. Based on your logic I will reply...

Thanks,

raj.

Former Member
0 Kudos

Hi Raj,

If String a = "ABC" then mapp String b value to target Else Mapp to Constant

Regards

justin_santhanam
Active Contributor
0 Kudos

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.

Former Member
0 Kudos

>>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