public Tuple readTuple(DataInput in) throws IOException { return readTuple(in, in.readByte()); }
@Override public void readFields(DataInput in) throws IOException { boolean nullness = in.readBoolean(); setNull(nullness); // Free up the previous value for GC mValue = null; if (!nullness) { mValue = bis.readTuple(in); } setIndex(in.readByte()); }
/** * Compare two NullableTuples as raw bytes. If neither are null, then * IntWritable.compare() is used. If both are null then the indices are * compared. Otherwise the null one is defined to be less. */ @Override public int compare(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2) { int rc = 0; Tuple t1; Tuple t2; // This can't be done on the raw data. Users are allowed to // implement their own versions of tuples, which means we have no // idea what the underlying representation is. So step one is to // instantiate each object as a tuple. try { t1 = bis.readTuple(new DataInputStream(new ByteArrayInputStream(b1, s1, l1))); t2 = bis.readTuple(new DataInputStream(new ByteArrayInputStream(b2, s2, l2))); } catch (IOException ioe) { mLog.error("Unable to instantiate tuples for comparison: " + ioe.getMessage()); throw new RuntimeException(ioe.getMessage(), ioe); } rc = compareTuple(t1, t2); //TODO think about how SchemaTuple could speed this up // handle PIG-927. If tuples are equal but any field inside tuple is null, // then we do not merge keys if indices are not same if (rc == 0 && mHasNullField) { rc = ((NullableTuple) t1).getIndex() - ((NullableTuple) t2).getIndex(); } return rc; }