You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by st...@apache.org on 2009/07/08 06:06:38 UTC
svn commit: r792025 - in /hadoop/hbase/trunk: CHANGES.txt
src/java/org/apache/hadoop/hbase/KeyValue.java
src/test/org/apache/hadoop/hbase/TestKeyValue.java
Author: stack
Date: Wed Jul 8 04:06:37 2009
New Revision: 792025
URL: http://svn.apache.org/viewvc?rev=792025&view=rev
Log:
HBASE-1622 Make KeyValue implement the Comparable interface to make it work with Cascading
Modified:
hadoop/hbase/trunk/CHANGES.txt
hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/KeyValue.java
hadoop/hbase/trunk/src/test/org/apache/hadoop/hbase/TestKeyValue.java
Modified: hadoop/hbase/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/CHANGES.txt?rev=792025&r1=792024&r2=792025&view=diff
==============================================================================
--- hadoop/hbase/trunk/CHANGES.txt (original)
+++ hadoop/hbase/trunk/CHANGES.txt Wed Jul 8 04:06:37 2009
@@ -450,6 +450,8 @@
HBASE-1620 Need to use special StoreScanner constructor for major compactions
(passed sf, no caching, etc) (Jon Gray via Stack)
HBASE-1624 Don't sort Puts if only one in list in HCM#processBatchOfRows
+ HBASE-1622 Make KeyValue implement the Comparable interface to make it work
+ with Cascading (Erik Holstad via Stack)
OPTIMIZATIONS
HBASE-1412 Change values for delete column and column family in KeyValue
Modified: hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/KeyValue.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/KeyValue.java?rev=792025&r1=792024&r2=792025&view=diff
==============================================================================
--- hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/KeyValue.java (original)
+++ hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/KeyValue.java Wed Jul 8 04:06:37 2009
@@ -30,7 +30,7 @@
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.ClassSize;
import org.apache.hadoop.io.RawComparator;
-import org.apache.hadoop.io.Writable;
+import org.apache.hadoop.io.WritableComparable;
/**
* An HBase Key/Value. Instances of this class are immutable. They are not
@@ -53,7 +53,7 @@
* <p>TODO: Group Key-only comparators and operations into a Key class, just
* for neatness sake, if can figure what to call it.
*/
-public class KeyValue implements Writable, HeapSize {
+public class KeyValue implements WritableComparable<KeyValue>, HeapSize {
static final Log LOG = LogFactory.getLog(KeyValue.class);
/**
@@ -61,7 +61,8 @@
*/
public static final char COLUMN_FAMILY_DELIMITER = ':';
- public static final byte[] COLUMN_FAMILY_DELIM_ARRAY = new byte[]{COLUMN_FAMILY_DELIMITER};
+ public static final byte[] COLUMN_FAMILY_DELIM_ARRAY =
+ new byte[]{COLUMN_FAMILY_DELIMITER};
/**
* Comparator for plain key/values; i.e. non-catalog table key/values.
@@ -1794,6 +1795,7 @@
(2 * Bytes.SIZEOF_INT));
}
+ // WritableComparable
// Writable
public void readFields(final DataInput in) throws IOException {
this.length = in.readInt();
@@ -1806,4 +1808,10 @@
out.writeInt(this.length);
out.write(this.bytes, this.offset, this.length);
}
+ // Comparable
+ public int compareTo(KeyValue that) {
+ return KEY_COMPARATOR.compare(this.bytes, this.offset, this.length,
+ that.getBuffer(), that.getOffset(), that.getLength());
+ }
+
}
Modified: hadoop/hbase/trunk/src/test/org/apache/hadoop/hbase/TestKeyValue.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/test/org/apache/hadoop/hbase/TestKeyValue.java?rev=792025&r1=792024&r2=792025&view=diff
==============================================================================
--- hadoop/hbase/trunk/src/test/org/apache/hadoop/hbase/TestKeyValue.java (original)
+++ hadoop/hbase/trunk/src/test/org/apache/hadoop/hbase/TestKeyValue.java Wed Jul 8 04:06:37 2009
@@ -276,4 +276,27 @@
// TODO actually write this test!
}
-}
\ No newline at end of file
+
+ public void testComparableInterface() {
+ byte [] row1 = Bytes.toBytes("row1");
+ byte [] row2 = Bytes.toBytes("row2");
+ byte [] fam1 = Bytes.toBytes("fam1");
+ byte [] fam2 = Bytes.toBytes("fam2");
+ byte [] qf1 = Bytes.toBytes("qf1");
+ byte [] qf2 = Bytes.toBytes("qf2");
+ byte [] val1 = Bytes.toBytes("val1");
+ KeyValue kv1 = new KeyValue(row1, fam1, qf1, val1);
+ KeyValue kv2 = new KeyValue(row2, fam2, qf2, val1);
+ int res = 0;
+
+ res = kv1.compareTo(kv2);
+ assertTrue(res < 0);
+
+ res = kv2.compareTo(kv1);
+ assertTrue(res > 0);
+
+ res = kv1.compareTo(kv1);
+ assertTrue(res == 0);
+ }
+
+}