public void configure(JobConf job) { super.setConf(job); } }
private int compareByteSequence(byte[] first, int start1, int end1, byte[] second, int start2, int end2, KeyDescription key) { if (start1 == -1) { if (key.reverse) { return 1; } return -1; } if (start2 == -1) { if (key.reverse) { return -1; } return 1; } int compareResult = 0; if (!key.numeric) { compareResult = compareBytes(first, start1, end1-start1 + 1, second, start2, end2 - start2 + 1); } if (key.numeric) { compareResult = numericalCompare (first, start1, end1, second, start2, end2); } if (key.reverse) { return -compareResult; } return compareResult; }
private int oneNegativeCompare(byte[] a, int start1, int end1, byte[] b, int start2, int end2) { //here a[] is negative and b[] is positive //We have to ascertain whether the number contains any digits. //If it does, then it is a smaller number for sure. If not, //then we need to scan b[] to find out whether b[] has a digit //If b[] does contain a digit, then b[] is certainly //greater. If not, that is, both a[] and b[] don't contain //digits then they should be considered equal. if (!isZero(a, start1, end1)) { return -1; } //reached here - this means that a[] is a ZERO if (!isZero(b, start2, end2)) { return -1; } //reached here - both numbers are basically ZEROs and hence //they should compare equal return 0; }
public void testWithoutMRJob(String keySpec, int expect) throws Exception { KeyFieldBasedComparator<Void, Void> keyFieldCmp = new KeyFieldBasedComparator<Void, Void>(); conf.set("mapreduce.partition.keycomparator.options", keySpec); keyFieldCmp.setConf(conf); int result = keyFieldCmp.compare(line1_bytes, 0, line1_bytes.length, line2_bytes, 0, line2_bytes.length); if ((expect >= 0 && result < 0) || (expect < 0 && result >= 0)) fail(); } }
if (first_b != NEGATIVE) { return oneNegativeCompare(a, start1 + 1, end1, b, start2, end2); if (first_a != NEGATIVE) { return -oneNegativeCompare(b, start2+1, end2, a, start1, end1); if (!isdigit(a[i]) || a[i] != b[j]) { break; if ((first_a == DECIMAL && (!isdigit(first_b) || j > end2)) || (first_b == DECIMAL && (!isdigit(first_a) || i > end1))) { return ((mul < 0) ? -decimalCompare(a, i, end1, b, j, end2) : decimalCompare(a, i, end1, b, j, end2)); if (isdigit(a[i++])) { numRemainDigits_a++; } else break; if (isdigit(b[j++])) { numRemainDigits_b++; } else break;
return compareBytes(b1, s1 + n1, l1 - n1, b2, s2 + n2, l2 - n2); lengthIndicesSecond, keySpec); int result; if ((result = compareByteSequence(b1, startCharFirst, endCharFirst, b2, startCharSecond, endCharSecond, keySpec)) != 0) { return result;
if (i > end1) { return -decimalCompare1(b, ++j, end2); return decimalCompare1(a, ++i, end1); if (isdigit(a[i]) && isdigit(b[j])) { return a[i] - b[j]; if (isdigit(a[i])) { return 1; if (isdigit(b[j])) { return -1; return -decimalCompare1(b, j, end2); return decimalCompare1(a, i, end1); return decimalCompare1(a, ++i, end1); return -decimalCompare1(b, ++j, end2);
private int decimalCompare1(byte[] a, int i, int end) { while (i <= end) { if (a[i] == ZERO) { i++; continue; } if (isdigit(a[i])) { return 1; } else { return 0; } } return 0; }
if (first_b != NEGATIVE) { return oneNegativeCompare(a, start1 + 1, end1, b, start2, end2); if (first_a != NEGATIVE) { return -oneNegativeCompare(b, start2+1, end2, a, start1, end1); if (!isdigit(a[i]) || a[i] != b[j]) { break; if ((first_a == DECIMAL && (!isdigit(first_b) || j > end2)) || (first_b == DECIMAL && (!isdigit(first_a) || i > end1))) { return ((mul < 0) ? -decimalCompare(a, i, end1, b, j, end2) : decimalCompare(a, i, end1, b, j, end2)); if (isdigit(a[i++])) { numRemainDigits_a++; } else break; if (isdigit(b[j++])) { numRemainDigits_b++; } else break;
return compareBytes(b1, s1 + n1, l1 - n1, b2, s2 + n2, l2 - n2); lengthIndicesSecond, keySpec); int result; if ((result = compareByteSequence(b1, startCharFirst, endCharFirst, b2, startCharSecond, endCharSecond, keySpec)) != 0) { return result;
if (i > end1) { return -decimalCompare1(b, ++j, end2); return decimalCompare1(a, ++i, end1); if (isdigit(a[i]) && isdigit(b[j])) { return a[i] - b[j]; if (isdigit(a[i])) { return 1; if (isdigit(b[j])) { return -1; return -decimalCompare1(b, j, end2); return decimalCompare1(a, i, end1); return decimalCompare1(a, ++i, end1); return -decimalCompare1(b, ++j, end2);
private int decimalCompare1(byte[] a, int i, int end) { while (i <= end) { if (a[i] == ZERO) { i++; continue; } if (isdigit(a[i])) { return 1; } else { return 0; } } return 0; }
public void testWithoutMRJob(String keySpec, int expect) throws Exception { KeyFieldBasedComparator<Void, Void> keyFieldCmp = new KeyFieldBasedComparator<Void, Void>(); conf.set("mapreduce.partition.keycomparator.options", keySpec); keyFieldCmp.setConf(conf); int result = keyFieldCmp.compare(line1_bytes, 0, line1_bytes.length, line2_bytes, 0, line2_bytes.length); if ((expect >= 0 && result < 0) || (expect < 0 && result >= 0)) fail(); } }
if (first_b != NEGATIVE) { return oneNegativeCompare(a, start1 + 1, end1, b, start2, end2); if (first_a != NEGATIVE) { return -oneNegativeCompare(b, start2+1, end2, a, start1, end1); if (!isdigit(a[i]) || a[i] != b[j]) { break; if ((first_a == DECIMAL && (!isdigit(first_b) || j > end2)) || (first_b == DECIMAL && (!isdigit(first_a) || i > end1))) { return ((mul < 0) ? -decimalCompare(a, i, end1, b, j, end2) : decimalCompare(a, i, end1, b, j, end2)); if (isdigit(a[i++])) { numRemainDigits_a++; } else break; if (isdigit(b[j++])) { numRemainDigits_b++; } else break;
private int compareByteSequence(byte[] first, int start1, int end1, byte[] second, int start2, int end2, KeyDescription key) { if (start1 == -1) { if (key.reverse) { return 1; } return -1; } if (start2 == -1) { if (key.reverse) { return -1; } return 1; } int compareResult = 0; if (!key.numeric) { compareResult = compareBytes(first, start1, end1-start1 + 1, second, start2, end2 - start2 + 1); } if (key.numeric) { compareResult = numericalCompare (first, start1, end1, second, start2, end2); } if (key.reverse) { return -compareResult; } return compareResult; }
return compareBytes(b1, s1 + n1, l1 - n1, b2, s2 + n2, l2 - n2); lengthIndicesSecond, keySpec); int result; if ((result = compareByteSequence(b1, startCharFirst, endCharFirst, b2, startCharSecond, endCharSecond, keySpec)) != 0) { return result;
if (i > end1) { return -decimalCompare1(b, ++j, end2); return decimalCompare1(a, ++i, end1); if (isdigit(a[i]) && isdigit(b[j])) { return a[i] - b[j]; if (isdigit(a[i])) { return 1; if (isdigit(b[j])) { return -1; return -decimalCompare1(b, j, end2); return decimalCompare1(a, i, end1); return decimalCompare1(a, ++i, end1); return -decimalCompare1(b, ++j, end2);
private int decimalCompare1(byte[] a, int i, int end) { while (i <= end) { if (a[i] == ZERO) { i++; continue; } if (isdigit(a[i])) { return 1; } else { return 0; } } return 0; }
public void configure(JobConf job) { super.setConf(job); } }
private int oneNegativeCompare(byte[] a, int start1, int end1, byte[] b, int start2, int end2) { //here a[] is negative and b[] is positive //We have to ascertain whether the number contains any digits. //If it does, then it is a smaller number for sure. If not, //then we need to scan b[] to find out whether b[] has a digit //If b[] does contain a digit, then b[] is certainly //greater. If not, that is, both a[] and b[] don't contain //digits then they should be considered equal. if (!isZero(a, start1, end1)) { return -1; } //reached here - this means that a[] is a ZERO if (!isZero(b, start2, end2)) { return -1; } //reached here - both numbers are basically ZEROs and hence //they should compare equal return 0; }