on 05-17-2012 10:22 PM
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
85 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.