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.mapreduce;
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.client.Result;
26 import org.apache.hadoop.hbase.client.Scan;
27 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
28 import org.apache.hadoop.mapreduce.Job;
29
30 /**
31 * Pass the given key and record as-is to the reduce phase.
32 */
33 @InterfaceAudience.Public
34 @InterfaceStability.Stable
35 public class IdentityTableMapper
36 extends TableMapper<ImmutableBytesWritable, Result> {
37
38 /**
39 * Use this before submitting a TableMap job. It will appropriately set up
40 * the job.
41 *
42 * @param table The table name.
43 * @param scan The scan with the columns to scan.
44 * @param mapper The mapper class.
45 * @param job The job configuration.
46 * @throws IOException When setting up the job fails.
47 */
48 @SuppressWarnings("rawtypes")
49 public static void initJob(String table, Scan scan,
50 Class<? extends TableMapper> mapper, Job job) throws IOException {
51 TableMapReduceUtil.initTableMapperJob(table, scan, mapper,
52 ImmutableBytesWritable.class, Result.class, job);
53 }
54
55 /**
56 * Pass the key, value to reduce.
57 *
58 * @param key The current key.
59 * @param value The current value.
60 * @param context The current context.
61 * @throws IOException When writing the record fails.
62 * @throws InterruptedException When the job is aborted.
63 */
64 public void map(ImmutableBytesWritable key, Result value, Context context)
65 throws IOException, InterruptedException {
66 context.write(key, value);
67 }
68
69 }