Return-Path: X-Original-To: apmail-hbase-commits-archive@www.apache.org Delivered-To: apmail-hbase-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 85F5617C02 for ; Wed, 22 Oct 2014 14:30:59 +0000 (UTC) Received: (qmail 10195 invoked by uid 500); 22 Oct 2014 14:30:59 -0000 Delivered-To: apmail-hbase-commits-archive@hbase.apache.org Received: (qmail 10109 invoked by uid 500); 22 Oct 2014 14:30:59 -0000 Mailing-List: contact commits-help@hbase.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@hbase.apache.org Delivered-To: mailing list commits@hbase.apache.org Received: (qmail 10090 invoked by uid 99); 22 Oct 2014 14:30:59 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 22 Oct 2014 14:30:59 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 148F7823EDA; Wed, 22 Oct 2014 14:30:59 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: tedyu@apache.org To: commits@hbase.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: git commit: HBASE-12306 CellCounter output's wrong value for Total Families Across all Rows in output file (Ashish Singhi) Date: Wed, 22 Oct 2014 14:30:59 +0000 (UTC) Repository: hbase Updated Branches: refs/heads/master 2908c1137 -> 19108fb85 HBASE-12306 CellCounter output's wrong value for Total Families Across all Rows in output file (Ashish Singhi) Project: http://git-wip-us.apache.org/repos/asf/hbase/repo Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/19108fb8 Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/19108fb8 Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/19108fb8 Branch: refs/heads/master Commit: 19108fb8504137a2e4d91b4d4ccb88f95698ebe5 Parents: 2908c11 Author: Ted Yu Authored: Wed Oct 22 14:30:53 2014 +0000 Committer: Ted Yu Committed: Wed Oct 22 14:30:53 2014 +0000 ---------------------------------------------------------------------- .../hadoop/hbase/mapreduce/CellCounter.java | 7 +-- .../hadoop/hbase/mapreduce/TestCellCounter.java | 47 +++++++++++++++++++- 2 files changed, 50 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hbase/blob/19108fb8/hbase-server/src/main/java/org/apache/hadoop/hbase/mapreduce/CellCounter.java ---------------------------------------------------------------------- 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)); http://git-wip-us.apache.org/repos/asf/hbase/blob/19108fb8/hbase-server/src/test/java/org/apache/hadoop/hbase/mapreduce/TestCellCounter.java ---------------------------------------------------------------------- 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..dd0bece 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); } } -} \ No newline at end of file + + /** + * 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)); + } + } +}