Guest User

Untitled

a guest
Jul 17th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. package query;
  2.  
  3. import java.io.IOException;
  4. import java.util.Iterator;
  5. import java.util.HashMap;
  6. import java.util.Set;
  7.  
  8. import org.apache.hadoop.io.*;
  9. import org.apache.hadoop.mapred.MapReduceBase;
  10. import org.apache.hadoop.mapred.OutputCollector;
  11. import org.apache.hadoop.mapred.Reducer;
  12. import org.apache.hadoop.mapred.Reporter;
  13.  
  14. public class RrdReducer extends MapReduceBase implements Reducer<IntWritable, FloatWritable, IntWritable, FloatWritable> {
  15.  
  16. public void reduce(IntWritable key, Iterator<FloatWritable> values, OutputCollector<IntWritable, FloatWritable> output, Reporter reporter) throws IOException
  17. {
  18. float threshold = 90;
  19. int time = 120;
  20. int min;
  21. int max;
  22. int cpt=0;
  23. HashMap<Integer, Float> cons = new HashMap<Integer, Float>();
  24. while (values.hasNext())
  25. {
  26. System.out.println("cpt: "+cpt++);
  27. Float v = values.next().get();
  28. if(v > threshold)
  29. {
  30. System.out.println("key: "+ key.get()+" value: "+v);
  31. cons.put(key.get(), v);
  32. }
  33. else {
  34. if(cons.size()>0) {
  35. Set<Integer> key_set = cons.keySet();
  36. min = Integer.MAX_VALUE;
  37. max = 0;
  38. for(Integer i : key_set)
  39. {
  40. if(i>max)
  41. max = i;
  42. if(i<min)
  43. min=i;
  44. }
  45. System.out.println("MIN: "+min);
  46. System.out.println("MAX: "+max);
  47.  
  48. if((max - min) > time)
  49. for(Integer k : key_set)
  50. {
  51. v = cons.get(k);
  52. output.collect(new IntWritable(k), new FloatWritable(v));
  53. }
  54. cons.clear();
  55. }
  56. }
  57. }
  58. }
  59.  
  60. }
Add Comment
Please, Sign In to add comment