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

Method computeAll

src/org/apache/pig/builtin/COV.java:291–319  ·  view source on GitHub ↗

compute sum(XY), sum(X), sum(Y) from given data sets @param first DataBag containing first data set @param second DataBag containing second data set @return tuple containing sum(XY), sum(X), sum(Y)

(DataBag first, DataBag second)

Source from the content-addressed store, hash-verified

289 * @return tuple containing sum(XY), sum(X), sum(Y)
290 */
291 protected static Tuple computeAll(DataBag first, DataBag second) throws IOException {
292 double sum_x_y = 0.0;
293 double sum_x = 0.0;
294 double sum_y = 0.0;
295 Iterator<Tuple> iterator_x = first.iterator();
296 Iterator<Tuple> iterator_y = second.iterator();
297 try{
298 while(iterator_x.hasNext()){
299 double x = (Double)iterator_x.next().get(0);
300 double y = (Double)iterator_y.next().get(0);
301 sum_x_y+=x*y;
302 sum_x+=x;
303 sum_y+=y;
304 }
305 }catch (Exception e){
306 throw new IOException("Caught exception processing input", e);
307 }
308
309 Tuple result = TupleFactory.getInstance().newTuple(3);
310 try{
311 result.set(0, sum_x_y);
312 result.set(1, sum_x);
313 result.set(2, sum_y);
314 }catch(Exception e) {
315 throw new IOException("Caught exception processing result", e);
316 }
317 return result;
318
319 }
320
321 @Override
322 public Schema outputSchema(Schema input) {

Callers 2

execMethod · 0.95
execMethod · 0.45

Calls 7

getInstanceMethod · 0.95
setMethod · 0.95
iteratorMethod · 0.65
getMethod · 0.65
newTupleMethod · 0.65
hasNextMethod · 0.45
nextMethod · 0.45

Tested by

no test coverage detected