1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements.  See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership.  The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License.  You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 package org.apache.hadoop.mapred;
20 
21 import java.io.IOException;
22 
23 import org.apache.hadoop.classification.InterfaceAudience;
24 import org.apache.hadoop.classification.InterfaceStability;
25 
26 /**
27  * <code>RecordReader</code> reads &lt;key, value&gt; pairs from an
28  * {@link InputSplit}.
29  *
30  * <p><code>RecordReader</code>, typically, converts the byte-oriented view of
31  * the input, provided by the <code>InputSplit</code>, and presents a
32  * record-oriented view for the {@link Mapper} and {@link Reducer} tasks for
33  * processing. It thus assumes the responsibility of processing record
34  * boundaries and presenting the tasks with keys and values.</p>
35  *
36  * @see InputSplit
37  * @see InputFormat
38  */
39 @InterfaceAudience.Public
40 @InterfaceStability.Stable
41 public interface RecordReader<K, V> {
42   /**
43    * Reads the next key/value pair from the input for processing.
44    *
45    * @param key the key to read data into
46    * @param value the value to read data into
47    * @return true iff a key/value was read, false if at EOF
48    */
next(K key, V value)49   boolean next(K key, V value) throws IOException;
50 
51   /**
52    * Create an object of the appropriate type to be used as a key.
53    *
54    * @return a new key object.
55    */
createKey()56   K createKey();
57 
58   /**
59    * Create an object of the appropriate type to be used as a value.
60    *
61    * @return a new value object.
62    */
createValue()63   V createValue();
64 
65   /**
66    * Returns the current position in the input.
67    *
68    * @return the current position in the input.
69    * @throws IOException
70    */
getPos()71   long getPos() throws IOException;
72 
73   /**
74    * Close this {@link InputSplit} to future operations.
75    *
76    * @throws IOException
77    */
close()78   public void close() throws IOException;
79 
80   /**
81    * How much of the input has the {@link RecordReader} consumed i.e.
82    * has been processed by?
83    *
84    * @return progress from <code>0.0</code> to <code>1.0</code>.
85    * @throws IOException
86    */
getProgress()87   float getProgress() throws IOException;
88 }
89