To sort key and value using composite key-value pairs

Source: Internet
Author: User

1  PackageKeysort;2 Importjava.io.IOException;3 4 Importorg.apache.hadoop.conf.Configuration;5 ImportOrg.apache.hadoop.io.Text;6 ImportOrg.apache.hadoop.mapreduce.Job;7 ImportOrg.apache.hadoop.mapreduce.Mapper;8 ImportOrg.apache.hadoop.mapreduce.Partitioner;9 ImportOrg.apache.hadoop.mapreduce.lib.input.FileInputFormat;Ten ImportOrg.apache.hadoop.mapreduce.lib.output.FileOutputFormat; One ImportOrg.apache.hadoop.fs.Path; A  Public classKeysort { -      Public Static classMymapperextendsMapper<object, text, text, text> { -         PrivateText map_value=NewText ("Hello");  the          Public voidMap (Object key,text value,context Context)throwsIOException, interruptedexception{ - context.write (value, map_value); -         } -     } +      -      Public Static classMypartitionerextendsPartitioner<text, text>{ +          PublicText realkey=NewText (); A @Override at          Public intGetpartition (text key, text value,intnumredtasks) { -             //TODO Auto-generated method stubs -String[] Kk=key.tostring (). Split ("\ T"); -Realkey.set (kk[0]); -SYSTEM.OUT.PRINTLN ("Partition key is:" +realkey.tostring ()); -             return((Realkey.hashcode () &integer.max_value)%numredtasks); in         } -          to     } +  -      Public Static voidMain (string[] args)throwsException the     { *         if(args.length!=2){ $System.err.println ("usage:matrixmultiply <inputPathM> <inputPathN> <outputPath>");Panax NotoginsengSystem.exit (2); -                    } theConfiguration conf=NewConfiguration (); +Job job=NewJob (conf, "Seconderysort"); AJob.setnumreducetasks (1);//when set to 0, the partitioning process is not performed and cannot be exploited with Jian Zhi theJob.setjarbyclass (Keysort.class); +Job.setmapperclass (Mymapper.class); -Job.setpartitionerclass (Mypartitioner.class); $Job.setoutputkeyclass (Text.class); $Job.setoutputvalueclass (Text.class); -Fileinputformat.setinputpaths (Job,NewPath (args[0])); -Fileoutputformat.setoutputpath (Job,NewPath (args[1])); theSystem.exit (Job.waitforcompletion (true)? 0:1); -         Wuyi     } the          -     } Wu      -      About      $      -     

To sort key and value using composite key-value pairs

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.