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 */
018
019package org.apache.hadoop.mapreduce;
020
021import java.io.Closeable;
022import java.io.IOException;
023
024import org.apache.hadoop.classification.InterfaceAudience;
025import org.apache.hadoop.classification.InterfaceStability;
026
027/**
028 * The record reader breaks the data into key/value pairs for input to the
029 * {@link Mapper}.
030 * @param <KEYIN>
031 * @param <VALUEIN>
032 */
033@InterfaceAudience.Public
034@InterfaceStability.Stable
035public abstract class RecordReader<KEYIN, VALUEIN> implements Closeable {
036
037  /**
038   * Called once at initialization.
039   * @param split the split that defines the range of records to read
040   * @param context the information about the task
041   * @throws IOException
042   * @throws InterruptedException
043   */
044  public abstract void initialize(InputSplit split,
045                                  TaskAttemptContext context
046                                  ) throws IOException, InterruptedException;
047
048  /**
049   * Read the next key, value pair.
050   * @return true if a key/value pair was read
051   * @throws IOException
052   * @throws InterruptedException
053   */
054  public abstract 
055  boolean nextKeyValue() throws IOException, InterruptedException;
056
057  /**
058   * Get the current key
059   * @return the current key or null if there is no current key
060   * @throws IOException
061   * @throws InterruptedException
062   */
063  public abstract
064  KEYIN getCurrentKey() throws IOException, InterruptedException;
065  
066  /**
067   * Get the current value.
068   * @return the object that was read
069   * @throws IOException
070   * @throws InterruptedException
071   */
072  public abstract 
073  VALUEIN getCurrentValue() throws IOException, InterruptedException;
074  
075  /**
076   * The current progress of the record reader through its data.
077   * @return a number between 0.0 and 1.0 that is the fraction of the data read
078   * @throws IOException
079   * @throws InterruptedException
080   */
081  public abstract float getProgress() throws IOException, InterruptedException;
082  
083  /**
084   * Close the record reader.
085   */
086  public abstract void close() throws IOException;
087}