cancel
Showing results for 
Search instead for 
Did you mean: 

Sorting the context based on a value

346

Hi Experts,

My scenario is to sort the values in Input Q based on a numerical value below are the details.

Input Q has below list of values.

Sequence field has below list of values.

Now the fields from the input Q should be aligned as per the sequence number.

like in total of 5 contexts:

1st context with no value, 2nd context with name2, 3rd context with name6 & name3, 4th context with name4, 5th context with name5 like shown below

Please help in UDF code for this logic.

View Entire Topic
former_member470153
Discoverer
0 Kudos

Hi Yeswanth,

All the time for the input Q will come the below values only?

0 Kudos

Hi Chandra,

Values will be different all the times, based on the sequence value the context should be added.

malathi2608
Explorer

Hi Yeswanth,

try below logic.

Sequence field as input1 and Input Q as input2

public void calculate(String[] var1, ResultList result, String[] var2, Container container) throws StreamTransformationException{

int c = 0;

for (int i = 0,k = 0;i<var1.length;i++)

{

c = Integer.parseInt(var1[i]);

for (int j = c; j >= 0;j--)

{

if (j == 0)

result.addContextChange();

else

{

result.addValue(var2[k]);

k=k+1;

} } }}