protected int compare(Map<String, Object> val, Map<String, Object> themVal) { return DataType.compare(val, themVal, DataType.MAP, DataType.MAP); }
/** * Compare two byte arrays. Comparison is done first using byte values then * length. So "g" will be greater than "abcdefg", but "hello worlds" is * greater than "hello world". If the other object is not a DataByteArray, * {@link DataType#compare} will be called. * * @param other Other object to compare to. * @return -1 if less than, 1 if greater than, 0 if equal. */ public int compareTo(Object other) { if (other instanceof DataByteArray) { DataByteArray dba = (DataByteArray) other; return compare(mData, dba.mData); } else { return DataType.compare(this, other); } }
@Override public int compareTo(Object other) { if (other instanceof Tuple) { Tuple t = (Tuple) other; int mySz = mFields.size(); int tSz = t.size(); if (tSz < mySz) { return 1; } else if (tSz > mySz) { return -1; } else { for (int i = 0; i < mySz; i++) { try { int c = DataType.compare(mFields.get(i), t.get(i)); if (c != 0) { return c; } } catch (ExecException e) { throw new RuntimeException("Unable to compare tuples", e); } } return 0; } } else { return DataType.compare(this, other); } }
/** /** * Compare two objects to each other. This function is necessary * because there's no super class that implements compareTo. This * function provides an (arbitrary) ordering of objects of different * types as follows: NULL < BOOLEAN < BYTE < INTEGER < LONG < * FLOAT < DOUBLE < DATETIME < BYTEARRAY < STRING < MAP < * TUPLE < BAG. No other functions should implement this cross * object logic. They should call this function for it instead. * @param o1 First object * @param o2 Second object * @return -1 if o1 is less, 0 if they are equal, 1 if o2 is less. */ public static int compare(Object o1, Object o2) { byte dt1 = findType(o1); byte dt2 = findType(o2); return compare(o1, o2, dt1, dt2); }
@Override public int compareTo(final Object o) { if (this == o) return 0; if (o instanceof AvroBagWrapper) { @SuppressWarnings("rawtypes") AvroBagWrapper bOther = (AvroBagWrapper) o; return GenericData.get().compare(theArray, bOther.theArray, theArray.getSchema()); } else { return DataType.compare(this, o); } }
@Override public int compare(Tuple o1, Tuple o2) { int ret = 0; if (o1 == null) { ret = -1; } else if (o2 == null) { ret = 1; } else { try { Object field1 = o1.get(fieldNum); Object field2 = o2.get(fieldNum); if (!typeFound) { datatype = DataType.findType(field1); if(datatype != DataType.NULL) { typeFound = true; } } ret = DataType.compare(field1, field2, datatype, datatype); } catch (ExecException e) { throw new RuntimeException("Error while comparing o1:" + o1 + " and o2:" + o2, e); } } return isDescOrder ? ret : ret * -1; } }
private boolean hasSameKey(Tuple t1, Tuple t2) { // Have to break the tuple down and compare it field to field. int sz1 = t1 == null ? 0 : t1.size(); int sz2 = t2 == null ? 0 : t2.size(); if (sz2 != sz1) { return false; } for (int i = 0; i < sz1 - 2; i++) { try { int c = DataType.compare(t1.get(i), t2.get(i)); if (c != 0) { return false; } } catch (ExecException e) { throw new RuntimeException("Unable to compare tuples", e); } } return true; }
@SuppressWarnings("unchecked") private int compareBinInterSedesMap(ByteBuffer bb1, ByteBuffer bb2, byte dt1, byte dt2) throws ExecException, IOException { int s1 = bb1.position(); int s2 = bb2.position(); int l1 = bb1.remaining(); int l2 = bb2.remaining(); // first compare sizes int bsz1 = readSize(bb1, dt1); int bsz2 = readSize(bb2, dt2); if (bsz1 > bsz2) return 1; else if (bsz1 < bsz2) return -1; else { DataInputBuffer buffer1 = new DataInputBuffer(); DataInputBuffer buffer2 = new DataInputBuffer(); buffer1.reset(bb1.array(), s1, l1); buffer2.reset(bb2.array(), s2, l2); Map<String, Object> map1 = (Map<String, Object>) mSedes.readDatum(buffer1, dt1); Map<String, Object> map2 = (Map<String, Object>) mSedes.readDatum(buffer2, dt2); bb1.position(buffer1.getPosition()); bb2.position(buffer2.getPosition()); return DataType.compare(map1, map2, DataType.MAP, DataType.MAP); } }
@SuppressWarnings("unchecked") @Override public int compareTo(Object other) { if (isSpecificSchemaTuple(other)) { return compareToSpecific((T)other); } if (other instanceof SchemaTuple<?>) { return compareTo((SchemaTuple<?>)other, false); } if (other instanceof Tuple) { return compareTo((Tuple)other, false); } return DataType.compare(this, other); }
private int compareTuple(Tuple t1, Tuple t2) { int sz1 = t1.size(); int sz2 = t2.size(); if (sz2 < sz1) { return 1; } else if (sz2 > sz1) { return -1; } else { for (int i = 0; i < sz1; i++) { try { int c = DataType.compare(t1.get(i), t2.get(i)); if (c != 0) { if (!mWholeTuple && !mAsc[i]) c *= -1; else if (mWholeTuple && !mAsc[0]) c *= -1; return c; } } catch (ExecException e) { throw new RuntimeException("Unable to compare tuples", e); } } return 0; } } }
private int compareTuple(Tuple t1, Tuple t2) { int sz1 = t1.size(); int sz2 = t2.size(); if (sz2 < sz1) { return 1; } else if (sz2 > sz1) { return -1; } else { for (int i = 0; i < sz1; i++) { try { int c = DataType.compare(t1.get(i), t2.get(i)); if (c != 0) { if (!mWholeTuple && !mAsc[i]) c *= -1; else if (mWholeTuple && !mAsc[0]) c *= -1; return c; } } catch (ExecException e) { throw new RuntimeException("Unable to compare tuples", e); } } return 0; } }
private int compareTuple(Tuple t1, Tuple t2) { mHasNullField = false; int sz1 = t1.size(); int sz2 = t2.size(); if (sz2 < sz1) { return 1; } else if (sz2 > sz1) { return -1; } else { for (int i = 0; i < sz1; i++) { try { Object o1 = t1.get(i); Object o2 = t2.get(i); if (o1==null || o2==null) mHasNullField = true; int c = DataType.compare(o1, o2); if (c != 0) { if (!mWholeTuple && !mAsc[i]) c *= -1; else if (mWholeTuple && !mAsc[0]) c *= -1; return c; } } catch (ExecException e) { throw new RuntimeException("Unable to compare tuples", e); } } return 0; } }
protected int compareToSpecific(T t) { int i = compareSize(t); if (i != 0) { return i; } i = super.compareToSpecific(t); if (i != 0) { return i; } for (int z = 0; z < appendedFieldsSize(); z++) { try { i = DataType.compare(getAppendedField(z), t.getAppendedField(z)); } catch (ExecException e) { throw new RuntimeException("Unable to get append", e); } if (i != 0) { return i; } } return 0; }
int c = DataType.compare(get(i), t.get(i));
@SuppressWarnings("unchecked") @Override public int compareTo(Object other) { if (this == other) return 0; if (other instanceof DataBag) { DataBag bOther = (DataBag) other; if (this.size() != bOther.size()) { if (this.size() > bOther.size()) return 1; else return -1; } // if we got this far, both bags should have same size // make a LimitedSortedBag for the other bag with same comparator and limit // so that both bag are sorted and we can loop through both iterators DataBag otherCloneDataBag = new LimitedSortedDataBag(mComp, limit); otherCloneDataBag.addAll((DataBag) other); Iterator<Tuple> thisIt = this.iterator(); Iterator<Tuple> otherIt = otherCloneDataBag.iterator(); while (thisIt.hasNext() && otherIt.hasNext()) { Tuple thisT = thisIt.next(); Tuple otherT = otherIt.next(); int c = thisT.compareTo(otherT); if (c != 0) return c; } return 0; // if we got this far, they must be equal } else { return DataType.compare(this, other); } }
protected int compareTo(SchemaTuple<?> t, boolean checkType) { if (checkType && getClass() == t.getClass()) { return compareToSpecific((T)t); } int i = super.compareTo(t, false); if (i != 0) { return i; } if (appendedFieldsSize() > 0) { int m = schemaSize(); for (int k = 0; k < size() - schemaSize(); k++) { try { i = DataType.compare(getAppendedField(k), t.get(m++)); } catch (ExecException e) { throw new RuntimeException("Unable to get append value", e); } if (i != 0) { return i; } } } return 0; }
@Override public int compareTo(Object o) { IndexedKey that = (IndexedKey) o; int res = index - that.getIndex(); if (res > 0) { return 1; } else if (res < 0) { return -1; } else { if (useSecondaryKey) { Tuple thisCompoundKey = (Tuple) key; Tuple thatCompoundKey = (Tuple)that.getKey(); PigSecondaryKeyComparatorSpark comparator = new PigSecondaryKeyComparatorSpark(secondarySortOrder); return comparator.compareCompoundKey(thisCompoundKey, thatCompoundKey); } else { return DataType.compare(key, that.getKey()); } } }
for (int i = 0; i < sz1; i++) { try { int c = DataType.compare(t1.get(i), t2.get(i)); if (c != 0) { if (!mAsc[i]) c *= -1;
@Override public int compare(Object o1, Object o2) { NullableBytesWritable nbw1 = (NullableBytesWritable)o1; NullableBytesWritable nbw2 = (NullableBytesWritable)o2; int rc = 0; // If either are null, handle differently. if (!nbw1.isNull() && !nbw2.isNull()) { rc = DataType.compare(nbw1.getValueAsPigType(), nbw2.getValueAsPigType()); } else { // Two nulls are equal if indices are same if (nbw1.isNull() && nbw2.isNull()) { rc = nbw1.getIndex() - nbw2.getIndex(); } else if (nbw1.isNull()) rc = -1; else rc = 1; } if (!mAsc[0]) rc *= -1; return rc; }