hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bus...@apache.org
Subject [43/52] [partial] hbase-site git commit: Published site at 29c46c4834a3f96e9fca33cb16bc7f3748fcd60c.
Date Tue, 05 Jul 2016 23:54:42 GMT
http://git-wip-us.apache.org/repos/asf/hbase-site/blob/6444c276/apidocs/src-html/org/apache/hadoop/hbase/mapred/TableOutputFormat.html
----------------------------------------------------------------------
diff --git a/apidocs/src-html/org/apache/hadoop/hbase/mapred/TableOutputFormat.html b/apidocs/src-html/org/apache/hadoop/hbase/mapred/TableOutputFormat.html
index 2cffd19..126b093 100644
--- a/apidocs/src-html/org/apache/hadoop/hbase/mapred/TableOutputFormat.html
+++ b/apidocs/src-html/org/apache/hadoop/hbase/mapred/TableOutputFormat.html
@@ -61,66 +61,71 @@
 <span class="sourceLineNo">053</span>   */<a name="line.53"></a>
 <span class="sourceLineNo">054</span>  protected static class TableRecordWriter implements RecordWriter&lt;ImmutableBytesWritable, Put&gt; {<a name="line.54"></a>
 <span class="sourceLineNo">055</span>    private BufferedMutator m_mutator;<a name="line.55"></a>
-<span class="sourceLineNo">056</span>    private Connection connection;<a name="line.56"></a>
-<span class="sourceLineNo">057</span>    /**<a name="line.57"></a>
-<span class="sourceLineNo">058</span>     * Instantiate a TableRecordWriter with the HBase HClient for writing. Assumes control over the<a name="line.58"></a>
-<span class="sourceLineNo">059</span>     * lifecycle of {@code conn}.<a name="line.59"></a>
+<span class="sourceLineNo">056</span>    private Connection conn;<a name="line.56"></a>
+<span class="sourceLineNo">057</span><a name="line.57"></a>
+<span class="sourceLineNo">058</span>    /**<a name="line.58"></a>
+<span class="sourceLineNo">059</span>     * Instantiate a TableRecordWriter with a BufferedMutator for batch writing.<a name="line.59"></a>
 <span class="sourceLineNo">060</span>     */<a name="line.60"></a>
-<span class="sourceLineNo">061</span>    public TableRecordWriter(final BufferedMutator mutator) throws IOException {<a name="line.61"></a>
-<span class="sourceLineNo">062</span>      this.m_mutator = mutator;<a name="line.62"></a>
-<span class="sourceLineNo">063</span>    }<a name="line.63"></a>
-<span class="sourceLineNo">064</span><a name="line.64"></a>
-<span class="sourceLineNo">065</span>    public TableRecordWriter(JobConf job) throws IOException {<a name="line.65"></a>
-<span class="sourceLineNo">066</span>      // expecting exactly one path<a name="line.66"></a>
-<span class="sourceLineNo">067</span>      TableName tableName = TableName.valueOf(job.get(OUTPUT_TABLE));<a name="line.67"></a>
-<span class="sourceLineNo">068</span>      connection = ConnectionFactory.createConnection(job);<a name="line.68"></a>
-<span class="sourceLineNo">069</span>      m_mutator = connection.getBufferedMutator(tableName);<a name="line.69"></a>
-<span class="sourceLineNo">070</span>    }<a name="line.70"></a>
-<span class="sourceLineNo">071</span><a name="line.71"></a>
-<span class="sourceLineNo">072</span>    public void close(Reporter reporter) throws IOException {<a name="line.72"></a>
-<span class="sourceLineNo">073</span>      this.m_mutator.close();<a name="line.73"></a>
-<span class="sourceLineNo">074</span>      if (connection != null) {<a name="line.74"></a>
-<span class="sourceLineNo">075</span>        connection.close();<a name="line.75"></a>
-<span class="sourceLineNo">076</span>        connection = null;<a name="line.76"></a>
-<span class="sourceLineNo">077</span>      }<a name="line.77"></a>
-<span class="sourceLineNo">078</span>    }<a name="line.78"></a>
-<span class="sourceLineNo">079</span><a name="line.79"></a>
-<span class="sourceLineNo">080</span>    public void write(ImmutableBytesWritable key, Put value) throws IOException {<a name="line.80"></a>
-<span class="sourceLineNo">081</span>      m_mutator.mutate(new Put(value));<a name="line.81"></a>
+<span class="sourceLineNo">061</span>    public TableRecordWriter(JobConf job) throws IOException {<a name="line.61"></a>
+<span class="sourceLineNo">062</span>      // expecting exactly one path<a name="line.62"></a>
+<span class="sourceLineNo">063</span>      TableName tableName = TableName.valueOf(job.get(OUTPUT_TABLE));<a name="line.63"></a>
+<span class="sourceLineNo">064</span>      try {<a name="line.64"></a>
+<span class="sourceLineNo">065</span>        this.conn = ConnectionFactory.createConnection(job);<a name="line.65"></a>
+<span class="sourceLineNo">066</span>        this.m_mutator = conn.getBufferedMutator(tableName);<a name="line.66"></a>
+<span class="sourceLineNo">067</span>      } finally {<a name="line.67"></a>
+<span class="sourceLineNo">068</span>        if (this.m_mutator == null) {<a name="line.68"></a>
+<span class="sourceLineNo">069</span>          conn.close();<a name="line.69"></a>
+<span class="sourceLineNo">070</span>          conn = null;<a name="line.70"></a>
+<span class="sourceLineNo">071</span>        }<a name="line.71"></a>
+<span class="sourceLineNo">072</span>      }<a name="line.72"></a>
+<span class="sourceLineNo">073</span>    }<a name="line.73"></a>
+<span class="sourceLineNo">074</span><a name="line.74"></a>
+<span class="sourceLineNo">075</span>    public void close(Reporter reporter) throws IOException {<a name="line.75"></a>
+<span class="sourceLineNo">076</span>      if (this.m_mutator != null) {<a name="line.76"></a>
+<span class="sourceLineNo">077</span>        this.m_mutator.close();<a name="line.77"></a>
+<span class="sourceLineNo">078</span>      }<a name="line.78"></a>
+<span class="sourceLineNo">079</span>      if (conn != null) {<a name="line.79"></a>
+<span class="sourceLineNo">080</span>        this.conn.close();<a name="line.80"></a>
+<span class="sourceLineNo">081</span>      }<a name="line.81"></a>
 <span class="sourceLineNo">082</span>    }<a name="line.82"></a>
-<span class="sourceLineNo">083</span>  }<a name="line.83"></a>
-<span class="sourceLineNo">084</span><a name="line.84"></a>
-<span class="sourceLineNo">085</span>  /**<a name="line.85"></a>
-<span class="sourceLineNo">086</span>   * Creates a new record writer.<a name="line.86"></a>
-<span class="sourceLineNo">087</span>   * <a name="line.87"></a>
-<span class="sourceLineNo">088</span>   * Be aware that the baseline javadoc gives the impression that there is a single<a name="line.88"></a>
-<span class="sourceLineNo">089</span>   * {@link RecordWriter} per job but in HBase, it is more natural if we give you a new<a name="line.89"></a>
-<span class="sourceLineNo">090</span>   * RecordWriter per call of this method. You must close the returned RecordWriter when done.<a name="line.90"></a>
-<span class="sourceLineNo">091</span>   * Failure to do so will drop writes.<a name="line.91"></a>
-<span class="sourceLineNo">092</span>   *<a name="line.92"></a>
-<span class="sourceLineNo">093</span>   * @param ignored Ignored filesystem<a name="line.93"></a>
-<span class="sourceLineNo">094</span>   * @param job Current JobConf<a name="line.94"></a>
-<span class="sourceLineNo">095</span>   * @param name Name of the job<a name="line.95"></a>
-<span class="sourceLineNo">096</span>   * @param progress<a name="line.96"></a>
-<span class="sourceLineNo">097</span>   * @return The newly created writer instance.<a name="line.97"></a>
-<span class="sourceLineNo">098</span>   * @throws IOException When creating the writer fails.<a name="line.98"></a>
-<span class="sourceLineNo">099</span>   */<a name="line.99"></a>
-<span class="sourceLineNo">100</span>  @Override<a name="line.100"></a>
-<span class="sourceLineNo">101</span>  public RecordWriter getRecordWriter(FileSystem ignored, JobConf job, String name,<a name="line.101"></a>
-<span class="sourceLineNo">102</span>      Progressable progress)<a name="line.102"></a>
-<span class="sourceLineNo">103</span>  throws IOException {<a name="line.103"></a>
-<span class="sourceLineNo">104</span>    return new TableRecordWriter(job);<a name="line.104"></a>
-<span class="sourceLineNo">105</span>  }<a name="line.105"></a>
-<span class="sourceLineNo">106</span><a name="line.106"></a>
-<span class="sourceLineNo">107</span>  @Override<a name="line.107"></a>
-<span class="sourceLineNo">108</span>  public void checkOutputSpecs(FileSystem ignored, JobConf job)<a name="line.108"></a>
-<span class="sourceLineNo">109</span>  throws FileAlreadyExistsException, InvalidJobConfException, IOException {<a name="line.109"></a>
-<span class="sourceLineNo">110</span>    String tableName = job.get(OUTPUT_TABLE);<a name="line.110"></a>
-<span class="sourceLineNo">111</span>    if (tableName == null) {<a name="line.111"></a>
-<span class="sourceLineNo">112</span>      throw new IOException("Must specify table name");<a name="line.112"></a>
-<span class="sourceLineNo">113</span>    }<a name="line.113"></a>
-<span class="sourceLineNo">114</span>  }<a name="line.114"></a>
-<span class="sourceLineNo">115</span>}<a name="line.115"></a>
+<span class="sourceLineNo">083</span><a name="line.83"></a>
+<span class="sourceLineNo">084</span>    public void write(ImmutableBytesWritable key, Put value) throws IOException {<a name="line.84"></a>
+<span class="sourceLineNo">085</span>      m_mutator.mutate(new Put(value));<a name="line.85"></a>
+<span class="sourceLineNo">086</span>    }<a name="line.86"></a>
+<span class="sourceLineNo">087</span>  }<a name="line.87"></a>
+<span class="sourceLineNo">088</span><a name="line.88"></a>
+<span class="sourceLineNo">089</span>  /**<a name="line.89"></a>
+<span class="sourceLineNo">090</span>   * Creates a new record writer.<a name="line.90"></a>
+<span class="sourceLineNo">091</span>   * <a name="line.91"></a>
+<span class="sourceLineNo">092</span>   * Be aware that the baseline javadoc gives the impression that there is a single<a name="line.92"></a>
+<span class="sourceLineNo">093</span>   * {@link RecordWriter} per job but in HBase, it is more natural if we give you a new<a name="line.93"></a>
+<span class="sourceLineNo">094</span>   * RecordWriter per call of this method. You must close the returned RecordWriter when done.<a name="line.94"></a>
+<span class="sourceLineNo">095</span>   * Failure to do so will drop writes.<a name="line.95"></a>
+<span class="sourceLineNo">096</span>   *<a name="line.96"></a>
+<span class="sourceLineNo">097</span>   * @param ignored Ignored filesystem<a name="line.97"></a>
+<span class="sourceLineNo">098</span>   * @param job Current JobConf<a name="line.98"></a>
+<span class="sourceLineNo">099</span>   * @param name Name of the job<a name="line.99"></a>
+<span class="sourceLineNo">100</span>   * @param progress<a name="line.100"></a>
+<span class="sourceLineNo">101</span>   * @return The newly created writer instance.<a name="line.101"></a>
+<span class="sourceLineNo">102</span>   * @throws IOException When creating the writer fails.<a name="line.102"></a>
+<span class="sourceLineNo">103</span>   */<a name="line.103"></a>
+<span class="sourceLineNo">104</span>  @Override<a name="line.104"></a>
+<span class="sourceLineNo">105</span>  public RecordWriter getRecordWriter(FileSystem ignored, JobConf job, String name,<a name="line.105"></a>
+<span class="sourceLineNo">106</span>      Progressable progress)<a name="line.106"></a>
+<span class="sourceLineNo">107</span>  throws IOException {<a name="line.107"></a>
+<span class="sourceLineNo">108</span>    // Clear write buffer on fail is true by default so no need to reset it.<a name="line.108"></a>
+<span class="sourceLineNo">109</span>    return new TableRecordWriter(job);<a name="line.109"></a>
+<span class="sourceLineNo">110</span>  }<a name="line.110"></a>
+<span class="sourceLineNo">111</span><a name="line.111"></a>
+<span class="sourceLineNo">112</span>  @Override<a name="line.112"></a>
+<span class="sourceLineNo">113</span>  public void checkOutputSpecs(FileSystem ignored, JobConf job)<a name="line.113"></a>
+<span class="sourceLineNo">114</span>  throws FileAlreadyExistsException, InvalidJobConfException, IOException {<a name="line.114"></a>
+<span class="sourceLineNo">115</span>    String tableName = job.get(OUTPUT_TABLE);<a name="line.115"></a>
+<span class="sourceLineNo">116</span>    if (tableName == null) {<a name="line.116"></a>
+<span class="sourceLineNo">117</span>      throw new IOException("Must specify table name");<a name="line.117"></a>
+<span class="sourceLineNo">118</span>    }<a name="line.118"></a>
+<span class="sourceLineNo">119</span>  }<a name="line.119"></a>
+<span class="sourceLineNo">120</span>}<a name="line.120"></a>
 
 
 

http://git-wip-us.apache.org/repos/asf/hbase-site/blob/6444c276/apidocs/src-html/org/apache/hadoop/hbase/mapreduce/Import.html
----------------------------------------------------------------------
diff --git a/apidocs/src-html/org/apache/hadoop/hbase/mapreduce/Import.html b/apidocs/src-html/org/apache/hadoop/hbase/mapreduce/Import.html
index 654bc34..c72a9ce 100644
--- a/apidocs/src-html/org/apache/hadoop/hbase/mapreduce/Import.html
+++ b/apidocs/src-html/org/apache/hadoop/hbase/mapreduce/Import.html
@@ -217,7 +217,7 @@
 <span class="sourceLineNo">209</span>              + Bytes.toString(row.get(), row.getOffset(), row.getLength()));<a name="line.209"></a>
 <span class="sourceLineNo">210</span>        }<a name="line.210"></a>
 <span class="sourceLineNo">211</span>        if (filter == null<a name="line.211"></a>
-<span class="sourceLineNo">212</span>            || !filter.filterRowKey(KeyValueUtil.createFirstOnRow(row.get(), row.getOffset(),<a name="line.212"></a>
+<span class="sourceLineNo">212</span>            || !filter.filterRowKey(CellUtil.createFirstOnRow(row.get(), row.getOffset(),<a name="line.212"></a>
 <span class="sourceLineNo">213</span>                (short) row.getLength()))) {<a name="line.213"></a>
 <span class="sourceLineNo">214</span>          for (Cell kv : value.rawCells()) {<a name="line.214"></a>
 <span class="sourceLineNo">215</span>            kv = filterKv(filter, kv);<a name="line.215"></a>
@@ -283,7 +283,7 @@
 <span class="sourceLineNo">275</span>              + Bytes.toString(row.get(), row.getOffset(), row.getLength()));<a name="line.275"></a>
 <span class="sourceLineNo">276</span>        }<a name="line.276"></a>
 <span class="sourceLineNo">277</span>        if (filter == null<a name="line.277"></a>
-<span class="sourceLineNo">278</span>            || !filter.filterRowKey(KeyValueUtil.createFirstOnRow(row.get(), row.getOffset(),<a name="line.278"></a>
+<span class="sourceLineNo">278</span>            || !filter.filterRowKey(CellUtil.createFirstOnRow(row.get(), row.getOffset(),<a name="line.278"></a>
 <span class="sourceLineNo">279</span>                (short) row.getLength()))) {<a name="line.279"></a>
 <span class="sourceLineNo">280</span>          for (Cell kv : value.rawCells()) {<a name="line.280"></a>
 <span class="sourceLineNo">281</span>            kv = filterKv(filter, kv);<a name="line.281"></a>
@@ -340,7 +340,7 @@
 <span class="sourceLineNo">332</span>            + Bytes.toString(key.get(), key.getOffset(), key.getLength()));<a name="line.332"></a>
 <span class="sourceLineNo">333</span>      }<a name="line.333"></a>
 <span class="sourceLineNo">334</span>      if (filter == null<a name="line.334"></a>
-<span class="sourceLineNo">335</span>          || !filter.filterRowKey(KeyValueUtil.createFirstOnRow(key.get(), key.getOffset(),<a name="line.335"></a>
+<span class="sourceLineNo">335</span>          || !filter.filterRowKey(CellUtil.createFirstOnRow(key.get(), key.getOffset(),<a name="line.335"></a>
 <span class="sourceLineNo">336</span>              (short) key.getLength()))) {<a name="line.336"></a>
 <span class="sourceLineNo">337</span>        processKV(key, result, context, put, delete);<a name="line.337"></a>
 <span class="sourceLineNo">338</span>      }<a name="line.338"></a>

http://git-wip-us.apache.org/repos/asf/hbase-site/blob/6444c276/apidocs/src-html/org/apache/hadoop/hbase/mapreduce/RowCounter.html
----------------------------------------------------------------------
diff --git a/apidocs/src-html/org/apache/hadoop/hbase/mapreduce/RowCounter.html b/apidocs/src-html/org/apache/hadoop/hbase/mapreduce/RowCounter.html
index ca3ad7f..e209a48 100644
--- a/apidocs/src-html/org/apache/hadoop/hbase/mapreduce/RowCounter.html
+++ b/apidocs/src-html/org/apache/hadoop/hbase/mapreduce/RowCounter.html
@@ -27,105 +27,105 @@
 <span class="sourceLineNo">019</span>package org.apache.hadoop.hbase.mapreduce;<a name="line.19"></a>
 <span class="sourceLineNo">020</span><a name="line.20"></a>
 <span class="sourceLineNo">021</span>import java.io.IOException;<a name="line.21"></a>
-<span class="sourceLineNo">022</span><a name="line.22"></a>
-<span class="sourceLineNo">023</span>import org.apache.commons.logging.Log;<a name="line.23"></a>
-<span class="sourceLineNo">024</span>import org.apache.commons.logging.LogFactory;<a name="line.24"></a>
-<span class="sourceLineNo">025</span>import org.apache.commons.lang.StringUtils;<a name="line.25"></a>
-<span class="sourceLineNo">026</span>import org.apache.hadoop.hbase.HConstants;<a name="line.26"></a>
-<span class="sourceLineNo">027</span>import org.apache.hadoop.hbase.classification.InterfaceAudience;<a name="line.27"></a>
-<span class="sourceLineNo">028</span>import org.apache.hadoop.hbase.classification.InterfaceStability;<a name="line.28"></a>
-<span class="sourceLineNo">029</span>import org.apache.hadoop.conf.Configuration;<a name="line.29"></a>
-<span class="sourceLineNo">030</span>import org.apache.hadoop.conf.Configured;<a name="line.30"></a>
-<span class="sourceLineNo">031</span>import org.apache.hadoop.hbase.HBaseConfiguration;<a name="line.31"></a>
-<span class="sourceLineNo">032</span>import org.apache.hadoop.hbase.client.Result;<a name="line.32"></a>
-<span class="sourceLineNo">033</span>import org.apache.hadoop.hbase.client.Scan;<a name="line.33"></a>
-<span class="sourceLineNo">034</span>import org.apache.hadoop.hbase.filter.FirstKeyOnlyFilter;<a name="line.34"></a>
-<span class="sourceLineNo">035</span>import org.apache.hadoop.hbase.io.ImmutableBytesWritable;<a name="line.35"></a>
-<span class="sourceLineNo">036</span>import org.apache.hadoop.hbase.util.Bytes;<a name="line.36"></a>
-<span class="sourceLineNo">037</span>import org.apache.hadoop.mapreduce.Counter;<a name="line.37"></a>
-<span class="sourceLineNo">038</span>import org.apache.hadoop.mapreduce.Job;<a name="line.38"></a>
-<span class="sourceLineNo">039</span>import org.apache.hadoop.mapreduce.lib.output.NullOutputFormat;<a name="line.39"></a>
-<span class="sourceLineNo">040</span>import org.apache.hadoop.util.Tool;<a name="line.40"></a>
-<span class="sourceLineNo">041</span>import org.apache.hadoop.util.ToolRunner;<a name="line.41"></a>
-<span class="sourceLineNo">042</span><a name="line.42"></a>
-<span class="sourceLineNo">043</span>/**<a name="line.43"></a>
-<span class="sourceLineNo">044</span> * A job with a just a map phase to count rows. Map outputs table rows IF the<a name="line.44"></a>
-<span class="sourceLineNo">045</span> * input row has columns that have content.<a name="line.45"></a>
-<span class="sourceLineNo">046</span> */<a name="line.46"></a>
-<span class="sourceLineNo">047</span>@InterfaceAudience.Public<a name="line.47"></a>
-<span class="sourceLineNo">048</span>@InterfaceStability.Stable<a name="line.48"></a>
-<span class="sourceLineNo">049</span>public class RowCounter extends Configured implements Tool {<a name="line.49"></a>
-<span class="sourceLineNo">050</span><a name="line.50"></a>
-<span class="sourceLineNo">051</span>  private static final Log LOG = LogFactory.getLog(RowCounter.class);<a name="line.51"></a>
-<span class="sourceLineNo">052</span><a name="line.52"></a>
-<span class="sourceLineNo">053</span>  /** Name of this 'program'. */<a name="line.53"></a>
-<span class="sourceLineNo">054</span>  static final String NAME = "rowcounter";<a name="line.54"></a>
-<span class="sourceLineNo">055</span><a name="line.55"></a>
-<span class="sourceLineNo">056</span>  private final static String JOB_NAME_CONF_KEY = "mapreduce.job.name";<a name="line.56"></a>
-<span class="sourceLineNo">057</span>  private final static String EXPECTED_COUNT_KEY = RowCounter.class.getName() + ".expected_count";<a name="line.57"></a>
-<span class="sourceLineNo">058</span><a name="line.58"></a>
-<span class="sourceLineNo">059</span>  /**<a name="line.59"></a>
-<span class="sourceLineNo">060</span>   * Mapper that runs the count.<a name="line.60"></a>
-<span class="sourceLineNo">061</span>   */<a name="line.61"></a>
-<span class="sourceLineNo">062</span>  static class RowCounterMapper<a name="line.62"></a>
-<span class="sourceLineNo">063</span>  extends TableMapper&lt;ImmutableBytesWritable, Result&gt; {<a name="line.63"></a>
-<span class="sourceLineNo">064</span><a name="line.64"></a>
-<span class="sourceLineNo">065</span>    /** Counter enumeration to count the actual rows. */<a name="line.65"></a>
-<span class="sourceLineNo">066</span>    public static enum Counters {ROWS}<a name="line.66"></a>
-<span class="sourceLineNo">067</span><a name="line.67"></a>
-<span class="sourceLineNo">068</span>    /**<a name="line.68"></a>
-<span class="sourceLineNo">069</span>     * Maps the data.<a name="line.69"></a>
-<span class="sourceLineNo">070</span>     *<a name="line.70"></a>
-<span class="sourceLineNo">071</span>     * @param row  The current table row key.<a name="line.71"></a>
-<span class="sourceLineNo">072</span>     * @param values  The columns.<a name="line.72"></a>
-<span class="sourceLineNo">073</span>     * @param context  The current context.<a name="line.73"></a>
-<span class="sourceLineNo">074</span>     * @throws IOException When something is broken with the data.<a name="line.74"></a>
-<span class="sourceLineNo">075</span>     * @see org.apache.hadoop.mapreduce.Mapper#map(KEYIN, VALUEIN,<a name="line.75"></a>
-<span class="sourceLineNo">076</span>     *   org.apache.hadoop.mapreduce.Mapper.Context)<a name="line.76"></a>
-<span class="sourceLineNo">077</span>     */<a name="line.77"></a>
-<span class="sourceLineNo">078</span>    @Override<a name="line.78"></a>
-<span class="sourceLineNo">079</span>    public void map(ImmutableBytesWritable row, Result values,<a name="line.79"></a>
-<span class="sourceLineNo">080</span>      Context context)<a name="line.80"></a>
-<span class="sourceLineNo">081</span>    throws IOException {<a name="line.81"></a>
-<span class="sourceLineNo">082</span>      // Count every row containing data, whether it's in qualifiers or values<a name="line.82"></a>
-<span class="sourceLineNo">083</span>      context.getCounter(Counters.ROWS).increment(1);<a name="line.83"></a>
-<span class="sourceLineNo">084</span>    }<a name="line.84"></a>
-<span class="sourceLineNo">085</span>  }<a name="line.85"></a>
-<span class="sourceLineNo">086</span><a name="line.86"></a>
-<span class="sourceLineNo">087</span>  /**<a name="line.87"></a>
-<span class="sourceLineNo">088</span>   * Sets up the actual job.<a name="line.88"></a>
-<span class="sourceLineNo">089</span>   *<a name="line.89"></a>
-<span class="sourceLineNo">090</span>   * @param conf  The current configuration.<a name="line.90"></a>
-<span class="sourceLineNo">091</span>   * @param args  The command line parameters.<a name="line.91"></a>
-<span class="sourceLineNo">092</span>   * @return The newly created job.<a name="line.92"></a>
-<span class="sourceLineNo">093</span>   * @throws IOException When setting up the job fails.<a name="line.93"></a>
-<span class="sourceLineNo">094</span>   */<a name="line.94"></a>
-<span class="sourceLineNo">095</span>  public static Job createSubmittableJob(Configuration conf, String[] args)<a name="line.95"></a>
-<span class="sourceLineNo">096</span>  throws IOException {<a name="line.96"></a>
-<span class="sourceLineNo">097</span>    String tableName = args[0];<a name="line.97"></a>
-<span class="sourceLineNo">098</span>    String startKey = null;<a name="line.98"></a>
-<span class="sourceLineNo">099</span>    String endKey = null;<a name="line.99"></a>
-<span class="sourceLineNo">100</span>    long startTime = 0;<a name="line.100"></a>
-<span class="sourceLineNo">101</span>    long endTime = 0;<a name="line.101"></a>
-<span class="sourceLineNo">102</span><a name="line.102"></a>
-<span class="sourceLineNo">103</span>    StringBuilder sb = new StringBuilder();<a name="line.103"></a>
-<span class="sourceLineNo">104</span><a name="line.104"></a>
-<span class="sourceLineNo">105</span>    final String rangeSwitch = "--range=";<a name="line.105"></a>
-<span class="sourceLineNo">106</span>    final String startTimeArgKey = "--starttime=";<a name="line.106"></a>
-<span class="sourceLineNo">107</span>    final String endTimeArgKey = "--endtime=";<a name="line.107"></a>
-<span class="sourceLineNo">108</span>    final String expectedCountArg = "--expected-count=";<a name="line.108"></a>
-<span class="sourceLineNo">109</span><a name="line.109"></a>
-<span class="sourceLineNo">110</span>    // First argument is table name, starting from second<a name="line.110"></a>
-<span class="sourceLineNo">111</span>    for (int i = 1; i &lt; args.length; i++) {<a name="line.111"></a>
-<span class="sourceLineNo">112</span>      if (args[i].startsWith(rangeSwitch)) {<a name="line.112"></a>
-<span class="sourceLineNo">113</span>        String[] startEnd = args[i].substring(rangeSwitch.length()).split(",", 2);<a name="line.113"></a>
-<span class="sourceLineNo">114</span>        if (startEnd.length != 2 || startEnd[1].contains(",")) {<a name="line.114"></a>
-<span class="sourceLineNo">115</span>          printUsage("Please specify range in such format as \"--range=a,b\" " +<a name="line.115"></a>
-<span class="sourceLineNo">116</span>              "or, with only one boundary, \"--range=,b\" or \"--range=a,\"");<a name="line.116"></a>
-<span class="sourceLineNo">117</span>          return null;<a name="line.117"></a>
-<span class="sourceLineNo">118</span>        }<a name="line.118"></a>
-<span class="sourceLineNo">119</span>        startKey = startEnd[0];<a name="line.119"></a>
-<span class="sourceLineNo">120</span>        endKey = startEnd[1];<a name="line.120"></a>
+<span class="sourceLineNo">022</span>import java.util.List;<a name="line.22"></a>
+<span class="sourceLineNo">023</span>import java.util.ArrayList;<a name="line.23"></a>
+<span class="sourceLineNo">024</span><a name="line.24"></a>
+<span class="sourceLineNo">025</span>import org.apache.commons.logging.Log;<a name="line.25"></a>
+<span class="sourceLineNo">026</span>import org.apache.commons.logging.LogFactory;<a name="line.26"></a>
+<span class="sourceLineNo">027</span>import org.apache.commons.lang.StringUtils;<a name="line.27"></a>
+<span class="sourceLineNo">028</span>import org.apache.hadoop.hbase.HConstants;<a name="line.28"></a>
+<span class="sourceLineNo">029</span>import org.apache.hadoop.hbase.classification.InterfaceAudience;<a name="line.29"></a>
+<span class="sourceLineNo">030</span>import org.apache.hadoop.hbase.classification.InterfaceStability;<a name="line.30"></a>
+<span class="sourceLineNo">031</span>import org.apache.hadoop.conf.Configuration;<a name="line.31"></a>
+<span class="sourceLineNo">032</span>import org.apache.hadoop.conf.Configured;<a name="line.32"></a>
+<span class="sourceLineNo">033</span>import org.apache.hadoop.hbase.HBaseConfiguration;<a name="line.33"></a>
+<span class="sourceLineNo">034</span>import org.apache.hadoop.hbase.client.Result;<a name="line.34"></a>
+<span class="sourceLineNo">035</span>import org.apache.hadoop.hbase.client.Scan;<a name="line.35"></a>
+<span class="sourceLineNo">036</span>import org.apache.hadoop.hbase.filter.FilterBase;<a name="line.36"></a>
+<span class="sourceLineNo">037</span>import org.apache.hadoop.hbase.filter.FirstKeyOnlyFilter;<a name="line.37"></a>
+<span class="sourceLineNo">038</span>import org.apache.hadoop.hbase.filter.MultiRowRangeFilter;<a name="line.38"></a>
+<span class="sourceLineNo">039</span>import org.apache.hadoop.hbase.io.ImmutableBytesWritable;<a name="line.39"></a>
+<span class="sourceLineNo">040</span>import org.apache.hadoop.hbase.util.Bytes;<a name="line.40"></a>
+<span class="sourceLineNo">041</span>import org.apache.hadoop.mapreduce.Counter;<a name="line.41"></a>
+<span class="sourceLineNo">042</span>import org.apache.hadoop.mapreduce.Job;<a name="line.42"></a>
+<span class="sourceLineNo">043</span>import org.apache.hadoop.mapreduce.lib.output.NullOutputFormat;<a name="line.43"></a>
+<span class="sourceLineNo">044</span>import org.apache.hadoop.util.Tool;<a name="line.44"></a>
+<span class="sourceLineNo">045</span>import org.apache.hadoop.util.ToolRunner;<a name="line.45"></a>
+<span class="sourceLineNo">046</span><a name="line.46"></a>
+<span class="sourceLineNo">047</span>/**<a name="line.47"></a>
+<span class="sourceLineNo">048</span> * A job with a just a map phase to count rows. Map outputs table rows IF the<a name="line.48"></a>
+<span class="sourceLineNo">049</span> * input row has columns that have content.<a name="line.49"></a>
+<span class="sourceLineNo">050</span> */<a name="line.50"></a>
+<span class="sourceLineNo">051</span>@InterfaceAudience.Public<a name="line.51"></a>
+<span class="sourceLineNo">052</span>@InterfaceStability.Stable<a name="line.52"></a>
+<span class="sourceLineNo">053</span>public class RowCounter extends Configured implements Tool {<a name="line.53"></a>
+<span class="sourceLineNo">054</span><a name="line.54"></a>
+<span class="sourceLineNo">055</span>  private static final Log LOG = LogFactory.getLog(RowCounter.class);<a name="line.55"></a>
+<span class="sourceLineNo">056</span><a name="line.56"></a>
+<span class="sourceLineNo">057</span>  /** Name of this 'program'. */<a name="line.57"></a>
+<span class="sourceLineNo">058</span>  static final String NAME = "rowcounter";<a name="line.58"></a>
+<span class="sourceLineNo">059</span><a name="line.59"></a>
+<span class="sourceLineNo">060</span>  private final static String JOB_NAME_CONF_KEY = "mapreduce.job.name";<a name="line.60"></a>
+<span class="sourceLineNo">061</span>  private final static String EXPECTED_COUNT_KEY = RowCounter.class.getName() + ".expected_count";<a name="line.61"></a>
+<span class="sourceLineNo">062</span><a name="line.62"></a>
+<span class="sourceLineNo">063</span>  /**<a name="line.63"></a>
+<span class="sourceLineNo">064</span>   * Mapper that runs the count.<a name="line.64"></a>
+<span class="sourceLineNo">065</span>   */<a name="line.65"></a>
+<span class="sourceLineNo">066</span>  static class RowCounterMapper<a name="line.66"></a>
+<span class="sourceLineNo">067</span>  extends TableMapper&lt;ImmutableBytesWritable, Result&gt; {<a name="line.67"></a>
+<span class="sourceLineNo">068</span><a name="line.68"></a>
+<span class="sourceLineNo">069</span>    /** Counter enumeration to count the actual rows. */<a name="line.69"></a>
+<span class="sourceLineNo">070</span>    public static enum Counters {ROWS}<a name="line.70"></a>
+<span class="sourceLineNo">071</span><a name="line.71"></a>
+<span class="sourceLineNo">072</span>    /**<a name="line.72"></a>
+<span class="sourceLineNo">073</span>     * Maps the data.<a name="line.73"></a>
+<span class="sourceLineNo">074</span>     *<a name="line.74"></a>
+<span class="sourceLineNo">075</span>     * @param row  The current table row key.<a name="line.75"></a>
+<span class="sourceLineNo">076</span>     * @param values  The columns.<a name="line.76"></a>
+<span class="sourceLineNo">077</span>     * @param context  The current context.<a name="line.77"></a>
+<span class="sourceLineNo">078</span>     * @throws IOException When something is broken with the data.<a name="line.78"></a>
+<span class="sourceLineNo">079</span>     * @see org.apache.hadoop.mapreduce.Mapper#map(KEYIN, VALUEIN,<a name="line.79"></a>
+<span class="sourceLineNo">080</span>     *   org.apache.hadoop.mapreduce.Mapper.Context)<a name="line.80"></a>
+<span class="sourceLineNo">081</span>     */<a name="line.81"></a>
+<span class="sourceLineNo">082</span>    @Override<a name="line.82"></a>
+<span class="sourceLineNo">083</span>    public void map(ImmutableBytesWritable row, Result values,<a name="line.83"></a>
+<span class="sourceLineNo">084</span>      Context context)<a name="line.84"></a>
+<span class="sourceLineNo">085</span>    throws IOException {<a name="line.85"></a>
+<span class="sourceLineNo">086</span>      // Count every row containing data, whether it's in qualifiers or values<a name="line.86"></a>
+<span class="sourceLineNo">087</span>      context.getCounter(Counters.ROWS).increment(1);<a name="line.87"></a>
+<span class="sourceLineNo">088</span>    }<a name="line.88"></a>
+<span class="sourceLineNo">089</span>  }<a name="line.89"></a>
+<span class="sourceLineNo">090</span><a name="line.90"></a>
+<span class="sourceLineNo">091</span>  /**<a name="line.91"></a>
+<span class="sourceLineNo">092</span>   * Sets up the actual job.<a name="line.92"></a>
+<span class="sourceLineNo">093</span>   *<a name="line.93"></a>
+<span class="sourceLineNo">094</span>   * @param conf  The current configuration.<a name="line.94"></a>
+<span class="sourceLineNo">095</span>   * @param args  The command line parameters.<a name="line.95"></a>
+<span class="sourceLineNo">096</span>   * @return The newly created job.<a name="line.96"></a>
+<span class="sourceLineNo">097</span>   * @throws IOException When setting up the job fails.<a name="line.97"></a>
+<span class="sourceLineNo">098</span>   */<a name="line.98"></a>
+<span class="sourceLineNo">099</span>  public static Job createSubmittableJob(Configuration conf, String[] args)<a name="line.99"></a>
+<span class="sourceLineNo">100</span>  throws IOException {<a name="line.100"></a>
+<span class="sourceLineNo">101</span>    String tableName = args[0];<a name="line.101"></a>
+<span class="sourceLineNo">102</span>    List&lt;MultiRowRangeFilter.RowRange&gt; rowRangeList = null;<a name="line.102"></a>
+<span class="sourceLineNo">103</span>    long startTime = 0;<a name="line.103"></a>
+<span class="sourceLineNo">104</span>    long endTime = 0;<a name="line.104"></a>
+<span class="sourceLineNo">105</span><a name="line.105"></a>
+<span class="sourceLineNo">106</span>    StringBuilder sb = new StringBuilder();<a name="line.106"></a>
+<span class="sourceLineNo">107</span><a name="line.107"></a>
+<span class="sourceLineNo">108</span>    final String rangeSwitch = "--range=";<a name="line.108"></a>
+<span class="sourceLineNo">109</span>    final String startTimeArgKey = "--starttime=";<a name="line.109"></a>
+<span class="sourceLineNo">110</span>    final String endTimeArgKey = "--endtime=";<a name="line.110"></a>
+<span class="sourceLineNo">111</span>    final String expectedCountArg = "--expected-count=";<a name="line.111"></a>
+<span class="sourceLineNo">112</span><a name="line.112"></a>
+<span class="sourceLineNo">113</span>    // First argument is table name, starting from second<a name="line.113"></a>
+<span class="sourceLineNo">114</span>    for (int i = 1; i &lt; args.length; i++) {<a name="line.114"></a>
+<span class="sourceLineNo">115</span>      if (args[i].startsWith(rangeSwitch)) {<a name="line.115"></a>
+<span class="sourceLineNo">116</span>        try {<a name="line.116"></a>
+<span class="sourceLineNo">117</span>          rowRangeList = parseRowRangeParameter(args[i], rangeSwitch);<a name="line.117"></a>
+<span class="sourceLineNo">118</span>        } catch (IllegalArgumentException e) {<a name="line.118"></a>
+<span class="sourceLineNo">119</span>          return null;<a name="line.119"></a>
+<span class="sourceLineNo">120</span>        }<a name="line.120"></a>
 <span class="sourceLineNo">121</span>        continue;<a name="line.121"></a>
 <span class="sourceLineNo">122</span>      }<a name="line.122"></a>
 <span class="sourceLineNo">123</span>      if (args[i].startsWith(startTimeArgKey)) {<a name="line.123"></a>
@@ -154,89 +154,131 @@
 <span class="sourceLineNo">146</span>    job.setJarByClass(RowCounter.class);<a name="line.146"></a>
 <span class="sourceLineNo">147</span>    Scan scan = new Scan();<a name="line.147"></a>
 <span class="sourceLineNo">148</span>    scan.setCacheBlocks(false);<a name="line.148"></a>
-<span class="sourceLineNo">149</span>    if (startKey != null &amp;&amp; !startKey.equals("")) {<a name="line.149"></a>
-<span class="sourceLineNo">150</span>      scan.setStartRow(Bytes.toBytesBinary(startKey));<a name="line.150"></a>
-<span class="sourceLineNo">151</span>    }<a name="line.151"></a>
-<span class="sourceLineNo">152</span>    if (endKey != null &amp;&amp; !endKey.equals("")) {<a name="line.152"></a>
-<span class="sourceLineNo">153</span>      scan.setStopRow(Bytes.toBytesBinary(endKey));<a name="line.153"></a>
-<span class="sourceLineNo">154</span>    }<a name="line.154"></a>
-<span class="sourceLineNo">155</span>    if (sb.length() &gt; 0) {<a name="line.155"></a>
-<span class="sourceLineNo">156</span>      for (String columnName : sb.toString().trim().split(" ")) {<a name="line.156"></a>
-<span class="sourceLineNo">157</span>        String family = StringUtils.substringBefore(columnName, ":");<a name="line.157"></a>
-<span class="sourceLineNo">158</span>        String qualifier = StringUtils.substringAfter(columnName, ":");<a name="line.158"></a>
-<span class="sourceLineNo">159</span><a name="line.159"></a>
-<span class="sourceLineNo">160</span>        if (StringUtils.isBlank(qualifier)) {<a name="line.160"></a>
-<span class="sourceLineNo">161</span>          scan.addFamily(Bytes.toBytes(family));<a name="line.161"></a>
-<span class="sourceLineNo">162</span>        }<a name="line.162"></a>
-<span class="sourceLineNo">163</span>        else {<a name="line.163"></a>
-<span class="sourceLineNo">164</span>          scan.addColumn(Bytes.toBytes(family), Bytes.toBytes(qualifier));<a name="line.164"></a>
-<span class="sourceLineNo">165</span>        }<a name="line.165"></a>
-<span class="sourceLineNo">166</span>      }<a name="line.166"></a>
-<span class="sourceLineNo">167</span>    }<a name="line.167"></a>
-<span class="sourceLineNo">168</span>    scan.setFilter(new FirstKeyOnlyFilter());<a name="line.168"></a>
-<span class="sourceLineNo">169</span>    scan.setTimeRange(startTime, endTime == 0 ? HConstants.LATEST_TIMESTAMP : endTime);<a name="line.169"></a>
-<span class="sourceLineNo">170</span>    job.setOutputFormatClass(NullOutputFormat.class);<a name="line.170"></a>
-<span class="sourceLineNo">171</span>    TableMapReduceUtil.initTableMapperJob(tableName, scan,<a name="line.171"></a>
-<span class="sourceLineNo">172</span>      RowCounterMapper.class, ImmutableBytesWritable.class, Result.class, job);<a name="line.172"></a>
-<span class="sourceLineNo">173</span>    job.setNumReduceTasks(0);<a name="line.173"></a>
-<span class="sourceLineNo">174</span>    return job;<a name="line.174"></a>
-<span class="sourceLineNo">175</span>  }<a name="line.175"></a>
-<span class="sourceLineNo">176</span><a name="line.176"></a>
-<span class="sourceLineNo">177</span>  /*<a name="line.177"></a>
-<span class="sourceLineNo">178</span>   * @param errorMessage Can attach a message when error occurs.<a name="line.178"></a>
-<span class="sourceLineNo">179</span>   */<a name="line.179"></a>
-<span class="sourceLineNo">180</span>  private static void printUsage(String errorMessage) {<a name="line.180"></a>
-<span class="sourceLineNo">181</span>    System.err.println("ERROR: " + errorMessage);<a name="line.181"></a>
-<span class="sourceLineNo">182</span>    printUsage();<a name="line.182"></a>
-<span class="sourceLineNo">183</span>  }<a name="line.183"></a>
-<span class="sourceLineNo">184</span><a name="line.184"></a>
-<span class="sourceLineNo">185</span>  /**<a name="line.185"></a>
-<span class="sourceLineNo">186</span>   * Prints usage without error message.<a name="line.186"></a>
-<span class="sourceLineNo">187</span>   * Note that we don't document --expected-count, because it's intended for test.<a name="line.187"></a>
-<span class="sourceLineNo">188</span>   */<a name="line.188"></a>
-<span class="sourceLineNo">189</span>  private static void printUsage() {<a name="line.189"></a>
-<span class="sourceLineNo">190</span>    System.err.println("Usage: RowCounter [options] &lt;tablename&gt; " +<a name="line.190"></a>
-<span class="sourceLineNo">191</span>        "[--starttime=[start] --endtime=[end] " +<a name="line.191"></a>
-<span class="sourceLineNo">192</span>        "[--range=[startKey],[endKey]] [&lt;column1&gt; &lt;column2&gt;...]");<a name="line.192"></a>
-<span class="sourceLineNo">193</span>    System.err.println("For performance consider the following options:\n"<a name="line.193"></a>
-<span class="sourceLineNo">194</span>        + "-Dhbase.client.scanner.caching=100\n"<a name="line.194"></a>
-<span class="sourceLineNo">195</span>        + "-Dmapreduce.map.speculative=false");<a name="line.195"></a>
-<span class="sourceLineNo">196</span>  }<a name="line.196"></a>
-<span class="sourceLineNo">197</span><a name="line.197"></a>
-<span class="sourceLineNo">198</span>  @Override<a name="line.198"></a>
-<span class="sourceLineNo">199</span>  public int run(String[] args) throws Exception {<a name="line.199"></a>
-<span class="sourceLineNo">200</span>    if (args.length &lt; 1) {<a name="line.200"></a>
-<span class="sourceLineNo">201</span>      printUsage("Wrong number of parameters: " + args.length);<a name="line.201"></a>
-<span class="sourceLineNo">202</span>      return -1;<a name="line.202"></a>
-<span class="sourceLineNo">203</span>    }<a name="line.203"></a>
-<span class="sourceLineNo">204</span>    Job job = createSubmittableJob(getConf(), args);<a name="line.204"></a>
-<span class="sourceLineNo">205</span>    if (job == null) {<a name="line.205"></a>
-<span class="sourceLineNo">206</span>      return -1;<a name="line.206"></a>
-<span class="sourceLineNo">207</span>    }<a name="line.207"></a>
-<span class="sourceLineNo">208</span>    boolean success = job.waitForCompletion(true);<a name="line.208"></a>
-<span class="sourceLineNo">209</span>    final long expectedCount = getConf().getLong(EXPECTED_COUNT_KEY, -1);<a name="line.209"></a>
-<span class="sourceLineNo">210</span>    if (success &amp;&amp; expectedCount != -1) {<a name="line.210"></a>
-<span class="sourceLineNo">211</span>      final Counter counter = job.getCounters().findCounter(RowCounterMapper.Counters.ROWS);<a name="line.211"></a>
-<span class="sourceLineNo">212</span>      success = expectedCount == counter.getValue();<a name="line.212"></a>
-<span class="sourceLineNo">213</span>      if (!success) {<a name="line.213"></a>
-<span class="sourceLineNo">214</span>        LOG.error("Failing job because count of '" + counter.getValue() +<a name="line.214"></a>
-<span class="sourceLineNo">215</span>            "' does not match expected count of '" + expectedCount + "'");<a name="line.215"></a>
-<span class="sourceLineNo">216</span>      }<a name="line.216"></a>
-<span class="sourceLineNo">217</span>    }<a name="line.217"></a>
-<span class="sourceLineNo">218</span>    return (success ? 0 : 1);<a name="line.218"></a>
-<span class="sourceLineNo">219</span>  }<a name="line.219"></a>
-<span class="sourceLineNo">220</span><a name="line.220"></a>
-<span class="sourceLineNo">221</span>  /**<a name="line.221"></a>
-<span class="sourceLineNo">222</span>   * Main entry point.<a name="line.222"></a>
-<span class="sourceLineNo">223</span>   * @param args The command line parameters.<a name="line.223"></a>
-<span class="sourceLineNo">224</span>   * @throws Exception When running the job fails.<a name="line.224"></a>
-<span class="sourceLineNo">225</span>   */<a name="line.225"></a>
-<span class="sourceLineNo">226</span>  public static void main(String[] args) throws Exception {<a name="line.226"></a>
-<span class="sourceLineNo">227</span>    int errCode = ToolRunner.run(HBaseConfiguration.create(), new RowCounter(), args);<a name="line.227"></a>
-<span class="sourceLineNo">228</span>    System.exit(errCode);<a name="line.228"></a>
-<span class="sourceLineNo">229</span>  }<a name="line.229"></a>
-<span class="sourceLineNo">230</span><a name="line.230"></a>
-<span class="sourceLineNo">231</span>}<a name="line.231"></a>
+<span class="sourceLineNo">149</span>    setScanFilter(scan, rowRangeList);<a name="line.149"></a>
+<span class="sourceLineNo">150</span>    if (sb.length() &gt; 0) {<a name="line.150"></a>
+<span class="sourceLineNo">151</span>      for (String columnName : sb.toString().trim().split(" ")) {<a name="line.151"></a>
+<span class="sourceLineNo">152</span>        String family = StringUtils.substringBefore(columnName, ":");<a name="line.152"></a>
+<span class="sourceLineNo">153</span>        String qualifier = StringUtils.substringAfter(columnName, ":");<a name="line.153"></a>
+<span class="sourceLineNo">154</span><a name="line.154"></a>
+<span class="sourceLineNo">155</span>        if (StringUtils.isBlank(qualifier)) {<a name="line.155"></a>
+<span class="sourceLineNo">156</span>          scan.addFamily(Bytes.toBytes(family));<a name="line.156"></a>
+<span class="sourceLineNo">157</span>        }<a name="line.157"></a>
+<span class="sourceLineNo">158</span>        else {<a name="line.158"></a>
+<span class="sourceLineNo">159</span>          scan.addColumn(Bytes.toBytes(family), Bytes.toBytes(qualifier));<a name="line.159"></a>
+<span class="sourceLineNo">160</span>        }<a name="line.160"></a>
+<span class="sourceLineNo">161</span>      }<a name="line.161"></a>
+<span class="sourceLineNo">162</span>    }<a name="line.162"></a>
+<span class="sourceLineNo">163</span>    scan.setTimeRange(startTime, endTime == 0 ? HConstants.LATEST_TIMESTAMP : endTime);<a name="line.163"></a>
+<span class="sourceLineNo">164</span>    job.setOutputFormatClass(NullOutputFormat.class);<a name="line.164"></a>
+<span class="sourceLineNo">165</span>    TableMapReduceUtil.initTableMapperJob(tableName, scan,<a name="line.165"></a>
+<span class="sourceLineNo">166</span>      RowCounterMapper.class, ImmutableBytesWritable.class, Result.class, job);<a name="line.166"></a>
+<span class="sourceLineNo">167</span>    job.setNumReduceTasks(0);<a name="line.167"></a>
+<span class="sourceLineNo">168</span>    return job;<a name="line.168"></a>
+<span class="sourceLineNo">169</span>  }<a name="line.169"></a>
+<span class="sourceLineNo">170</span><a name="line.170"></a>
+<span class="sourceLineNo">171</span>  private static List&lt;MultiRowRangeFilter.RowRange&gt; parseRowRangeParameter(<a name="line.171"></a>
+<span class="sourceLineNo">172</span>    String arg, String rangeSwitch) {<a name="line.172"></a>
+<span class="sourceLineNo">173</span>    final String[] ranges = arg.substring(rangeSwitch.length()).split(";");<a name="line.173"></a>
+<span class="sourceLineNo">174</span>    final List&lt;MultiRowRangeFilter.RowRange&gt; rangeList = new ArrayList&lt;&gt;();<a name="line.174"></a>
+<span class="sourceLineNo">175</span>    for (String range : ranges) {<a name="line.175"></a>
+<span class="sourceLineNo">176</span>      String[] startEnd = range.split(",", 2);<a name="line.176"></a>
+<span class="sourceLineNo">177</span>      if (startEnd.length != 2 || startEnd[1].contains(",")) {<a name="line.177"></a>
+<span class="sourceLineNo">178</span>        printUsage("Please specify range in such format as \"--range=a,b\" " +<a name="line.178"></a>
+<span class="sourceLineNo">179</span>            "or, with only one boundary, \"--range=,b\" or \"--range=a,\"");<a name="line.179"></a>
+<span class="sourceLineNo">180</span>        throw new IllegalArgumentException("Wrong range specification: " + range);<a name="line.180"></a>
+<span class="sourceLineNo">181</span>      }<a name="line.181"></a>
+<span class="sourceLineNo">182</span>      String startKey = startEnd[0];<a name="line.182"></a>
+<span class="sourceLineNo">183</span>      String endKey = startEnd[1];<a name="line.183"></a>
+<span class="sourceLineNo">184</span>      rangeList.add(new MultiRowRangeFilter.RowRange(<a name="line.184"></a>
+<span class="sourceLineNo">185</span>        Bytes.toBytesBinary(startKey), true,<a name="line.185"></a>
+<span class="sourceLineNo">186</span>        Bytes.toBytesBinary(endKey), false));<a name="line.186"></a>
+<span class="sourceLineNo">187</span>    }<a name="line.187"></a>
+<span class="sourceLineNo">188</span>    return rangeList;<a name="line.188"></a>
+<span class="sourceLineNo">189</span>  }<a name="line.189"></a>
+<span class="sourceLineNo">190</span><a name="line.190"></a>
+<span class="sourceLineNo">191</span>  /**<a name="line.191"></a>
+<span class="sourceLineNo">192</span>   * Sets filter {@link FilterBase} to the {@link Scan} instance.<a name="line.192"></a>
+<span class="sourceLineNo">193</span>   * If provided rowRangeList contains more than one element,<a name="line.193"></a>
+<span class="sourceLineNo">194</span>   * method sets filter which is instance of {@link MultiRowRangeFilter}.<a name="line.194"></a>
+<span class="sourceLineNo">195</span>   * Otherwise, method sets filter which is instance of {@link FirstKeyOnlyFilter}.<a name="line.195"></a>
+<span class="sourceLineNo">196</span>   * If rowRangeList contains exactly one element, startRow and stopRow are set to the scan.<a name="line.196"></a>
+<span class="sourceLineNo">197</span>   * @param scan<a name="line.197"></a>
+<span class="sourceLineNo">198</span>   * @param rowRangeList<a name="line.198"></a>
+<span class="sourceLineNo">199</span>   */<a name="line.199"></a>
+<span class="sourceLineNo">200</span>  private static void setScanFilter(Scan scan, List&lt;MultiRowRangeFilter.RowRange&gt; rowRangeList) {<a name="line.200"></a>
+<span class="sourceLineNo">201</span>    final int size = rowRangeList == null ? 0 : rowRangeList.size();<a name="line.201"></a>
+<span class="sourceLineNo">202</span>    if (size &lt;= 1) {<a name="line.202"></a>
+<span class="sourceLineNo">203</span>      scan.setFilter(new FirstKeyOnlyFilter());<a name="line.203"></a>
+<span class="sourceLineNo">204</span>    }<a name="line.204"></a>
+<span class="sourceLineNo">205</span>    if (size == 1) {<a name="line.205"></a>
+<span class="sourceLineNo">206</span>      MultiRowRangeFilter.RowRange range = rowRangeList.get(0);<a name="line.206"></a>
+<span class="sourceLineNo">207</span>      scan.setStartRow(range.getStartRow()); //inclusive<a name="line.207"></a>
+<span class="sourceLineNo">208</span>      scan.setStopRow(range.getStopRow());   //exclusive<a name="line.208"></a>
+<span class="sourceLineNo">209</span>    } else if (size &gt; 1) {<a name="line.209"></a>
+<span class="sourceLineNo">210</span>      try {<a name="line.210"></a>
+<span class="sourceLineNo">211</span>        scan.setFilter(new MultiRowRangeFilter(rowRangeList));<a name="line.211"></a>
+<span class="sourceLineNo">212</span>      } catch (IOException e) {<a name="line.212"></a>
+<span class="sourceLineNo">213</span>        //the IOException should never be thrown. see HBASE-16145<a name="line.213"></a>
+<span class="sourceLineNo">214</span>        throw new RuntimeException("Cannot instantiate MultiRowRangeFilter");<a name="line.214"></a>
+<span class="sourceLineNo">215</span>      }<a name="line.215"></a>
+<span class="sourceLineNo">216</span>    }<a name="line.216"></a>
+<span class="sourceLineNo">217</span>  }<a name="line.217"></a>
+<span class="sourceLineNo">218</span><a name="line.218"></a>
+<span class="sourceLineNo">219</span>  /*<a name="line.219"></a>
+<span class="sourceLineNo">220</span>   * @param errorMessage Can attach a message when error occurs.<a name="line.220"></a>
+<span class="sourceLineNo">221</span>   */<a name="line.221"></a>
+<span class="sourceLineNo">222</span>  private static void printUsage(String errorMessage) {<a name="line.222"></a>
+<span class="sourceLineNo">223</span>    System.err.println("ERROR: " + errorMessage);<a name="line.223"></a>
+<span class="sourceLineNo">224</span>    printUsage();<a name="line.224"></a>
+<span class="sourceLineNo">225</span>  }<a name="line.225"></a>
+<span class="sourceLineNo">226</span><a name="line.226"></a>
+<span class="sourceLineNo">227</span>  /**<a name="line.227"></a>
+<span class="sourceLineNo">228</span>   * Prints usage without error message.<a name="line.228"></a>
+<span class="sourceLineNo">229</span>   * Note that we don't document --expected-count, because it's intended for test.<a name="line.229"></a>
+<span class="sourceLineNo">230</span>   */<a name="line.230"></a>
+<span class="sourceLineNo">231</span>  private static void printUsage() {<a name="line.231"></a>
+<span class="sourceLineNo">232</span>    System.err.println("Usage: RowCounter [options] &lt;tablename&gt; " +<a name="line.232"></a>
+<span class="sourceLineNo">233</span>        "[--starttime=[start] --endtime=[end] " +<a name="line.233"></a>
+<span class="sourceLineNo">234</span>        "[--range=[startKey],[endKey][;[startKey],[endKey]...]] [&lt;column1&gt; &lt;column2&gt;...]");<a name="line.234"></a>
+<span class="sourceLineNo">235</span>    System.err.println("For performance consider the following options:\n"<a name="line.235"></a>
+<span class="sourceLineNo">236</span>        + "-Dhbase.client.scanner.caching=100\n"<a name="line.236"></a>
+<span class="sourceLineNo">237</span>        + "-Dmapreduce.map.speculative=false");<a name="line.237"></a>
+<span class="sourceLineNo">238</span>  }<a name="line.238"></a>
+<span class="sourceLineNo">239</span><a name="line.239"></a>
+<span class="sourceLineNo">240</span>  @Override<a name="line.240"></a>
+<span class="sourceLineNo">241</span>  public int run(String[] args) throws Exception {<a name="line.241"></a>
+<span class="sourceLineNo">242</span>    if (args.length &lt; 1) {<a name="line.242"></a>
+<span class="sourceLineNo">243</span>      printUsage("Wrong number of parameters: " + args.length);<a name="line.243"></a>
+<span class="sourceLineNo">244</span>      return -1;<a name="line.244"></a>
+<span class="sourceLineNo">245</span>    }<a name="line.245"></a>
+<span class="sourceLineNo">246</span>    Job job = createSubmittableJob(getConf(), args);<a name="line.246"></a>
+<span class="sourceLineNo">247</span>    if (job == null) {<a name="line.247"></a>
+<span class="sourceLineNo">248</span>      return -1;<a name="line.248"></a>
+<span class="sourceLineNo">249</span>    }<a name="line.249"></a>
+<span class="sourceLineNo">250</span>    boolean success = job.waitForCompletion(true);<a name="line.250"></a>
+<span class="sourceLineNo">251</span>    final long expectedCount = getConf().getLong(EXPECTED_COUNT_KEY, -1);<a name="line.251"></a>
+<span class="sourceLineNo">252</span>    if (success &amp;&amp; expectedCount != -1) {<a name="line.252"></a>
+<span class="sourceLineNo">253</span>      final Counter counter = job.getCounters().findCounter(RowCounterMapper.Counters.ROWS);<a name="line.253"></a>
+<span class="sourceLineNo">254</span>      success = expectedCount == counter.getValue();<a name="line.254"></a>
+<span class="sourceLineNo">255</span>      if (!success) {<a name="line.255"></a>
+<span class="sourceLineNo">256</span>        LOG.error("Failing job because count of '" + counter.getValue() +<a name="line.256"></a>
+<span class="sourceLineNo">257</span>            "' does not match expected count of '" + expectedCount + "'");<a name="line.257"></a>
+<span class="sourceLineNo">258</span>      }<a name="line.258"></a>
+<span class="sourceLineNo">259</span>    }<a name="line.259"></a>
+<span class="sourceLineNo">260</span>    return (success ? 0 : 1);<a name="line.260"></a>
+<span class="sourceLineNo">261</span>  }<a name="line.261"></a>
+<span class="sourceLineNo">262</span><a name="line.262"></a>
+<span class="sourceLineNo">263</span>  /**<a name="line.263"></a>
+<span class="sourceLineNo">264</span>   * Main entry point.<a name="line.264"></a>
+<span class="sourceLineNo">265</span>   * @param args The command line parameters.<a name="line.265"></a>
+<span class="sourceLineNo">266</span>   * @throws Exception When running the job fails.<a name="line.266"></a>
+<span class="sourceLineNo">267</span>   */<a name="line.267"></a>
+<span class="sourceLineNo">268</span>  public static void main(String[] args) throws Exception {<a name="line.268"></a>
+<span class="sourceLineNo">269</span>    int errCode = ToolRunner.run(HBaseConfiguration.create(), new RowCounter(), args);<a name="line.269"></a>
+<span class="sourceLineNo">270</span>    System.exit(errCode);<a name="line.270"></a>
+<span class="sourceLineNo">271</span>  }<a name="line.271"></a>
+<span class="sourceLineNo">272</span><a name="line.272"></a>
+<span class="sourceLineNo">273</span>}<a name="line.273"></a>
 
 
 


Mime
View raw message