001/**
002 *
003 * Licensed to the Apache Software Foundation (ASF) under one
004 * or more contributor license agreements.  See the NOTICE file
005 * distributed with this work for additional information
006 * regarding copyright ownership.  The ASF licenses this file
007 * to you under the Apache License, Version 2.0 (the
008 * "License"); you may not use this file except in compliance
009 * with the License.  You may obtain a copy of the License at
010 *
011 *     http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing, software
014 * distributed under the License is distributed on an "AS IS" BASIS,
015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016 * See the License for the specific language governing permissions and
017 * limitations under the License.
018 */
019package org.apache.hadoop.hbase.mapreduce;
020
021import java.io.IOException;
022
023import org.apache.yetus.audience.InterfaceAudience;
024import org.apache.hadoop.hbase.client.Result;
025import org.apache.hadoop.hbase.client.Scan;
026import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
027import org.apache.hadoop.mapreduce.Job;
028
029/**
030 * Pass the given key and record as-is to the reduce phase.
031 */
032@InterfaceAudience.Public
033public class IdentityTableMapper
034extends TableMapper<ImmutableBytesWritable, Result> {
035
036  /**
037   * Use this before submitting a TableMap job. It will appropriately set up
038   * the job.
039   *
040   * @param table  The table name.
041   * @param scan  The scan with the columns to scan.
042   * @param mapper  The mapper class.
043   * @param job  The job configuration.
044   * @throws IOException When setting up the job fails.
045   */
046  @SuppressWarnings("rawtypes")
047  public static void initJob(String table, Scan scan,
048    Class<? extends TableMapper> mapper, Job job) throws IOException {
049    TableMapReduceUtil.initTableMapperJob(table, scan, mapper,
050      ImmutableBytesWritable.class, Result.class, job);
051  }
052
053  /**
054   * Pass the key, value to reduce.
055   *
056   * @param key  The current key.
057   * @param value  The current value.
058   * @param context  The current context.
059   * @throws IOException When writing the record fails.
060   * @throws InterruptedException When the job is aborted.
061   */
062  public void map(ImmutableBytesWritable key, Result value, Context context)
063  throws IOException, InterruptedException {
064    context.write(key, value);
065  }
066
067}