From 9c8f02e4ef3037e8eaf649360ce83a898c3b20e1 Mon Sep 17 00:00:00 2001 From: brandboat Date: Sat, 18 Mar 2017 18:02:42 +0800 Subject: [PATCH] HBASE-16014 Get and Put constructor argument lists are divergent Signed-off-by: CHIA-PING TSAI --- .../org/apache/hadoop/hbase/client/Get.java | 22 +++++++++++++++++++ .../apache/hadoop/hbase/client/TestGet.java | 12 ++++++++++ 2 files changed, 34 insertions(+) diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Get.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Get.java index a581ed55510..3771aff383f 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Get.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Get.java @@ -20,6 +20,7 @@ package org.apache.hadoop.hbase.client; import java.io.IOException; +import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -130,6 +131,27 @@ public class Get extends Query } } + /** + * Create a Get operation for the specified row. + * @param row + * @param rowOffset + * @param rowLength + */ + public Get(byte[] row, int rowOffset, int rowLength) { + Mutation.checkRow(row, rowOffset, rowLength); + this.row = Bytes.copy(row, rowOffset, rowLength); + } + + /** + * Create a Get operation for the specified row. + * @param row + */ + public Get(ByteBuffer row) { + Mutation.checkRow(row); + this.row = new byte[row.remaining()]; + row.get(this.row); + } + public boolean isCheckExistenceOnly() { return checkExistenceOnly; } diff --git a/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestGet.java b/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestGet.java index 810f6bc92ea..6a2bb396695 100644 --- a/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestGet.java +++ b/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestGet.java @@ -27,6 +27,7 @@ import static org.junit.Assert.fail; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; +import java.nio.ByteBuffer; import java.lang.reflect.InvocationTargetException; import java.util.Arrays; import java.util.List; @@ -241,4 +242,15 @@ public class TestGet { assertEquals("my.MockFilter", filters.get(1).getClass().getName()); assertTrue(filters.get(2) instanceof KeyOnlyFilter); } + + @Test + public void testGetRowConstructor() { + byte[] row1 = Bytes.toBytes("testRow"); + byte[] row2 = Bytes.toBytes("testtestRow"); + ByteBuffer rowBuffer = ByteBuffer.allocate(16); + rowBuffer = ByteBuffer.wrap(row1); + Get get1 = new Get(rowBuffer); + Get get2 = new Get(row2, 4, 7); + Assert.assertArrayEquals(get1.getRow(), get2.getRow()); + } }