Author: rohini Date: Fri Aug 11 15:49:27 2017 New Revision: 1804812 URL: http://svn.apache.org/viewvc?rev=1804812&view=rev Log: PIG-5288: Improve performance of PigTextRawBytesComparator (rohini)
Modified: pig/trunk/CHANGES.txt pig/trunk/src/org/apache/pig/backend/hadoop/executionengine/mapReduceLayer/PigWritableComparators.java pig/trunk/src/org/apache/pig/impl/io/NullableText.java Modified: pig/trunk/CHANGES.txt URL: http://svn.apache.org/viewvc/pig/trunk/CHANGES.txt?rev=1804812&r1=1804811&r2=1804812&view=diff ============================================================================== --- pig/trunk/CHANGES.txt (original) +++ pig/trunk/CHANGES.txt Fri Aug 11 15:49:27 2017 @@ -24,6 +24,8 @@ INCOMPATIBLE CHANGES IMPROVEMENTS +PIG-5288: Improve performance of PigTextRawBytesComparator (rohini) + PIG-5287: bump jython to 2.7.1 (dbist13 via rohini) PIG-5264: Remove deprecated keys from PigConfiguration (nkollar via rohini) Modified: pig/trunk/src/org/apache/pig/backend/hadoop/executionengine/mapReduceLayer/PigWritableComparators.java URL: http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/backend/hadoop/executionengine/mapReduceLayer/PigWritableComparators.java?rev=1804812&r1=1804811&r2=1804812&view=diff ============================================================================== --- pig/trunk/src/org/apache/pig/backend/hadoop/executionengine/mapReduceLayer/PigWritableComparators.java (original) +++ pig/trunk/src/org/apache/pig/backend/hadoop/executionengine/mapReduceLayer/PigWritableComparators.java Fri Aug 11 15:49:27 2017 @@ -19,6 +19,7 @@ package org.apache.pig.backend.hadoop.ex import org.apache.hadoop.io.WritableComparator; import org.apache.pig.impl.io.NullablePartitionWritable; +import org.apache.pig.impl.io.NullableText; public class PigWritableComparators { @@ -134,6 +135,26 @@ public class PigWritableComparators { public int compare(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2) { return WritableComparator.compareBytes(b1, s1, l1, b2, s2, l2); } + + @Override + public int compare(Object o1, Object o2) { + NullableText nt1 = (NullableText)o1; + NullableText nt2 = (NullableText)o2; + int rc = 0; + + // If either are null, handle differently. + if (!nt1.isNull() && !nt2.isNull()) { + rc = nt1.getText().compareTo(nt2.getText()); + } else { + // Two nulls are equal if indices are same + if (nt1.isNull() && nt2.isNull()) { + rc = nt1.getIndex() - nt2.getIndex(); + } + else if (nt1.isNull()) rc = -1; + else rc = 1; + } + return rc; + } } public static class PigBytesRawBytesComparator extends PigBytesRawComparator { @@ -146,6 +167,7 @@ public class PigWritableComparators { public int compare(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2) { return WritableComparator.compareBytes(b1, s1, l1, b2, s2, l2); } + } public static class PigTupleSortBytesComparator extends PigTupleSortComparator { Modified: pig/trunk/src/org/apache/pig/impl/io/NullableText.java URL: http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/impl/io/NullableText.java?rev=1804812&r1=1804811&r2=1804812&view=diff ============================================================================== --- pig/trunk/src/org/apache/pig/impl/io/NullableText.java (original) +++ pig/trunk/src/org/apache/pig/impl/io/NullableText.java Fri Aug 11 15:49:27 2017 @@ -42,7 +42,12 @@ public class NullableText extends PigNul mValue = new Text(string); } + @Override public Object getValueAsPigType() { return isNull() ? null : ((Text)mValue).toString(); } + + public Text getText() { + return isNull() ? null : (Text)mValue; + } }