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
019 package org.apache.hadoop.mapred;
020
021 import java.io.IOException;
022
023 import org.apache.hadoop.classification.InterfaceAudience;
024 import org.apache.hadoop.classification.InterfaceStability;
025
026 /**
027 * <code>RecordReader</code> reads <key, value> pairs from an
028 * {@link InputSplit}.
029 *
030 * <p><code>RecordReader</code>, typically, converts the byte-oriented view of
031 * the input, provided by the <code>InputSplit</code>, and presents a
032 * record-oriented view for the {@link Mapper} & {@link Reducer} tasks for
033 * processing. It thus assumes the responsibility of processing record
034 * boundaries and presenting the tasks with keys and values.</p>
035 *
036 * @see InputSplit
037 * @see InputFormat
038 */
039 @InterfaceAudience.Public
040 @InterfaceStability.Stable
041 public interface RecordReader<K, V> {
042 /**
043 * Reads the next key/value pair from the input for processing.
044 *
045 * @param key the key to read data into
046 * @param value the value to read data into
047 * @return true iff a key/value was read, false if at EOF
048 */
049 boolean next(K key, V value) throws IOException;
050
051 /**
052 * Create an object of the appropriate type to be used as a key.
053 *
054 * @return a new key object.
055 */
056 K createKey();
057
058 /**
059 * Create an object of the appropriate type to be used as a value.
060 *
061 * @return a new value object.
062 */
063 V createValue();
064
065 /**
066 * Returns the current position in the input.
067 *
068 * @return the current position in the input.
069 * @throws IOException
070 */
071 long getPos() throws IOException;
072
073 /**
074 * Close this {@link InputSplit} to future operations.
075 *
076 * @throws IOException
077 */
078 public void close() throws IOException;
079
080 /**
081 * How much of the input has the {@link RecordReader} consumed i.e.
082 * has been processed by?
083 *
084 * @return progress from <code>0.0</code> to <code>1.0</code>.
085 * @throws IOException
086 */
087 float getProgress() throws IOException;
088 }