InputFormat to Key-value generation process

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.