Hadoop: input, output, key, value format

Source: Internet
Author: User
Map: (K1, V1) → list (K2, V2)
Reduce: (K2, list (V2) → list (K3, V3)

(K1, V1 ):
Jobconf. setinputkeyclass (K1.Class);
Jobconf. setinputvalueclass (v1.Class);

List (K2, V2 ):
Job. setmapoutputkeyclass (K2.Class);
Job. setmapoutputvalueclass (V2.Class);

List (K3, V3 ):
Jobconf. setoutputkeyclass (K3.Class);
Jobconf. setoutputvalueclass (V3.Class);

 Jobconf. setinputformat (myinputformat. Class); inputformat: Textinputformat: used to read plain text files. Files are divided into a series of rows ending with LF or Cr. The key is the offset of each row (longwritable), and the value is the content of each row (text ). Keyvaluetextinputformat: used to read files. If the row is split into two parts by a separator, the first part is the key, and the remaining part is the value. If there is no separator, the entire row is used as the key, and the value is null. Sequencefileinputformat: used to read sequencefile. The read format must be consistent with the setoutputkeyclass set when writing sequencefileoutputformat (Key + value format ). Sequencefileinputfilter: Based on the filter, the data that meets the conditions is obtained from sequencefile, and the filter is specified through setfilterclass. Three filters are built in, and the record that regexfilter obtains the key value that meets the specified regular expression; percentfilter uses the specified parameter F to retrieve records with the number of record rows F % = 0; md5filter uses the specified parameter F to retrieve records with MD5 (key) % F = 0. Example: Conf. setinputformat (keyvaluetextinputformat. Class ); Jobconf. setoutputformat (myoutputformat. Class); setoutputformat: Textoutputformat: output to a plain text file in the format of key + "" + value. Nulloutputformat:/dev/null in hadoop, which sends the output to the black hole. Sequencefileoutputformat: Output sequencefile. The specific format is related to setoutputkeyclass and delimiter. In this case, the read format of sequencefileinputformat should be consistent with the output format of sequencefileoutputformat (Key + value format) encoding, multipletexto: output records to different files based on keys. You can rewrite dbinputformat and dboutputformat to read and output records from dB to DB. Example: Conf. setoutputformat (textoutputformat. Class );

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.