diff --git hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValue.java hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValue.java index a384773..9697a81 100644 --- hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValue.java +++ hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValue.java @@ -1649,7 +1649,7 @@ public class KeyValue implements Cell, HeapSize, Cloneable { this.bytes, getQualifierOffset(), getQualifierLength()); } - public boolean matchingQualifier(final KeyValue other) { + public boolean matchingQualifier(final Cell other) { return matchingQualifier(other.getQualifierArray(), other.getQualifierOffset(), other.getQualifierLength()); } @@ -1663,7 +1663,7 @@ public class KeyValue implements Cell, HeapSize, Cloneable { this.bytes, getRowOffset(), getRowLength()); } - public boolean matchingRow(KeyValue other) { + public boolean matchingRow(Cell other) { return matchingRow(other.getRowArray(), other.getRowOffset(), other.getRowLength()); } @@ -1693,7 +1693,7 @@ public class KeyValue implements Cell, HeapSize, Cloneable { public boolean matchingColumn(final byte [] family, final int foffset, final int flength, final byte [] qualifier, final int qoffset, final int qlength) { int rl = getRowLength(); - int o = getFamilyOffset(rl); + int o = getFamilyOffset(); int fl = getFamilyLength(o); if (!Bytes.equals(family, foffset, flength, this.bytes, o, fl)) { return false; @@ -2088,10 +2088,10 @@ public class KeyValue implements Cell, HeapSize, Cloneable { return Long.MAX_VALUE; } - public int compareTimestamps(final KeyValue left, final KeyValue right) { + public int compareTimestamps(final Cell left, final Cell right) { // Compare timestamps - long ltimestamp = left.getTimestamp(left.getKeyLength()); - long rtimestamp = right.getTimestamp(right.getKeyLength()); + long ltimestamp = left.getTimestamp(); + long rtimestamp = right.getTimestamp(); return compareTimestamps(ltimestamp, rtimestamp); } @@ -2100,7 +2100,7 @@ public class KeyValue implements Cell, HeapSize, Cloneable { * @param right * @return Result comparing rows. */ - public int compareRows(final KeyValue left, final KeyValue right) { + public int compareRows(final Cell left, final Cell right) { return compareRows(left.getRowArray(),left.getRowOffset(), left.getRowLength(), right.getRowArray(), right.getRowOffset(), right.getRowLength()); } @@ -2120,17 +2120,33 @@ public class KeyValue implements Cell, HeapSize, Cloneable { return Bytes.compareTo(left, loffset, llength, right, roffset, rlength); } - int compareColumns(final KeyValue left, final short lrowlength, - final KeyValue right, final short rrowlength) { - int lfoffset = left.getFamilyOffset(lrowlength); - int rfoffset = right.getFamilyOffset(rrowlength); - int lclength = left.getTotalColumnLength(lrowlength,lfoffset); - int rclength = right.getTotalColumnLength(rrowlength, rfoffset); - int lfamilylength = left.getFamilyLength(lfoffset); - int rfamilylength = right.getFamilyLength(rfoffset); - return compareColumns(left.getBuffer(), lfoffset, - lclength, lfamilylength, - right.getBuffer(), rfoffset, rclength, rfamilylength); + int compareColumns(final Cell left, final short lrowlength, + final Cell right, final short rrowlength) { + int lfoffset = left.getFamilyOffset(); + int rfoffset = right.getFamilyOffset(); + int lclength = left.getQualifierLength(); + int rclength = right.getQualifierLength(); + int lfamilylength = left.getFamilyLength(); + int rfamilylength = right.getFamilyLength(); + int diff = compareFamilies(left.getFamilyArray(), lfoffset, lfamilylength, right.getFamilyArray(), rfoffset, rfamilylength); + if(diff != 0) { + return diff; + } else { + return compareColumns(left.getQualifierArray(), left.getQualifierOffset(), lclength, + right.getQualifierArray(), right.getQualifierOffset(), rclength); + } + } + + protected int compareFamilies(final byte[] left, final int loffset, final int lfamilylength, final byte[] right, + final int roffset, final int rfamilylength) { + int diff = Bytes.compareTo(left, loffset, lfamilylength, right, roffset, rfamilylength); + return diff; + } + + protected int compareColumns(final byte[] left, final int loffset, final int lquallength, final byte[] right, + final int roffset, final int rquallength) { + int diff = Bytes.compareTo(left, loffset, lquallength, right, roffset, rquallength); + return diff; } protected int compareColumns( @@ -2303,14 +2319,14 @@ public class KeyValue implements Cell, HeapSize, Cloneable { * @param right * @return True if same row and column. */ - public boolean matchingRowColumn(final KeyValue left, - final KeyValue right) { + public boolean matchingRowColumn(final Cell left, + final Cell right) { short lrowlength = left.getRowLength(); short rrowlength = right.getRowLength(); // TsOffset = end of column data. just comparing Row+CF length of each - if ((left.getTimestampOffset() - left.getOffset()) != - (right.getTimestampOffset() - right.getOffset())) { + if ((left.getRowLength() + left.getFamilyLength() + left.getQualifierLength()) != + (right.getRowLength() + right.getFamilyLength() + right.getQualifierLength())) { return false; } @@ -2318,15 +2334,21 @@ public class KeyValue implements Cell, HeapSize, Cloneable { return false; } - int lfoffset = left.getFamilyOffset(lrowlength); - int rfoffset = right.getFamilyOffset(rrowlength); - int lclength = left.getTotalColumnLength(lrowlength,lfoffset); - int rclength = right.getTotalColumnLength(rrowlength, rfoffset); - int lfamilylength = left.getFamilyLength(lfoffset); - int rfamilylength = right.getFamilyLength(rfoffset); - int ccRes = compareColumns(left.getBuffer(), lfoffset, lclength, lfamilylength, - right.getBuffer(), rfoffset, rclength, rfamilylength); - return ccRes == 0; + int lfoffset = left.getFamilyOffset(); + int rfoffset = right.getFamilyOffset(); + int lclength = left.getQualifierLength(); + int rclength = right.getQualifierLength(); + int lfamilylength = left.getFamilyLength(); + int rfamilylength = right.getFamilyLength(); + int diff = compareFamilies(left.getFamilyArray(), lfoffset, lfamilylength, + right.getFamilyArray(), rfoffset, rfamilylength); + if(diff != 0) { + return false; + } else { + diff = compareColumns(left.getQualifierArray(), left.getQualifierOffset(), lclength, + right.getQualifierArray(), right.getQualifierOffset(), rclength); + return diff == 0; + } } /** @@ -2335,7 +2357,7 @@ public class KeyValue implements Cell, HeapSize, Cloneable { * @param right * @return True if rows match. */ - public boolean matchingRows(final KeyValue left, final KeyValue right) { + public boolean matchingRows(final Cell left, final Cell right) { short lrowlength = left.getRowLength(); short rrowlength = right.getRowLength(); return matchingRows(left, lrowlength, right, rrowlength); @@ -2348,8 +2370,8 @@ public class KeyValue implements Cell, HeapSize, Cloneable { * @param rrowlength * @return True if rows match. */ - private boolean matchingRows(final KeyValue left, final short lrowlength, - final KeyValue right, final short rrowlength) { + private boolean matchingRows(final Cell left, final short lrowlength, + final Cell right, final short rrowlength) { return lrowlength == rrowlength && matchingRows(left.getRowArray(), left.getRowOffset(), lrowlength, right.getRowArray(), right.getRowOffset(), rrowlength); @@ -2877,14 +2899,15 @@ public class KeyValue implements Cell, HeapSize, Cloneable { /** * Comparator that compares row component only of a KeyValue. */ - public static class RowOnlyComparator implements Comparator { + public static class RowOnlyComparator implements Comparator { final KVComparator comparator; public RowOnlyComparator(final KVComparator c) { this.comparator = c; } - public int compare(KeyValue left, KeyValue right) { + @Override + public int compare(Cell left, Cell right) { return comparator.compareRows(left, right); } }