Public abstract class Inputformat<k, v> {
public abstract
List<inputsplit> Getsplits (Jobcontext context
) throws IOException, interruptedexception;
public abstract
Recordreader<k,v> Createrecordreader (Inputsplit split,
Taskattemptcontext context
) throws IOException,
Interruptedexception;
}
Public abstract class Fileinputformat<k, v> extends Inputformat<k, v> {
public class Textinputformat extends Fileinputformat<longwritable, text> {
Getsplits method to get the number of slices in the input file, each split corresponds to a map.
Create the Recordreader, the Recordreader receives the split well, realizes Nextkeyvalue, Getcurrentkey, GetCurrentValue.
As shown below, each map class inherits the Mapper class, and in the Mapper class, the Run method invokes Recordreader in InputFormat to get the key, value
public class Mapper<keyin, Valuein, Keyout, valueout> {
/**
* Expert users can override this method for more complete control over the
* Execution of the Mapper.
* @param context
* @throws IOException
*/
public void run (context context) throws IOException, Interruptedexception {
Setup (context);
try {
while (Context.nextkeyvalue ()) {
Map (Context.getcurrentkey (), Context.getcurrentvalue (), context);
}
} finally {
Cleanup (context);
}
}
}
InputFormat to Key-value generation process