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 2013/07/29 20:53:50 UTC
svn commit: r1508176 - in /hbase/branches/0.94/src:
main/java/org/apache/hadoop/hbase/client/Result.java
test/java/org/apache/hadoop/hbase/client/TestResult.java
Author: stack
Date: Mon Jul 29 18:53:49 2013
New Revision: 1508176
URL: http://svn.apache.org/r1508176
Log:
HBASE-9032 Result.getBytes() returns null if backed by KeyValue array
Modified:
hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/client/Result.java
hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/client/TestResult.java
Modified: hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/client/Result.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/client/Result.java?rev=1508176&r1=1508175&r2=1508176&view=diff
==============================================================================
--- hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/client/Result.java (original)
+++ hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/client/Result.java Mon Jul 29 18:53:49 2013
@@ -36,6 +36,7 @@ import org.apache.hadoop.hbase.KeyValue.
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.hbase.io.WritableWithSize;
import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.hadoop.io.DataOutputBuffer;
import org.apache.hadoop.io.Writable;
/**
@@ -401,6 +402,22 @@ public class Result implements Writable,
* @return pointer to raw binary of Result
*/
public ImmutableBytesWritable getBytes() {
+ if (this.bytes == null && this.kvs != null) {
+ int totalLen = 0;
+ for(KeyValue kv : kvs) {
+ totalLen += kv.getLength() + Bytes.SIZEOF_INT;
+ }
+ DataOutputBuffer out = new DataOutputBuffer(totalLen);
+ try {
+ for(KeyValue kv : kvs) {
+ kv.write(out);
+ }
+ out.close();
+ } catch (IOException e) {
+ throw new RuntimeException("IOException in Result.getBytes()", e);
+ }
+ this.bytes = new ImmutableBytesWritable(out.getData(), 0, out.getLength());
+ }
return this.bytes;
}
Modified: hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/client/TestResult.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/client/TestResult.java?rev=1508176&r1=1508175&r2=1508176&view=diff
==============================================================================
--- hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/client/TestResult.java (original)
+++ hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/client/TestResult.java Mon Jul 29 18:53:49 2013
@@ -21,8 +21,10 @@
package org.apache.hadoop.hbase.client;
import junit.framework.TestCase;
+
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.SmallTests;
+import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.hbase.util.Bytes;
import org.junit.experimental.categories.Category;
@@ -122,8 +124,27 @@ public class TestResult extends TestCase
}
}
+ /**
+ * Verify that Result.getBytes(...) behaves correctly.
+ */
+ public void testResultGetBytes() throws Exception {
+ byte [] value1 = Bytes.toBytes("value1");
+ byte [] qual = Bytes.toBytes("qual");
+
+ KeyValue kv1 = new KeyValue(row, family, qual, value);
+ KeyValue kv2 = new KeyValue(row, family, qual, value1);
+
+ Result r1 = new Result(new KeyValue[] {kv1, kv2});
+
+ ImmutableBytesWritable bytes = r1.getBytes();
+ assertNotNull(bytes);
+
+ Result r2 = new Result(bytes);
+ // no exception thrown
+ Result.compareResults(r1, r2);
+ }
+
@org.junit.Rule
public org.apache.hadoop.hbase.ResourceCheckerJUnitRule cu =
new org.apache.hadoop.hbase.ResourceCheckerJUnitRule();
}
-