View Javadoc

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