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
This commit is contained in:
Michael Stack 2014-04-15 06:13:38 +00:00
parent d1e4cf0566
commit 550618ceb7
2 changed files with 26 additions and 7 deletions

View File

@ -22,6 +22,7 @@ import java.io.IOException;
import java.util.Set; import java.util.Set;
import java.util.TreeSet; import java.util.TreeSet;
import org.apache.commons.lang.StringUtils;
import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.classification.InterfaceStability; import org.apache.hadoop.classification.InterfaceStability;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
@ -124,13 +125,14 @@ public class RowCounter {
} }
if (sb.length() > 0) { if (sb.length() > 0) {
for (String columnName : sb.toString().trim().split(" ")) { for (String columnName : sb.toString().trim().split(" ")) {
String [] fields = columnName.split(":"); String family = StringUtils.substringBefore(columnName, ":");
if(fields.length == 1) { String qualifier = StringUtils.substringAfter(columnName, ":");
scan.addFamily(Bytes.toBytes(fields[0]));
} else { if (StringUtils.isBlank(qualifier)) {
byte[] qualifier = Bytes.toBytes(fields[1]); scan.addFamily(Bytes.toBytes(family));
qualifiers.add(qualifier); }
scan.addColumn(Bytes.toBytes(fields[0]), qualifier); else {
scan.addColumn(Bytes.toBytes(family), Bytes.toBytes(qualifier));
} }
} }
} }

View File

@ -56,6 +56,7 @@ public class TestRowCounter {
private final static String COL_FAM = "col_fam"; private final static String COL_FAM = "col_fam";
private final static String COL1 = "c1"; private final static String COL1 = "c1";
private final static String COL2 = "c2"; 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 TOTAL_ROWS = 10;
private final static int ROWS_WITH_ONE_COL = 2; private final static int ROWS_WITH_ONE_COL = 2;
@ -108,6 +109,20 @@ public class TestRowCounter {
runRowCount(args, 8); 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 * Test a case when the column specified in command line arguments is not part
* of first KV for a row. * of first KV for a row.
@ -154,6 +169,7 @@ public class TestRowCounter {
final byte[] value = Bytes.toBytes("abcd"); final byte[] value = Bytes.toBytes("abcd");
final byte[] col1 = Bytes.toBytes(COL1); final byte[] col1 = Bytes.toBytes(COL1);
final byte[] col2 = Bytes.toBytes(COL2); final byte[] col2 = Bytes.toBytes(COL2);
final byte[] col3 = Bytes.toBytes(COMPOSITE_COLUMN);
ArrayList<Put> rowsUpdate = new ArrayList<Put>(); ArrayList<Put> rowsUpdate = new ArrayList<Put>();
// write few rows with two columns // write few rows with two columns
int i = 0; int i = 0;
@ -162,6 +178,7 @@ public class TestRowCounter {
Put put = new Put(row); Put put = new Put(row);
put.add(family, col1, value); put.add(family, col1, value);
put.add(family, col2, value); put.add(family, col2, value);
put.add(family, col3, value);
rowsUpdate.add(put); rowsUpdate.add(put);
} }