diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/mapreduce/RowCounter.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/mapreduce/RowCounter.java index 145b366db7b..8522a61a64c 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/mapreduce/RowCounter.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/mapreduce/RowCounter.java @@ -118,10 +118,7 @@ public class RowCounter extends Configured implements Tool { } startKey = startEnd[0]; endKey = startEnd[1]; - } - if (startTime < endTime) { - printUsage("--endtime=" + endTime + " needs to be greater than --starttime=" + startTime); - return null; + continue; } if (args[i].startsWith(startTimeArgKey)) { startTime = Long.parseLong(args[i].substring(startTimeArgKey.length())); @@ -136,11 +133,13 @@ public class RowCounter extends Configured implements Tool { Long.parseLong(args[i].substring(expectedCountArg.length()))); continue; } - else { - // if no switch, assume column names - sb.append(args[i]); - sb.append(" "); - } + // if no switch, assume column names + sb.append(args[i]); + sb.append(" "); + } + if (endTime < startTime) { + printUsage("--endtime=" + endTime + " needs to be greater than --starttime=" + startTime); + return null; } Job job = Job.getInstance(conf, conf.get(JOB_NAME_CONF_KEY, NAME + "_" + tableName)); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/mapreduce/TestRowCounter.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/mapreduce/TestRowCounter.java index 8501164214c..6657d0fba20 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/mapreduce/TestRowCounter.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/mapreduce/TestRowCounter.java @@ -57,6 +57,7 @@ public class TestRowCounter { private static final Log LOG = LogFactory.getLog(TestRowCounter.class); private final static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); private final static String TABLE_NAME = "testRowCounter"; + private final static String TABLE_NAME_TS_RANGE = "testRowCounter_ts_range"; private final static String COL_FAM = "col_fam"; private final static String COL1 = "c1"; private final static String COL2 = "c2"; @@ -138,6 +139,21 @@ public class TestRowCounter { runRowCount(args, 10); } + + /** + * Test a case when the column specified in command line arguments is + * exclusive for few rows and also a row range filter is specified + * + * @throws Exception + */ + @Test + public void testRowCounterColumnAndRowRange() throws Exception { + String[] args = new String[] { + TABLE_NAME, "--range=rov,rox", COL_FAM + ":" + COL1 + }; + runRowCount(args, 8); + } + /** * Test a case when the timerange is specified with --starttime and --endtime options * @@ -154,7 +170,8 @@ public class TestRowCounter { long ts; // clean up content of TABLE_NAME - Table table = TEST_UTIL.deleteTableData(TableName.valueOf(TABLE_NAME)); + Table table = TEST_UTIL.createTable(TableName.valueOf(TABLE_NAME_TS_RANGE), Bytes.toBytes(COL_FAM)); + ts = System.currentTimeMillis(); put1.addColumn(family, col1, ts, Bytes.toBytes("val1")); table.put(put1); @@ -168,28 +185,28 @@ public class TestRowCounter { table.close(); String[] args = new String[] { - TABLE_NAME, COL_FAM + ":" + COL1, + TABLE_NAME_TS_RANGE, COL_FAM + ":" + COL1, "--starttime=" + 0, "--endtime=" + ts }; runRowCount(args, 1); args = new String[] { - TABLE_NAME, COL_FAM + ":" + COL1, + TABLE_NAME_TS_RANGE, COL_FAM + ":" + COL1, "--starttime=" + 0, "--endtime=" + (ts - 10) }; runRowCount(args, 1); args = new String[] { - TABLE_NAME, COL_FAM + ":" + COL1, + TABLE_NAME_TS_RANGE, COL_FAM + ":" + COL1, "--starttime=" + ts, "--endtime=" + (ts + 1000) }; runRowCount(args, 2); args = new String[] { - TABLE_NAME, COL_FAM + ":" + COL1, + TABLE_NAME_TS_RANGE, COL_FAM + ":" + COL1, "--starttime=" + (ts - 30 * 1000), "--endtime=" + (ts + 30 * 1000), };