Tuple implements ITuple, Serializable, Cloneable { public Tuple deepCopy() { return deepCopy(this); } Tuple(Schema schema); @Override Object get(int pos); @Override void set(int pos, Object object); @Override String toString(); static String toString(ITuple tuple); @Override void clear(); @Override Schema getSchema(); @Override Object get(String field); @Override void set(String field, Object object); boolean equals(Object that); int hashCode(); void shallowCopy(ITuple tupleDest); Tuple deepCopy(); Tuple deepCopy(Map<String, FieldClonator> customClonators); static Tuple deepCopy(ITuple tuple); static Tuple deepCopy(ITuple tuple, Map<String, FieldClonator> customClonators); @Override Integer getInteger(int pos); @Override Integer getInteger(String field); @Override Long getLong(int pos); @Override Long getLong(String field); @Override Float getFloat(int pos); @Override Float getFloat(String field); @Override Double getDouble(int pos); @Override Double getDouble(String field); @Override Boolean getBoolean(int pos); @Override Boolean getBoolean(String field); @Override String getString(int pos); @Override String getString(String field);  }
@Test public void testDeepCopy() throws Exception { Schema schema = new Schema("schema", Fields.parse("str1:string,str2:string,b1:bytes,b2:bytes,tuple:com.datasalt.pangool.io.Tuple,object:org.apache.hadoop.io.IntWritable,int:int,null:org.apache.hadoop.io.IntWritable")); Tuple t = new Tuple(schema); t.set("str1", "hola"); t.set("str2", new Utf8("hola")); byte[] data = new byte[]{(byte) 0xab, (byte) 0x12}; ByteBuffer bf = ByteBuffer.wrap(data); t.set("b1", data); t.set("b2", bf); Schema schema2 = new Schema("schema2", Fields.parse("str:string")); Tuple innerT = new Tuple(schema2); innerT.set(0, "pepe"); t.set("int", 4); t.set("null", null); t.set("tuple", innerT); assertIDontKnow(t); t.set("tuple", null); t.set("object", new IntWritable(3)); assertIDontKnow(t); t.set("object", null); t.set("tuple", innerT); t.set("object", new IntWritable(3)); HashMap<String, FieldClonator> clonators = new HashMap<String, FieldClonator>(); clonators.put("tuple", new FieldClonator() { @Override public Object giveMeACopy(Object value) { return ((Tuple) value).deepCopy(); } }); clonators.put("object", new FieldClonator() { @Override public Object giveMeACopy(Object value) { return new IntWritable(((IntWritable) value).get()); } }); assertIsAClone(t, t.deepCopy(clonators)); }
@Test public void testDeepCopy2() throws Exception { int NUM_TUPLES = 200; HashMap<String, FieldClonator> clonators = new HashMap<String, FieldClonator>(); clonators.put("thrift_field", new FieldClonator() { @Override public Object giveMeACopy(Object value) { return ((TBase) value).deepCopy(); } }); clonators.put("my_avro", new FieldClonator() { @Override public Object giveMeACopy(Object value) { GenericData.Record r = (GenericData.Record) value; GenericData.Record copy = new GenericData.Record(r, true); return copy; } }); Tuple t = new Tuple(decorateWithNullables(SCHEMA)); for (int i = 0; i < NUM_TUPLES; i++) { fillTuple(true, t); assertIsAClone(t, t.deepCopy(clonators)); } }