hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject svn commit: r1587443 - in /hbase/trunk/hbase-server/src: main/java/org/apache/hadoop/hbase/mapreduce/RowCounter.java test/java/org/apache/hadoop/hbase/mapreduce/TestRowCounter.java
Date Tue, 15 Apr 2014 06:13:38 GMT
Author: stack
Date: Tue Apr 15 06:13:38 2014
New Revision: 1587443

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

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

Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/mapreduce/RowCounter.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/mapreduce/RowCounter.java?rev=1587443&r1=1587442&r2=1587443&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/mapreduce/RowCounter.java
(original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/mapreduce/RowCounter.java
Tue Apr 15 06:13:38 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;
@@ -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));
         }
       }
     }

Modified: hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/mapreduce/TestRowCounter.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/mapreduce/TestRowCounter.java?rev=1587443&r1=1587442&r2=1587443&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/mapreduce/TestRowCounter.java
(original)
+++ hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/mapreduce/TestRowCounter.java
Tue Apr 15 06:13:38 2014
@@ -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;
 
@@ -109,6 +110,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.
    * 
@@ -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<Put> rowsUpdate = new ArrayList<Put>();
     // 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);
     }
 



Mime
View raw message