Custom Partitions in MapReduce

Source: Internet
Author: User
The data for the reducer task is derived from the Mapper task, which is to say that the mapper task divides the data and runs on different reducer tasks for different data. The process of dividing data by mapper tasks is called partition. The class responsible for implementing the partitioning data is called Partitioner.

The default partition class is Hashpartitioner, which handles the output of the mapper task, the Getpartition () method has three parameters, and key, value refers to the output of the Mapper task, respectively. Numreducetasks refers to the number of reducer tasks set, the default value is 1. Then the remainder of any integer dividing with 1 is certainly 0. That is to say Getpartition (...) The return value of the method is always 0. That is, the output of the mapper task is always given to a reducer task and can only be exported to a single file.

Based on this analysis, if you want to customize the partition and eventually output to multiple files, the data in the Mapper task should be divided into multiple extents. So, we only need to overwrite the Partitioner class of Getpartition (...), according to certain rules let getpartition (...) The return value of the method is 0,1,2,3 .... and two settings in the drive.

Custom Partitions in MapReduce

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.