@Override public void accumulate(Tuple b) throws IOException { try { Long curVal = doTupleWork(b, opProvider); if (curVal == null) { return; } if (intermediateVal == null) { intermediateVal = getSeed(opProvider.getOp()); } intermediateVal = doWork(intermediateVal, curVal, opProvider.getOp()); } catch (ExecException ee) { throw ee; } catch (Exception e) { int errCode = 2106; throw new ExecException("Error executing function on Longs", errCode, PigException.BUG, e); } }
protected static Long doTupleWork(Tuple input, KnownOpProvider opProvider) throws ExecException { DataBag values = (DataBag)input.get(0); // if we were handed an empty bag, return NULL // this is in compliance with SQL standard if(values == null || values.size() == 0) { return null; } Long sofar = AlgebraicLongMathBase.getSeed(opProvider.getOp()); boolean sawNonNull = false; for (Iterator<Tuple> it = values.iterator(); it.hasNext();) { Tuple t = it.next(); try { // Note: use Number.longValue() instead of casting to Long // to allow Integers, too. Number n = ((Number)(t.get(0))); if (n == null) continue; Long d = n.longValue(); sawNonNull = true; sofar = doWork(sofar, d, opProvider.getOp()); }catch(RuntimeException exp) { int errCode = 2103; throw new ExecException("Problem doing work on Longs", errCode, PigException.BUG, exp); } } return sawNonNull ? sofar : null; }
@Override public Long exec(Tuple input) throws IOException { try { return doTupleWork(input, opProvider); } catch (ExecException ee) { throw ee; } catch (Exception e) { int errCode = 2106; throw new ExecException("Error executing function on Longs", errCode, PigException.BUG, e); } }
@Override public Long exec(Tuple input) throws IOException { try { return doTupleWork(input, this); } catch (ExecException ee) { throw ee; } catch (Exception e) { int errCode = 2106; throw new ExecException("Error executing function on Longs", errCode, PigException.BUG, e); } } }
@Override public Tuple exec(Tuple input) throws IOException { try { return tfact.newTuple(doTupleWork(input, this)); } catch (ExecException ee) { throw ee; } catch (Exception e) { int errCode = 2106; throw new ExecException("Error executing function on Longs", errCode, PigException.BUG, e); } } }