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.mapred;
019
020import java.io.IOException;
021import org.apache.hadoop.hbase.client.Result;
022import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
023import org.apache.hadoop.mapred.JobConf;
024import org.apache.hadoop.mapred.MapReduceBase;
025import org.apache.hadoop.mapred.OutputCollector;
026import org.apache.hadoop.mapred.Reporter;
027import org.apache.yetus.audience.InterfaceAudience;
028
029/**
030 * Pass the given key and record as-is to reduce
031 */
032@InterfaceAudience.Public
033public class IdentityTableMap extends MapReduceBase
034  implements TableMap<ImmutableBytesWritable, Result> {
035
036  /** constructor */
037  public IdentityTableMap() {
038    super();
039  }
040
041  /**
042   * Use this before submitting a TableMap job. It will appropriately set up the JobConf.
043   * @param table   table name
044   * @param columns columns to scan
045   * @param mapper  mapper class
046   * @param job     job configuration
047   */
048  @SuppressWarnings("unchecked")
049  public static void initJob(String table, String columns, Class<? extends TableMap> mapper,
050    JobConf job) {
051    TableMapReduceUtil.initTableMapJob(table, columns, mapper, ImmutableBytesWritable.class,
052      Result.class, job);
053  }
054
055  /**
056   * Pass the key, value to reduce
057   */
058  public void map(ImmutableBytesWritable key, Result value,
059    OutputCollector<ImmutableBytesWritable, Result> output, Reporter reporter) throws IOException {
060
061    // convert
062    output.collect(key, value);
063  }
064}