HBASE-3661 Handle empty qualifier better in shell for increments
git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1396902 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
c2045b11da
commit
6d42266145
|
@ -921,7 +921,9 @@ public class HTable implements HTableInterface {
|
|||
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(
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue