| 55 | private static TupleFactory mTupleFactory = TupleFactory.getInstance(); |
| 56 | |
| 57 | @Override |
| 58 | public Long exec(Tuple input) throws IOException { |
| 59 | try { |
| 60 | DataBag bag = (DataBag)input.get(0); |
| 61 | if(bag==null) |
| 62 | return null; |
| 63 | |
| 64 | Iterator it = bag.iterator(); |
| 65 | long cnt = 0; |
| 66 | while (it.hasNext()){ |
| 67 | Tuple t = (Tuple)it.next(); |
| 68 | if (t != null && t.size() > 0 && t.get(0) != null ) |
| 69 | cnt++; |
| 70 | } |
| 71 | return cnt; |
| 72 | } catch (ExecException ee) { |
| 73 | throw ee; |
| 74 | } catch (Exception e) { |
| 75 | int errCode = 2106; |
| 76 | String msg = "Error while computing count in " + this.getClass().getSimpleName(); |
| 77 | throw new ExecException(msg, errCode, PigException.BUG, e); |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | public String getInitial() { |
| 82 | return Initial.class.getName(); |