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