cancel
Showing results for 
Search instead for 
Did you mean: 

UDF for comparison with empty field

Former Member
0 Kudos

Hi experts,

Need help on this.

I have to compare two queues and pass the greatest of them into the result.Now my problem is some times 1st queue has less or more no of entries than 2nd queue.so for that the result should get the value of the existing queue.

example:

forecast: 100     20     200     30     70    

orders:    90     100     300     50     70     110     0     350     400

result:    100    100     300     50     70     110     0     350     400

i tried to use Mapwithdefault and removing suppress after comparison but was not lucky enough.

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi Ashutosh,

     I guess, you can do the same thing using standard function. Please refer to the below screen shot.

Thanks & Regards,

Samir

former_member184681
Active Contributor
0 Kudos

Hi,

You can make it even simpler, if you used mapWithDefault(0) instead of mapWithDefault(space). This way it will become:

Forecast -> mapWithDefault(0) ->

                                                  greater -> if -> Result

Order -> mapWithDefault(0) ->

Map the first mapWithDefault to both: greater (as first argument) and if (as "then" argument) and the second mapWithDefault to both: greater (as second argument) and if (as "else" argument).

Regards,

Greg

iaki_vila
Active Contributor
0 Kudos

Hi Ashutosh,

Another way to do the UDF (all values in queue):

public void compareArrayStrings(String[] aParam,String[] bParam,ResultList result,Container container){

boolean exit = false;

int lenA = aParam.length;

int lenB = bParam.length;

int iterA = 0;

int iterB = 0;

while (exit == false){

if ((iterA < lenA) && (iterB < lenB)){

   if (Integer.parseInt(aParam[iterA]) >  Integer.parseInt(bParam[iterB]))

          result.addValue(aParam[iterA]);

           else  result.addValue(bParam[iterB]);

   iterA++;

   iterB++;

}

else if ((iterA < lenA) && (iterB == lenB)) {

  result.addValue(aParam[iterA]);

  iterA++;

}  else if ((iterB < lenB) && (iterA == lenA)){

  result.addValue(bParam[iterB]);                   

       iterB ++;   

}  else exit = true;

}

}

If I test your example:

Regards.

baskar_gopalakrishnan2
Active Contributor
0 Kudos

Pass two queues as parameter to the UDF  method

Example:  int[] forecast  int[] orders

// Assume you have forecast and orders in int type.

  

int[]  result =  new result[];

for (int i =0; i < forecast.length;  i++){

   for(int j=0; j< orders.length; j++){

  

    if(forecast[i] > orders[j]){

      result[i] = forecast[i];

    } else{

      result[i] = orders[j];

    }

}

}

result.addValue(result);

Map the forecast and orders as input to the udf and map the output to orders.

   

That's it.  if your input values are string then you have to convert to int before condition check.