hadoop-common-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From steven <commercial...@yahoo.de>
Subject reducer, unexpected output
Date Fri, 19 Dec 2014 12:43:07 GMT
hi,


got a reducer that is not producing the expected output.
reducer looks like this:


//this reducer gets all the prices for one specific time frame for one 
product
public class StockReducer extends
     Reducer<IntArrayWritable, IntWritable, IntArrayWritable, 
IntArrayWritable> {

     @Override
     public void reduce(IntArrayWritable key, Iterable<IntWritable> 
values, Context context)
             throws IOException, InterruptedException {

         int high = 0;
         int low = 0;
         int open = 0;
         int close = 0;


         int unknown = Integer.MAX_VALUE;
         open = unknown;


         //calculating values, values holds the prices inside a specific 
timeframe, for example: 1000-3000ms
         for (IntWritable value : values) {
             System.out.println("value: " + value);

             int current = value.get();

             if (open == unknown) {
                 high = current;
                 low = current;
                 open = current;
                 close = current;

             }



             //high
             if (current > high) {
                 high = current;
             }

             //low
             if (current < low) {
                 low = current;
             }

             close = current;
         }
         System.out.println("high; " + high + " low: " + low + " open: " 
+ open + " close: " + close);

         int productID = key.get(1);
         int time = key.get(2);
         IntArrayWritable newKey = new IntArrayWritable(productID, time);

         IntArrayWritable output = new IntArrayWritable(high, low, 
open,close);


         context.write(newKey, output);

     }
}




IntArrayWritable is a custom data structure that uses a array for 
internal storage.
Basically a Array for ints that implements WritableComparable.


with this input:
1000,T,0,104,1000,1100,27147,80,80,80,80,81,81,98,98,98,101,137,137,139,177,177,177,173,166,149,134,130,124,119,111,104,92
1000,T,1,743,300,300,4976,492,492,492,492,492,497,497,856,856,863,866,875,875,954,954,954,954,954,954,954,954,770,770,770,770,743
1000,T,2,40,800,1000,11922,29,29,29,29,29,29,29,44,46,46,50,51,51,65,65,65,61,52,47,47,47,44,42,40,32,30
1000,T,3,6,1600,1900,29212,4,4,4,4,4,4,4,4,4,5,5,8,8,11,11,9,9,9,8,8,8,8,6,6,6,5
1000,T,4,16,200,200,6366,12,12,12,12,13,13,13,13,13,13,13,22,22,19,19,19,19,19,19,19,19,19,19,19,19,16
2001,T,0,103,6700,7000,44658,80,80,80,80,80,81,96,98,98,101,134,137,139,220,192,176,168,162,156,149,144,132,122,112,104,95
2001,T,1,699,1500,1700,8003,489,489,492,492,492,492,497,844,856,863,875,875,887,1215,1215,1193,1064,1053,995,995,975,846,751,704,699,553
2001,T,2,43,4500,4900,18861,29,29,29,29,29,29,29,46,46,47,50,51,52,96,69,64,57,53,52,51,50,49,48,45,44,36
2001,T,3,6,10100,12500,47158,4,4,4,4,4,4,4,4,4,4,5,8,8,12,11,10,9,9,8,8,7,7,7,6,5,4
2001,T,4,14,2400,2500,10450,12,12,12,12,12,13,13,13,13,13,13,22,22,36,30,25,23,21,20,20,20,18,16,16,15,12
3001,T,0,103,8600,9300,56951,79,80,80,80,80,81,96,98,98,101,134,137,139,224,196,177,166,159,152,145,138,130,120,110,104,82
3001,T,1,647,2800,3000,9836,488,488,489,492,492,497,833,844,856,863,875,887,898,1597,1216,1001,980,957,935,860,846,794,752,705,667,550
3001,T,2,46,5900,7200,21840,29,29,29,29,30,44,46,46,47,48,51,52,52,80,71,69,63,61,59,55,53,51,48,44,39,34
3001,T,3,6,15100,18300,56662,4,4,4,4,4,4,4,4,4,4,5,8,8,12,11,10,9,8,8,8,7,7,6,6,5,4
3001,T,4,14,1500,1800,12389,12,12,12,12,12,13,13,13,13,13,13,22,22,27,27,24,24,23,23,22,20,17,15,14,13,12



i get:
[0, 1]  [104, 104, 104, 104]
[0, 2]  [103, 103, 103, 103]
[0, 3]  [103, 103, 103, 103]
[1, 1]  [743, 743, 743, 743]
[1, 2]  [699, 699, 699, 699]
[1, 3]  [647, 647, 647, 647]
[2, 1]  [40, 40, 40, 40]
[2, 2]  [43, 43, 43, 43]
[2, 3]  [46, 46, 46, 46]
[3, 1]  [6, 6, 6, 6]
[3, 2]  [6, 6, 6, 6]
[3, 3]  [6, 6, 6, 6]
[4, 1]  [16, 16, 16, 16]
[4, 2]  [14, 14, 14, 14]
[4, 3]  [14, 14, 14, 14]


productID, timeframe    high, low, open, close

but high, low, open, close are all the same values...why does the code 
not produce differnt values for these?
input is a log from a stock market simulation.



if i test the code like this:
import java.util.ArrayList;
import java.util.List;

public class HighLowOpenClose {



     public void calculate(List<Integer> input) {
         int unknown=Integer.MAX_VALUE;
         int open = unknown;
         int close = 0;
         int low = 0;
         int high = 0;

         for (Integer current: input) {
             //output in each run
             System.out.println("high " + high + " low: " + low);
             if (open == unknown) {

                 //this should only happen once
                 //System.out.println("inside if loop");
                 open = current;
                 close = current;
                 low = current;
                 high = current;
             }

             if (current > high) {
                 high = current;
             }

             if (current < low) {
                 low = current;
             }

             close = current;
         }

         //expected output: high: 50, low: 9
         System.out.println("high: " + high + " low: " + low);
     }


     public static void main(String[] args) {
         HighLowOpenClose x = new HighLowOpenClose();
         List<Integer> input = new ArrayList<Integer>();

         //generate some input, values 10....50
         for (int n=10; n<50; n++) {
             input.add(n);
         }
         input.add(9);

         x.calculate(input);

     }
}


the for loop produces the expected output.
any ideas?


greetings


Mime
View raw message