View Javadoc

1   /**
2    *
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *     http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   */
19  package org.apache.hadoop.hbase.mapred;
20  
21  import java.io.IOException;
22  
23  import org.apache.hadoop.hbase.classification.InterfaceAudience;
24  import org.apache.hadoop.hbase.classification.InterfaceStability;
25  import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
26  import org.apache.hadoop.hbase.client.Result;
27  import org.apache.hadoop.mapred.JobConf;
28  import org.apache.hadoop.mapred.MapReduceBase;
29  import org.apache.hadoop.mapred.OutputCollector;
30  import org.apache.hadoop.mapred.Reporter;
31  
32  /**
33   * Pass the given key and record as-is to reduce
34   */
35  @InterfaceAudience.Public
36  @InterfaceStability.Stable
37  public class IdentityTableMap
38  extends MapReduceBase
39  implements TableMap<ImmutableBytesWritable, Result> {
40  
41    /** constructor */
42    public IdentityTableMap() {
43      super();
44    }
45  
46    /**
47     * Use this before submitting a TableMap job. It will
48     * appropriately set up the JobConf.
49     *
50     * @param table table name
51     * @param columns columns to scan
52     * @param mapper mapper class
53     * @param job job configuration
54     */
55    @SuppressWarnings("unchecked")
56    public static void initJob(String table, String columns,
57      Class<? extends TableMap> mapper, JobConf job) {
58      TableMapReduceUtil.initTableMapJob(table, columns, mapper,
59        ImmutableBytesWritable.class,
60        Result.class, job);
61    }
62  
63    /**
64     * Pass the key, value to reduce
65     * @param key
66     * @param value
67     * @param output
68     * @param reporter
69     * @throws IOException
70     */
71    public void map(ImmutableBytesWritable key, Result value,
72        OutputCollector<ImmutableBytesWritable,Result> output,
73        Reporter reporter) throws IOException {
74  
75      // convert
76      output.collect(key, value);
77    }
78  }