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 2012/10/11 06:58:29 UTC
svn commit: r1396902 - in /hbase/trunk/hbase-server/src:
main/java/org/apache/hadoop/hbase/client/HTable.java
main/java/org/apache/hadoop/hbase/client/Increment.java
main/ruby/hbase/table.rb
test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java
Author: stack
Date: Thu Oct 11 04:58:29 2012
New Revision: 1396902
URL: http://svn.apache.org/viewvc?rev=1396902&view=rev
Log:
HBASE-3661 Handle empty qualifier better in shell for increments
Modified:
hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/client/HTable.java
hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/client/Increment.java
hbase/trunk/hbase-server/src/main/ruby/hbase/table.rb
hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java
Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/client/HTable.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/client/HTable.java?rev=1396902&r1=1396901&r2=1396902&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/client/HTable.java (original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/client/HTable.java Thu Oct 11 04:58:29 2012
@@ -921,7 +921,9 @@ public class HTable implements HTableInt
if (row == null) {
npe = new NullPointerException("row is null");
} else if (family == null) {
- npe = new NullPointerException("column is null");
+ npe = new NullPointerException("family is null");
+ } else if (qualifier == null) {
+ npe = new NullPointerException("qualifier is null");
}
if (npe != null) {
throw new IOException(
Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/client/Increment.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/client/Increment.java?rev=1396902&r1=1396901&r2=1396902&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/client/Increment.java (original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/client/Increment.java Thu Oct 11 04:58:29 2012
@@ -78,6 +78,9 @@ public class Increment implements Row {
* @param rowLock previously acquired row lock, or null
*/
public Increment(byte [] row, RowLock rowLock) {
+ if (row == null) {
+ throw new IllegalArgumentException("Cannot increment a null row");
+ }
this.row = row;
if(rowLock != null) {
this.lockId = rowLock.getLockId();
@@ -95,6 +98,12 @@ public class Increment implements Row {
* @return the Increment object
*/
public Increment addColumn(byte [] family, byte [] qualifier, long amount) {
+ if (family == null) {
+ throw new IllegalArgumentException("family cannot be null");
+ }
+ if (qualifier == null) {
+ throw new IllegalArgumentException("qualifier cannot be null");
+ }
NavigableMap<byte [], Long> set = familyMap.get(family);
if(set == null) {
set = new TreeMap<byte [], Long>(Bytes.BYTES_COMPARATOR);
Modified: hbase/trunk/hbase-server/src/main/ruby/hbase/table.rb
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/ruby/hbase/table.rb?rev=1396902&r1=1396901&r2=1396902&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/ruby/hbase/table.rb (original)
+++ hbase/trunk/hbase-server/src/main/ruby/hbase/table.rb Thu Oct 11 04:58:29 2012
@@ -154,6 +154,9 @@ EOF
def _incr_internal(row, column, value = nil)
value ||= 1
family, qualifier = parse_column_name(column)
+ if qualifier.nil?
+ raise ArgumentError, "Failed to provide both column family and column qualifier for incr"
+ end
@table.incrementColumnValue(row.to_s.to_java_bytes, family, qualifier, value)
end
Modified: hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java?rev=1396902&r1=1396901&r2=1396902&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java (original)
+++ hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java Thu Oct 11 04:58:29 2012
@@ -4295,6 +4295,59 @@ public class TestFromClientSide {
}
}
+ @Test
+ public void testIncrementInvalidArguments() throws Exception {
+ LOG.info("Starting testIncrementInvalidArguments");
+ final byte[] TABLENAME = Bytes.toBytes("testIncrementInvalidArguments");
+ HTable ht = TEST_UTIL.createTable(TABLENAME, FAMILY);
+ final byte[] COLUMN = Bytes.toBytes("column");
+ try {
+ // try null row
+ ht.incrementColumnValue(null, FAMILY, COLUMN, 5);
+ fail("Should have thrown IOException");
+ } catch (IOException iox) {
+ // success
+ }
+ try {
+ // try null family
+ ht.incrementColumnValue(ROW, null, COLUMN, 5);
+ fail("Should have thrown IOException");
+ } 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(null);
+ incNoRow.addColumn(FAMILY, COLUMN, 5);
+ fail("Should have thrown IllegalArgumentException");
+ } catch (IllegalArgumentException iax) {
+ // success
+ }
+ // try null family
+ try {
+ Increment incNoFamily = new Increment(ROW);
+ incNoFamily.addColumn(null, COLUMN, 5);
+ fail("Should have thrown IllegalArgumentException");
+ } 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