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 2008/04/15 23:19:39 UTC
svn commit: r648415 - in /hadoop/hbase/branches/0.1: ./
src/java/org/apache/hadoop/hbase/mapred/
Author: stack
Date: Tue Apr 15 14:19:35 2008
New Revision: 648415
URL: http://svn.apache.org/viewvc?rev=648415&view=rev
Log:
HBASE-559 MR example job to count table rows
Added:
hadoop/hbase/branches/0.1/src/java/org/apache/hadoop/hbase/mapred/Driver.java
hadoop/hbase/branches/0.1/src/java/org/apache/hadoop/hbase/mapred/RowCounter.java
hadoop/hbase/branches/0.1/src/java/org/apache/hadoop/hbase/mapred/RowCounter_Counters.properties
Modified:
hadoop/hbase/branches/0.1/CHANGES.txt
hadoop/hbase/branches/0.1/build.xml
hadoop/hbase/branches/0.1/src/java/org/apache/hadoop/hbase/mapred/package-info.java
Modified: hadoop/hbase/branches/0.1/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/hbase/branches/0.1/CHANGES.txt?rev=648415&r1=648414&r2=648415&view=diff
==============================================================================
--- hadoop/hbase/branches/0.1/CHANGES.txt (original)
+++ hadoop/hbase/branches/0.1/CHANGES.txt Tue Apr 15 14:19:35 2008
@@ -11,6 +11,10 @@
HBASE-12 when hbase regionserver restarts, it says "impossible state for
createLease()"
+ IMPROVEMENTS
+ HBASE-559 MR example job to count table rows
+
+
Release 0.1.1 - 04/11/2008
BUG FIXES
Modified: hadoop/hbase/branches/0.1/build.xml
URL: http://svn.apache.org/viewvc/hadoop/hbase/branches/0.1/build.xml?rev=648415&r1=648414&r2=648415&view=diff
==============================================================================
--- hadoop/hbase/branches/0.1/build.xml (original)
+++ hadoop/hbase/branches/0.1/build.xml Tue Apr 15 14:19:35 2008
@@ -148,12 +148,20 @@
</javac>
</target>
- <!-- Override jar target to specify main class -->
<target name="jar" depends="compile">
+ <!--Copy over any properties under src-->
+ <copy todir="${build.classes}">
+ <fileset dir="${src.dir}">
+ <include name="**/*.properties" />
+ </fileset>
+ </copy>
<jar jarfile="${build.dir}/${final.name}.jar"
basedir="${build.classes}" >
<fileset file="${basedir}/conf/hbase-default.xml"/>
<zipfileset dir="${build.webapps}" prefix="webapps"/>
+ <manifest>
+ <attribute name="Main-Class" value="org/apache/hadoop/hbase/mapred/Driver" />
+ </manifest>
</jar>
</target>
Added: hadoop/hbase/branches/0.1/src/java/org/apache/hadoop/hbase/mapred/Driver.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/branches/0.1/src/java/org/apache/hadoop/hbase/mapred/Driver.java?rev=648415&view=auto
==============================================================================
--- hadoop/hbase/branches/0.1/src/java/org/apache/hadoop/hbase/mapred/Driver.java (added)
+++ hadoop/hbase/branches/0.1/src/java/org/apache/hadoop/hbase/mapred/Driver.java Tue Apr 15 14:19:35 2008
@@ -0,0 +1,39 @@
+/**
+ * Copyright 2008 The Apache Software Foundation
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase.mapred;
+
+import org.apache.hadoop.util.ProgramDriver;
+
+/**
+ * Driver for hbase mapreduce jobs. Select which to run by passing
+ * name of job to this main.
+ */
+public class Driver {
+ /**
+ * @param args
+ * @throws Throwable
+ */
+ public static void main(String[] args) throws Throwable {
+ ProgramDriver pgd = new ProgramDriver();
+ pgd.addClass(RowCounter.NAME, RowCounter.class,
+ "Count rows in HBase table");
+ pgd.driver(args);
+ }
+}
Added: hadoop/hbase/branches/0.1/src/java/org/apache/hadoop/hbase/mapred/RowCounter.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/branches/0.1/src/java/org/apache/hadoop/hbase/mapred/RowCounter.java?rev=648415&view=auto
==============================================================================
--- hadoop/hbase/branches/0.1/src/java/org/apache/hadoop/hbase/mapred/RowCounter.java (added)
+++ hadoop/hbase/branches/0.1/src/java/org/apache/hadoop/hbase/mapred/RowCounter.java Tue Apr 15 14:19:35 2008
@@ -0,0 +1,133 @@
+/**
+ * Copyright 2008 The Apache Software Foundation
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase.mapred;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.hbase.HBaseConfiguration;
+import org.apache.hadoop.hbase.HStoreKey;
+import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
+import org.apache.hadoop.io.MapWritable;
+import org.apache.hadoop.io.Text;
+import org.apache.hadoop.mapred.JobClient;
+import org.apache.hadoop.mapred.JobConf;
+import org.apache.hadoop.mapred.OutputCollector;
+import org.apache.hadoop.mapred.Reporter;
+import org.apache.hadoop.mapred.lib.IdentityReducer;
+import org.apache.hadoop.util.Tool;
+import org.apache.hadoop.util.ToolRunner;
+
+/**
+ * A job with a map to count rows.
+ * Map outputs table rows IF the input row has columns that have content.
+ * Uses an {@link IdentityReducer}
+ */
+public class RowCounter extends TableMap<Text, MapWritable> implements Tool {
+ /* Name of this 'program'
+ */
+ static final String NAME = "rowcounter";
+
+ private Configuration conf;
+ private final MapWritable EMPTY_VALUE = new MapWritable();
+ private static enum Counters {ROWS}
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public void map(final HStoreKey key,
+ @SuppressWarnings("unused") final MapWritable value,
+ final OutputCollector<Text, MapWritable> output,
+ @SuppressWarnings("unused") final Reporter reporter)
+ throws IOException {
+ Text row = key.getRow();
+ boolean content = false;
+ for (Map.Entry e: value.entrySet()) {
+ ImmutableBytesWritable ibw = (ImmutableBytesWritable)e.getValue();
+ if (ibw != null && ibw.get().length > 0) {
+ content = true;
+ break;
+ }
+ }
+ if (!content) {
+ return;
+ }
+ // Give out same value every time. We're only interested in the row/key
+ reporter.incrCounter(Counters.ROWS, 1);
+ output.collect(row, EMPTY_VALUE);
+ }
+
+ @SuppressWarnings("unused")
+ public JobConf createSubmittableJob(String[] args) throws IOException {
+ JobConf c = new JobConf(getConf(), RowCounter.class);
+ c.setJobName(NAME);
+ // Columns are space delimited
+ StringBuilder sb = new StringBuilder();
+ final int columnoffset = 2;
+ for (int i = columnoffset; i < args.length; i++) {
+ if (i > columnoffset) {
+ sb.append(" ");
+ }
+ sb.append(args[i]);
+ }
+ // Second argument is the table name.
+ TableMap.initJob(args[1], sb.toString(), this.getClass(), c);
+ c.setReducerClass(IdentityReducer.class);
+ // First arg is the output directory.
+ c.setOutputPath(new Path(args[0]));
+ return c;
+ }
+
+ static int printUsage() {
+ System.out.println(NAME +
+ " <outputdir> <tablename> <column1> [<column2>...]");
+ return -1;
+ }
+
+ public int run(final String[] args) throws Exception {
+ // Make sure there are at least 3 parameters
+ if (args.length < 3) {
+ System.err.println("ERROR: Wrong number of parameters: " + args.length);
+ return printUsage();
+ }
+ JobClient.runJob(createSubmittableJob(args));
+ return 0;
+ }
+
+ public Configuration getConf() {
+ return this.conf;
+ }
+
+ public void setConf(final Configuration c) {
+ this.conf = c;
+ }
+
+ public static void main(String[] args) throws Exception {
+ HBaseConfiguration c = new HBaseConfiguration();
+ c.set("hbase.master", "durruti.local:60000");
+ int errCode = ToolRunner.run(c, new RowCounter(), args);
+ System.exit(errCode);
+ }
+}
Added: hadoop/hbase/branches/0.1/src/java/org/apache/hadoop/hbase/mapred/RowCounter_Counters.properties
URL: http://svn.apache.org/viewvc/hadoop/hbase/branches/0.1/src/java/org/apache/hadoop/hbase/mapred/RowCounter_Counters.properties?rev=648415&view=auto
==============================================================================
--- hadoop/hbase/branches/0.1/src/java/org/apache/hadoop/hbase/mapred/RowCounter_Counters.properties (added)
+++ hadoop/hbase/branches/0.1/src/java/org/apache/hadoop/hbase/mapred/RowCounter_Counters.properties Tue Apr 15 14:19:35 2008
@@ -0,0 +1,6 @@
+
+# ResourceBundle properties file for RowCounter MR job
+
+CounterGroupName= RowCounter
+
+ROWS.name= Rows
Modified: hadoop/hbase/branches/0.1/src/java/org/apache/hadoop/hbase/mapred/package-info.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/branches/0.1/src/java/org/apache/hadoop/hbase/mapred/package-info.java?rev=648415&r1=648414&r2=648415&view=diff
==============================================================================
--- hadoop/hbase/branches/0.1/src/java/org/apache/hadoop/hbase/mapred/package-info.java (original)
+++ hadoop/hbase/branches/0.1/src/java/org/apache/hadoop/hbase/mapred/package-info.java Tue Apr 15 14:19:35 2008
@@ -75,7 +75,15 @@
reducers so load is spread across the hbase cluster.
</p>
-<h2> Sample MR Bulk Uploader </h2>
+<h2>Example Code</h2>
+<h3>Sample Row Counter</h3>
+<p>See {@link org.apache.hadoop.hbase.mapred.RowCounter}. You should be able to run
+it by doing: <code>% ./bin/hadoop jar hbase-X.X.X.jar</code>. This will invoke
+the hbase MapReduce Driver class. Select 'rowcounter' from the choice of jobs
+offered.
+</p>
+
+<h3> Sample MR Bulk Uploader </h3>
<p>Read the class comment below for specification of inputs, prerequisites, etc.
</p>
<blockquote><pre>package org.apache.hadoop.hbase.mapred;