Compares a tuple with two fields. Emits any differences. @param input a tuple with exactly two fields. @throws IOException if there are not exactly two fields in a tuple
(Tuple input)
| 52 | * @throws IOException if there are not exactly two fields in a tuple |
| 53 | */ |
| 54 | @Override |
| 55 | public DataBag exec(Tuple input) throws IOException { |
| 56 | if (input.size() != 2) { |
| 57 | int errCode = 2107; |
| 58 | String msg = "DIFF expected two inputs but received " + input.size() + " inputs."; |
| 59 | throw new ExecException(msg, errCode, PigException.BUG); |
| 60 | } |
| 61 | try { |
| 62 | DataBag output = mBagFactory.newDefaultBag(); |
| 63 | Object o1 = input.get(0); |
| 64 | if (o1 instanceof DataBag) { |
| 65 | DataBag bag1 = (DataBag)o1; |
| 66 | DataBag bag2 = (DataBag)input.get(1); |
| 67 | computeDiff(bag1, bag2, output); |
| 68 | } else { |
| 69 | Object d1 = input.get(0); |
| 70 | Object d2 = input.get(1); |
| 71 | if (!d1.equals(d2)) { |
| 72 | output.add(mTupleFactory.newTuple(d1)); |
| 73 | output.add(mTupleFactory.newTuple(d2)); |
| 74 | } |
| 75 | } |
| 76 | return output; |
| 77 | } catch (ExecException ee) { |
| 78 | throw ee; |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | private void computeDiff( |
| 83 | DataBag bag1, |