From 550618ceb7961c7c1bc1a56203e523ac0ff3c3d6 Mon Sep 17 00:00:00 2001 From: Michael Stack Date: Tue, 15 Apr 2014 06:13:38 +0000 Subject: [PATCH] HBASE-10966 RowCounter misinterprets column names that have colons in their qualifier git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1587443 13f79535-47bb-0310-9956-ffa450edef68 --- .../hadoop/hbase/mapreduce/RowCounter.java | 16 +++++++++------- .../hadoop/hbase/mapreduce/TestRowCounter.java | 17 +++++++++++++++++ 2 files changed, 26 insertions(+), 7 deletions(-) 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 4fc08d264e1..2cb03fc42a4 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 @@ -22,6 +22,7 @@ import java.io.IOException; import java.util.Set; import java.util.TreeSet; +import org.apache.commons.lang.StringUtils; import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.classification.InterfaceStability; import org.apache.hadoop.conf.Configuration; @@ -124,13 +125,14 @@ public class RowCounter { } if (sb.length() > 0) { for (String columnName : sb.toString().trim().split(" ")) { - String [] fields = columnName.split(":"); - if(fields.length == 1) { - scan.addFamily(Bytes.toBytes(fields[0])); - } else { - byte[] qualifier = Bytes.toBytes(fields[1]); - qualifiers.add(qualifier); - scan.addColumn(Bytes.toBytes(fields[0]), qualifier); + String family = StringUtils.substringBefore(columnName, ":"); + String qualifier = StringUtils.substringAfter(columnName, ":"); + + if (StringUtils.isBlank(qualifier)) { + scan.addFamily(Bytes.toBytes(family)); + } + else { + scan.addColumn(Bytes.toBytes(family), Bytes.toBytes(qualifier)); } } } 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 a9c2ae5c75f..e908a0af97c 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 @@ -56,6 +56,7 @@ public class TestRowCounter { private final static String COL_FAM = "col_fam"; private final static String COL1 = "c1"; private final static String COL2 = "c2"; + private final static String COMPOSITE_COLUMN = "C:A:A"; private final static int TOTAL_ROWS = 10; private final static int ROWS_WITH_ONE_COL = 2; @@ -108,6 +109,20 @@ public class TestRowCounter { runRowCount(args, 8); } + /** + * Test a case when the column specified in command line arguments is + * one for which the qualifier contains colons. + * + * @throws Exception + */ + @Test + public void testRowCounterColumnWithColonInQualifier() throws Exception { + String[] args = new String[] { + TABLE_NAME, COL_FAM + ":" + COMPOSITE_COLUMN + }; + runRowCount(args, 8); + } + /** * Test a case when the column specified in command line arguments is not part * of first KV for a row. @@ -154,6 +169,7 @@ public class TestRowCounter { final byte[] value = Bytes.toBytes("abcd"); final byte[] col1 = Bytes.toBytes(COL1); final byte[] col2 = Bytes.toBytes(COL2); + final byte[] col3 = Bytes.toBytes(COMPOSITE_COLUMN); ArrayList rowsUpdate = new ArrayList(); // write few rows with two columns int i = 0; @@ -162,6 +178,7 @@ public class TestRowCounter { Put put = new Put(row); put.add(family, col1, value); put.add(family, col2, value); + put.add(family, col3, value); rowsUpdate.add(put); }