From a793deb89e26f04e87e9205a5965cd2e710b81de Mon Sep 17 00:00:00 2001 From: Ashish Singhi Date: Tue, 21 Oct 2014 15:10:37 +0530 Subject: [PATCH] HBASE-12306 CellCounter output's wrong value for Total Families Across all Rows in output file --- .../apache/hadoop/hbase/mapreduce/CellCounter.java | 7 ++-- .../hadoop/hbase/mapreduce/TestCellCounter.java | 45 ++++++++++++++++++++++ 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/mapreduce/CellCounter.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/mapreduce/CellCounter.java index 8bb4111..2790fe2 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/mapreduce/CellCounter.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/mapreduce/CellCounter.java @@ -127,9 +127,10 @@ public class CellCounter extends Configured implements Tool { if (!thisRowFamilyName.equals(currentFamilyName)) { currentFamilyName = thisRowFamilyName; context.getCounter("CF", thisRowFamilyName).increment(1); - context.write(new Text("Total Families Across all Rows"), - new IntWritable(1)); - context.write(new Text(thisRowFamilyName), new IntWritable(1)); + if (1 == context.getCounter("CF", thisRowFamilyName).getValue()) { + context.write(new Text("Total Families Across all Rows"), new IntWritable(1)); + context.write(new Text(thisRowFamilyName), new IntWritable(1)); + } } String thisRowQualifierName = thisRowFamilyName + separator + Bytes.toStringBinary(CellUtil.cloneQualifier(value)); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/mapreduce/TestCellCounter.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/mapreduce/TestCellCounter.java index 092a18f..40e69f9 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/mapreduce/TestCellCounter.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/mapreduce/TestCellCounter.java @@ -156,4 +156,49 @@ public class TestCellCounter { System.setSecurityManager(SECURITY_MANAGER); } } + + /** + * Test CellCounter for complete table all data should print to output + */ + @Test(timeout = 300000) + public void testCellCounterForCompleteTable() throws Exception { + String sourceTable = "testCellCounterForCompleteTable"; + String outputPath = OUTPUT_DIR + sourceTable; + LocalFileSystem localFileSystem = new LocalFileSystem(); + Path outputDir = + new Path(outputPath).makeQualified(localFileSystem.getUri(), + localFileSystem.getWorkingDirectory()); + byte[][] families = { FAMILY_A, FAMILY_B }; + Table t = UTIL.createTable(Bytes.toBytes(sourceTable), families); + try { + Put p = new Put(ROW1); + p.add(FAMILY_A, QUALIFIER, now, Bytes.toBytes("Data11")); + p.add(FAMILY_B, QUALIFIER, now + 1, Bytes.toBytes("Data12")); + p.add(FAMILY_A, QUALIFIER, now + 2, Bytes.toBytes("Data13")); + t.put(p); + p = new Put(ROW2); + p.add(FAMILY_B, QUALIFIER, now, Bytes.toBytes("Dat21")); + p.add(FAMILY_A, QUALIFIER, now + 1, Bytes.toBytes("Data22")); + p.add(FAMILY_B, QUALIFIER, now + 2, Bytes.toBytes("Data23")); + t.put(p); + String[] args = { sourceTable, outputDir.toString(), ";" }; + runCount(args); + FileInputStream inputStream = + new FileInputStream(outputPath + File.separator + "part-r-00000"); + String data = IOUtils.toString(inputStream); + inputStream.close(); + assertTrue(data.contains("Total Families Across all Rows" + "\t" + "2")); + assertTrue(data.contains("Total Qualifiers across all Rows" + "\t" + "4")); + assertTrue(data.contains("Total ROWS" + "\t" + "2")); + assertTrue(data.contains("b;q" + "\t" + "2")); + assertTrue(data.contains("a;q" + "\t" + "2")); + assertTrue(data.contains("row1;a;q_Versions" + "\t" + "1")); + assertTrue(data.contains("row1;b;q_Versions" + "\t" + "1")); + assertTrue(data.contains("row2;a;q_Versions" + "\t" + "1")); + assertTrue(data.contains("row2;b;q_Versions" + "\t" + "1")); + } finally { + t.close(); + FileUtil.fullyDelete(new File(outputPath)); + } + } } \ No newline at end of file -- 1.9.2.msysgit.0