The default implementation of PigStreamingBase. It converts tuples into fieldDel separated lines and fieldDel separated lines into tuples.
| 32 | * |
| 33 | */ |
| 34 | public class PigStreaming extends PigStreamingBase { |
| 35 | |
| 36 | private byte recordDel = '\n'; |
| 37 | |
| 38 | private byte fieldDel = '\t'; |
| 39 | |
| 40 | private WritableByteArray out; |
| 41 | |
| 42 | /** |
| 43 | * The constructor that uses the default field delimiter. |
| 44 | */ |
| 45 | public PigStreaming() { |
| 46 | out = new WritableByteArray(); |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * The constructor that accepts a user-specified field |
| 51 | * delimiter. |
| 52 | * |
| 53 | * @param delimiter a <code>String</code> specifying the field |
| 54 | * delimiter. |
| 55 | */ |
| 56 | public PigStreaming(String delimiter) { |
| 57 | this(); |
| 58 | fieldDel = StorageUtil.parseFieldDel(delimiter); |
| 59 | } |
| 60 | |
| 61 | @Override |
| 62 | public WritableByteArray serializeToBytes(Tuple t) throws IOException { |
| 63 | out.reset(); |
| 64 | int sz = t.size(); |
| 65 | for (int i=0; i<sz; i++) { |
| 66 | Object field = t.get(i); |
| 67 | |
| 68 | StorageUtil.putField(out,field); |
| 69 | |
| 70 | if (i == sz - 1) { |
| 71 | // last field in tuple. |
| 72 | out.write(recordDel); |
| 73 | } else { |
| 74 | out.write(fieldDel); |
| 75 | } |
| 76 | } |
| 77 | return out; |
| 78 | } |
| 79 | |
| 80 | @Override |
| 81 | public Tuple deserialize(byte[] bytes, int offset, int length) throws IOException { |
| 82 | return StorageUtil.bytesToTuple(bytes, offset, length, fieldDel); |
| 83 | } |
| 84 | |
| 85 | @Override |
| 86 | public LoadCaster getLoadCaster() throws IOException { |
| 87 | return new Utf8StorageConverter(); |
| 88 | } |
| 89 | |
| 90 | } |
nothing calls this directly
no outgoing calls
no test coverage detected