MCPcopy Create free account
hub / github.com/apache/pig / exec

Method exec

tutorial/src/org/apache/pig/tutorial/ScoreGenerator.java:75–115  ·  view source on GitHub ↗
(Tuple input)

Source from the content-addressed store, hash-verified

73 }
74
75 public DataBag exec(Tuple input) throws IOException {
76 if (input == null || input.size() == 0)
77 return null;
78 try{
79 DataBag output = DefaultBagFactory.getInstance().newDefaultBag();
80 DataBag in = (DataBag)input.get(0);
81
82 Map<String, Long> pairs = new HashMap<String, Long>();
83 List<Long> counts = new ArrayList<Long> ();
84
85 Iterator<Tuple> it = in.iterator();
86 while (it.hasNext()) {
87 Tuple t = it.next();
88 String hour = (String)t.get(1);
89 Long count = (Long)t.get(2);
90 pairs.put(hour, count);
91 counts.add(count);
92 }
93
94 double mean = computeMean(counts);
95 double standardDeviation = computeSD(counts, mean);
96
97 Iterator<String> it2 = pairs.keySet().iterator();
98 while (it2.hasNext()) {
99 String hour = it2.next();
100 Long count = pairs.get(hour);
101 if ( count > mean ) {
102 Tuple t = TupleFactory.getInstance().newTuple(4);
103 t.set(0, hour);
104 t.set(1, ((double) count - mean) / standardDeviation ); // the score
105 t.set(2, count);
106 t.set(3, mean);
107 output.add(t);
108 }
109 }
110 return output;
111 }catch (Exception e){
112 System.err.println("ScoreGenerator: failed to process input; error - " + e.getMessage());
113 return null;
114 }
115 }
116
117 @Override
118 /**

Callers

nothing calls this directly

Calls 15

getMethod · 0.95
iteratorMethod · 0.95
addMethod · 0.95
computeMeanMethod · 0.95
computeSDMethod · 0.95
getInstanceMethod · 0.95
setMethod · 0.95
sizeMethod · 0.65
newTupleMethod · 0.65
newDefaultBagMethod · 0.45
getInstanceMethod · 0.45
hasNextMethod · 0.45

Tested by

no test coverage detected