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