Custom Split mode in hadoop2.6.0

Source: Internet
Author: User

Recently studying Hadoop, using the hadoop2.6.0

Then, when learning to write a mapreduce program, it is found that the default input to the file is divided by each line, the following analysis of the way to change this segmentation:

Let's see how the default is implemented:

If you do not use the job's setinputformatclass () setting, the default InputFormat class is to use the Textinputformat class

Textinputformat class is inherited from Fileinputformat

Fileinputformat implements the InputFormat interface

As you can see in Textinputformat, the Linerecordreader class is called in the Getrecordreader function. We note that there is a delimiter parameter in the passed in parameter, which is used to specify the delimiter (you can view The implementation of the linerecordreader in the implementation of the file segmentation), So we can define a class Myinputformat inherit the Fileinputformat class and then

String delimiter = context.getconfiguration (). Get (
"Textinputformat.record.delimiter");

Instead:String delimiter = "END";

The "END" is the specified delimiter.

Then in the program, set the InputFormat class to Myinputformat.class in the job.

Custom Split mode in hadoop2.6.0

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.