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 2014/04/15 08:12:37 UTC

svn commit: r1587441 - in /hbase/branches/0.96/hbase-server/src: main/java/org/apache/hadoop/hbase/mapreduce/RowCounter.java test/java/org/apache/hadoop/hbase/mapreduce/TestRowCounter.java

Author: stack
Date: Tue Apr 15 06:12:36 2014
New Revision: 1587441

URL: http://svn.apache.org/r1587441
Log:
HBASE-10966 RowCounter misinterprets column names that have colons in their qualifier

Modified:
    hbase/branches/0.96/hbase-server/src/main/java/org/apache/hadoop/hbase/mapreduce/RowCounter.java
    hbase/branches/0.96/hbase-server/src/test/java/org/apache/hadoop/hbase/mapreduce/TestRowCounter.java

Modified: hbase/branches/0.96/hbase-server/src/main/java/org/apache/hadoop/hbase/mapreduce/RowCounter.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.96/hbase-server/src/main/java/org/apache/hadoop/hbase/mapreduce/RowCounter.java?rev=1587441&r1=1587440&r2=1587441&view=diff
==============================================================================
--- hbase/branches/0.96/hbase-server/src/main/java/org/apache/hadoop/hbase/mapreduce/RowCounter.java (original)
+++ hbase/branches/0.96/hbase-server/src/main/java/org/apache/hadoop/hbase/mapreduce/RowCounter.java Tue Apr 15 06:12:36 2014
@@ -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;
@@ -125,13 +126,14 @@ public class RowCounter {
     scan.setFilter(new FirstKeyOnlyFilter());
     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));
         }
       }
     }

Modified: hbase/branches/0.96/hbase-server/src/test/java/org/apache/hadoop/hbase/mapreduce/TestRowCounter.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.96/hbase-server/src/test/java/org/apache/hadoop/hbase/mapreduce/TestRowCounter.java?rev=1587441&r1=1587440&r2=1587441&view=diff
==============================================================================
--- hbase/branches/0.96/hbase-server/src/test/java/org/apache/hadoop/hbase/mapreduce/TestRowCounter.java (original)
+++ hbase/branches/0.96/hbase-server/src/test/java/org/apache/hadoop/hbase/mapreduce/TestRowCounter.java Tue Apr 15 06:12:36 2014
@@ -52,6 +52,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;
 
@@ -105,6 +106,20 @@ public class TestRowCounter {
   }
 
   /**
+   * 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.
    * 
@@ -150,6 +165,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<Put> rowsUpdate = new ArrayList<Put>();
     // write few rows with two columns
     int i = 0;
@@ -158,6 +174,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);
     }