You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by zg...@apache.org on 2017/05/19 09:45:56 UTC
hbase git commit: HBASE-15616 Allow null qualifier for all table
operations
Repository: hbase
Updated Branches:
refs/heads/master 7a535f584 -> 3fe4b28bb
HBASE-15616 Allow null qualifier for all table operations
Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/3fe4b28b
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/3fe4b28b
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/3fe4b28b
Branch: refs/heads/master
Commit: 3fe4b28bb07466e6ba245d8c40da425db70f706c
Parents: 7a535f5
Author: Guanghao Zhang <zg...@apache.org>
Authored: Thu May 18 13:12:01 2017 +0800
Committer: Guanghao Zhang <zg...@apache.org>
Committed: Fri May 19 17:47:08 2017 +0800
----------------------------------------------------------------------
.../org/apache/hadoop/hbase/client/HTable.java | 2 -
.../apache/hadoop/hbase/client/Increment.java | 3 -
.../hbase/shaded/protobuf/RequestConverter.java | 13 +--
.../hadoop/hbase/client/TestFromClientSide.java | 96 ++++++++++++++++++++
.../client/TestIncrementsFromClientSide.java | 15 ---
5 files changed, 103 insertions(+), 26 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hbase/blob/3fe4b28b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HTable.java
----------------------------------------------------------------------
diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HTable.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HTable.java
index bcb9d6b..d207f6a 100644
--- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HTable.java
+++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HTable.java
@@ -716,8 +716,6 @@ public class HTable implements Table {
npe = new NullPointerException("row is null");
} else if (family == null) {
npe = new NullPointerException("family is null");
- } else if (qualifier == null) {
- npe = new NullPointerException("qualifier is null");
}
if (npe != null) {
throw new IOException(
http://git-wip-us.apache.org/repos/asf/hbase/blob/3fe4b28b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Increment.java
----------------------------------------------------------------------
diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Increment.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Increment.java
index 179a566..4ba0efa 100644
--- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Increment.java
+++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Increment.java
@@ -119,9 +119,6 @@ public class Increment extends Mutation implements Comparable<Row> {
if (family == null) {
throw new IllegalArgumentException("family cannot be null");
}
- if (qualifier == null) {
- throw new IllegalArgumentException("qualifier cannot be null");
- }
List<Cell> list = getCellList(family);
KeyValue kv = createPutKeyValue(family, qualifier, ts, Bytes.toBytes(amount));
list.add(kv);
http://git-wip-us.apache.org/repos/asf/hbase/blob/3fe4b28b/hbase-client/src/main/java/org/apache/hadoop/hbase/shaded/protobuf/RequestConverter.java
----------------------------------------------------------------------
diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/shaded/protobuf/RequestConverter.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/shaded/protobuf/RequestConverter.java
index 42c69a7..4fd0d95 100644
--- a/hbase-client/src/main/java/org/apache/hadoop/hbase/shaded/protobuf/RequestConverter.java
+++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/shaded/protobuf/RequestConverter.java
@@ -190,7 +190,8 @@ public final class RequestConverter {
columnBuilder.setFamily(UnsafeByteOperations.unsafeWrap(family));
QualifierValue.Builder valueBuilder = QualifierValue.newBuilder();
valueBuilder.setValue(UnsafeByteOperations.unsafeWrap(Bytes.toBytes(amount)));
- valueBuilder.setQualifier(UnsafeByteOperations.unsafeWrap(qualifier));
+ valueBuilder.setQualifier(UnsafeByteOperations
+ .unsafeWrap(qualifier == null ? HConstants.EMPTY_BYTE_ARRAY : qualifier));
columnBuilder.addQualifierValue(valueBuilder.build());
mutateBuilder.addColumnValue(columnBuilder.build());
if (nonce != HConstants.NO_NONCE) {
@@ -1006,14 +1007,14 @@ public final class RequestConverter {
* @return a Condition
* @throws IOException
*/
- private static Condition buildCondition(final byte[] row,
- final byte[] family, final byte [] qualifier,
- final ByteArrayComparable comparator,
- final CompareType compareType) throws IOException {
+ private static Condition buildCondition(final byte[] row, final byte[] family,
+ final byte[] qualifier, final ByteArrayComparable comparator, final CompareType compareType)
+ throws IOException {
Condition.Builder builder = Condition.newBuilder();
builder.setRow(UnsafeByteOperations.unsafeWrap(row));
builder.setFamily(UnsafeByteOperations.unsafeWrap(family));
- builder.setQualifier(UnsafeByteOperations.unsafeWrap(qualifier));
+ builder.setQualifier(UnsafeByteOperations
+ .unsafeWrap(qualifier == null ? HConstants.EMPTY_BYTE_ARRAY : qualifier));
builder.setComparator(ProtobufUtil.toComparator(comparator));
builder.setCompareType(compareType);
return builder.build();
http://git-wip-us.apache.org/repos/asf/hbase/blob/3fe4b28b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java
index 8ee697f..dd9024a 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java
@@ -1427,6 +1427,62 @@ public class TestFromClientSide {
}
@Test
+ public void testNullQualifier() throws Exception {
+ final TableName tableName = TableName.valueOf(name.getMethodName());
+ Table table = TEST_UTIL.createTable(tableName, FAMILY);
+
+ // Work for Put
+ Put put = new Put(ROW);
+ put.addColumn(FAMILY, null, VALUE);
+ table.put(put);
+
+ // Work for Get, Scan
+ getTestNull(table, ROW, FAMILY, VALUE);
+ scanTestNull(table, ROW, FAMILY, VALUE);
+
+ // Work for Delete
+ Delete delete = new Delete(ROW);
+ delete.addColumns(FAMILY, null);
+ table.delete(delete);
+
+ Get get = new Get(ROW);
+ Result result = table.get(get);
+ assertEmptyResult(result);
+
+ // Work for Increment/Append
+ Increment increment = new Increment(ROW);
+ increment.addColumn(FAMILY, null, 1L);
+ table.increment(increment);
+ getTestNull(table, ROW, FAMILY, 1L);
+
+ table.incrementColumnValue(ROW, FAMILY, null, 1L);
+ getTestNull(table, ROW, FAMILY, 2L);
+
+ delete = new Delete(ROW);
+ delete.addColumns(FAMILY, null);
+ table.delete(delete);
+
+ Append append = new Append(ROW);
+ append.add(FAMILY, null, VALUE);
+ table.append(append);
+ getTestNull(table, ROW, FAMILY, VALUE);
+
+ // Work for checkAndMutate, checkAndPut, checkAndDelete
+ put = new Put(ROW);
+ put.addColumn(FAMILY, null, Bytes.toBytes("checkAndPut"));
+ table.put(put);
+ table.checkAndPut(ROW, FAMILY, null, VALUE, put);
+
+ RowMutations mutate = new RowMutations(ROW);
+ mutate.add(new Put(ROW).addColumn(FAMILY, null, Bytes.toBytes("checkAndMutate")));
+ table.checkAndMutate(ROW, FAMILY, null, CompareOp.EQUAL, Bytes.toBytes("checkAndPut"), mutate);
+
+ delete = new Delete(ROW);
+ delete.addColumns(FAMILY, null);
+ table.checkAndDelete(ROW, FAMILY, null, Bytes.toBytes("checkAndMutate"), delete);
+ }
+
+ @Test
public void testVersions() throws Exception {
final TableName tableName = TableName.valueOf(name.getMethodName());
@@ -2815,6 +2871,27 @@ public class TestFromClientSide {
}
+ private void getTestNull(Table ht, byte[] row, byte[] family, long value) throws Exception {
+ Get get = new Get(row);
+ get.addColumn(family, null);
+ Result result = ht.get(get);
+ assertSingleResult(result, row, family, null, value);
+
+ get = new Get(row);
+ get.addColumn(family, HConstants.EMPTY_BYTE_ARRAY);
+ result = ht.get(get);
+ assertSingleResult(result, row, family, HConstants.EMPTY_BYTE_ARRAY, value);
+
+ get = new Get(row);
+ get.addFamily(family);
+ result = ht.get(get);
+ assertSingleResult(result, row, family, HConstants.EMPTY_BYTE_ARRAY, value);
+
+ get = new Get(row);
+ result = ht.get(get);
+ assertSingleResult(result, row, family, HConstants.EMPTY_BYTE_ARRAY, value);
+ }
+
private void scanTestNull(Table ht, byte[] row, byte[] family, byte[] value)
throws Exception {
scanTestNull(ht, row, family, value, false);
@@ -3386,6 +3463,25 @@ public class TestFromClientSide {
equals(value, CellUtil.cloneValue(kv)));
}
+ private void assertSingleResult(Result result, byte[] row, byte[] family, byte[] qualifier,
+ long value) throws Exception {
+ assertTrue(
+ "Expected row [" + Bytes.toString(row) + "] " + "Got row [" + Bytes.toString(result.getRow())
+ + "]", equals(row, result.getRow()));
+ assertTrue("Expected a single key but result contains " + result.size(), result.size() == 1);
+ Cell kv = result.rawCells()[0];
+ assertTrue(
+ "Expected family [" + Bytes.toString(family) + "] " + "Got family ["
+ + Bytes.toString(CellUtil.cloneFamily(kv)) + "]",
+ equals(family, CellUtil.cloneFamily(kv)));
+ assertTrue("Expected qualifier [" + Bytes.toString(qualifier) + "] " + "Got qualifier ["
+ + Bytes.toString(CellUtil.cloneQualifier(kv)) + "]",
+ equals(qualifier, CellUtil.cloneQualifier(kv)));
+ assertTrue(
+ "Expected value [" + value + "] " + "Got value [" + Bytes.toLong(CellUtil.cloneValue(kv))
+ + "]", value == Bytes.toLong(CellUtil.cloneValue(kv)));
+ }
+
private void assertSingleResult(Result result, byte [] row, byte [] family,
byte [] qualifier, long ts, byte [] value)
throws Exception {
http://git-wip-us.apache.org/repos/asf/hbase/blob/3fe4b28b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestIncrementsFromClientSide.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestIncrementsFromClientSide.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestIncrementsFromClientSide.java
index 4406812..767cace 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestIncrementsFromClientSide.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestIncrementsFromClientSide.java
@@ -225,13 +225,6 @@ public class TestIncrementsFromClientSide {
} catch (IOException iox) {
// success
}
- try {
- // try null qualifier
- ht.incrementColumnValue(ROW, FAMILY, null, 5);
- fail("Should have thrown IOException");
- } catch (IOException iox) {
- // success
- }
// try null row
try {
Increment incNoRow = new Increment((byte [])null);
@@ -250,14 +243,6 @@ public class TestIncrementsFromClientSide {
} catch (IllegalArgumentException iax) {
// success
}
- // try null qualifier
- try {
- Increment incNoQualifier = new Increment(ROW);
- incNoQualifier.addColumn(FAMILY, null, 5);
- fail("Should have thrown IllegalArgumentException");
- } catch (IllegalArgumentException iax) {
- // success
- }
}
@Test