cancel
Showing results for 
Search instead for 
Did you mean: 

Need Help in UDF: Create Contexts

former_member184789
Active Contributor
0 Kudos

Hi,

We have two inputs to the UDF, one will have a numeric value such as 2,3 etc. and we need to create this no. of contexts for the second input. For example if the first input is 3, we need to create 3 contexts for the second input.It is similar to UseoneasMany, except that instead of creating contexts based on the no. of times a value appears, we need to create contexts based on a numeric value.Pls note that the same value of second input will be created as many times as the numeric value in first input.

Accepted Solutions (1)

Accepted Solutions (1)

markangelo_dihiansan
Active Contributor
0 Kudos

Hello,

You can use this UDF:

type:contextType

arguments: inp1, inp2

for(int a=0;a<inp1.length;a++){

    int temp = Integer.parseInt(inp1[a]);

    for(int b=0;b<temp;b++){

        result.addValue(inp2[a]);

    }

}

Hope this helps,

Mark

former_member184789
Active Contributor
0 Kudos

Thanks Mark..It worked exactly as desired..I will never forget the timely help from you..Thanks a lot.

Answers (1)

Answers (1)

justin_santhanam
Active Contributor
0 Kudos

Hi Adarsh,

Use the below function:

When you are defining the parameters define input1 variable as int input2 as String ( and define as Queue)

for(int i=0;i<input1[0]-1;i++)

{

result.addValue(input2[0]);

}