cancel
Showing results for 
Search instead for 
Did you mean: 

UDF

Former Member
0 Kudos

Hi All,

I need to implment the mapping using UDF for the second occurrence of the source field which needs to be mapped to the target field.

Similarly,I need to write the UDFs for the third,fourth occurrneces of the same source field.

Can you please help me?

Thanks in advance

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

I need to implment the mapping using UDF for the second occurrence of the source field which needs to be mapped to the target field.

Similarly,I need to write the UDFs for the third,fourth occurrneces of the same source field.

Yes u can do it using a UDF also...

a single UDF will suffice, and we will be passing the which occurence u want to map as an index parameter, i.e., 2 or 3 or 4

Try this code,

Input: sourceField,index // index will be passed as a constant 2 or 3 or 4 , what ever u want...

the udf will be in all values of queue.....

-



int i = Integer.parseInt(index);
return sourceField<i>;

-


Former Member
0 Kudos

Hi hlbabu123,

Thanks for the reply.

Input: sourceField,index // index will be passed as a constant 2 or 3 or 4 , what ever u want...

the udf will be in all values of queue.....




--------------------------------------------------------------------------------

int i = Integer.parseInt(index);
return sourceField<i>;

Which parameters of this UDF should be declared while creating the UDF?

Thanks in advance

Former Member
0 Kudos

Hi Shwetha,

Which parameters of this UDF should be declared while creating the UDF?

i have mentioned it earlier...

Input: sourceField,index // index will be passed as a constant 2 or 3 or 4 , what ever u want...

the sourceField is the one from which u want to extract 2 or 3rd or 4 th occurence of field.

index will be passed as a constant, 2 or 3 or 4 based on ur req....

One UDF will surve for all the combinations u want

Babu

Former Member
0 Kudos

Hi Babu,

Thanks for your reply.

Input: sourceField,index // index will be passed as a constant 2 or 3 or 4 , what ever u want...

the sourceField is the one from which u want to extract 2 or 3rd or 4 th occurence of field.

index will be passed as a constant, 2 or 3 or 4 based on ur req....

One UDF will surve for all the combinations u want

I want to ask you how many and which parameters should be declared as arguments while creating the UDF?

Do I mention 2 arguments 1 as sourceField and ,2 as index?

Also,how to use this UDF differently for the second,third and the fourth occurrences?Means,how to pass the second,third and the fourth occurrence to this same UDF that I need to use differently for 3 different fields in the mapping?

Thanks in advance

0 Kudos

Hi Swetha,

As per Babu you need to pass the constant as the second argument which occurence you want to get as output. The first argument to pass to the UDF will be your source values.

That is you need to pass 2 or 3 or 4 as index to the UDF using constants, so that particluar occurance will be returned.

@ Babu: correct me if I am wrong...

Regards

Venkat

Former Member
0 Kudos

Hi Shwetha,

I want to ask you how many and which parameters should be declared as arguments while creating the UDF?

u will pass 2 parameters to the UDF.

Do I mention 2 arguments 1 as sourceField and ,2 as index?

yes u r correct.

Also,how to use this UDF differently for the second,third and the fourth occurrences?Means,how to pass the second,third and the fourth occurrence to this same UDF that I need to use differently for 3 different fields in the mapping?

When u want to map the 2nd occurence of the sourceField to a target fileld u will pass to UDF,

sourceField

index(its a constant value 2)

When u want to map the 3rd occurence of the sourceField to a target fileld u will pass to UDF,

sourceField

index(its a constant value 3)

and so on...

Let us know, still u face the prblm..

Babu

Former Member
0 Kudos

Hi Venkat,

Exactly u r correct!!!

Babu

Former Member
0 Kudos

Hi Venkat and Babu,

Thanks for your reply.

When u want to map the 2nd occurence of the sourceField to a target fileld u will pass to UDF,

sourceField
index(its a constant value 2)


When u want to map the 3rd occurence of the sourceField to a target fileld u will pass to UDF,

sourceField
index(its a constant value 3)

and so on...

Means,in the 3 different UDFs I will have to declare the variable as Index with the constant values as 2,3 and 4.

But while creating the UDF and declaring the variable how can I declare the variable Index as a constant?There are only 3 Java Types that is String,int,float?

Thanks in advance.

0 Kudos

Hi Swetha,

no need to create three UDF, just create only one UDF and use it as many times as you want, and while using the UDF depending upon the occurence you want to get, just pass the number(eg: 2 or 3 or 4) to that UDF using CONSTANT function which is available in the mapping functions.

Regards

Venkat

Former Member
0 Kudos

Hi Venkat,

Thanks for the reply.

no need to create three UDF, just create only one UDF and use it as many times as you want, and while using the UDF depending upon the occurence you want to get, just pass the number(eg: 2 or 3 or 4) to that UDF using CONSTANT function which is available in the mapping functions.

Means ,while creating the UDF,I need to declare 2 variables as type agrument and Java Type String, the first one as sourceField and the second one as the index.

In the mapping, the first input to the UDF will be the sourceField that is the source string while the other input to the UDF will be the constant function whose context will be 2 for the second occurrence,3 for the third occurrence,4 for the fourth occurrence.

I can use the same UDF but with the different values of the constant function.Right?

Thanks in advance.

Answers (1)

Answers (1)

former_member204873
Contributor
0 Kudos

hi,

If you just want to supress first occurence of a field, try to use:

String xyz[] = {"1","2","3"}; -


input

int len = xyz.length;

for (int x = 1;x<len; x++ ){

result.addValue(xyz[x]) ;

}

Former Member
0 Kudos

Hi Mayank,

String xyz[] = {"1","2","3"}; ---- input 
int len = xyz.length;
for (int x = 1;x<len; x++ ){
result.addValue(xyz[x]) ;
}

Which parameters of this UDF shuld be declared as variables?

Thanks in avance