Hadoop implements AbstractJob to simplify Job settings

Source: Internet
Author: User

Writing a job in hadoop generally adopts the following method: [java] Job job = new Job (); job. setXxx ();... in this way, there are a lot of codes, and the parameters are not easy to control. For example, I want to control the input parameters and write some code such as control parsing, as follows: [java] if (args. length! = 2) {System. err. out ("Usage <input> <output>")}. In addition, the above is only a rough judgment, but it is not very accurate. Is there a better way to reduce the amount of code without setting it? In fact, you can implement the AbstractJob class in Mahout, as follows: [java] package mahout. fansy. bayes. transform; import org. apache. hadoop. conf. configuration; import org. apache. hadoop. fs. path; import org. apache. hadoop. io. longWritable; import org. apache. hadoop. io. text; import org. apache. hadoop. mapreduce. job; import org. apache. hadoop. mapreduce. mapper; import org. apache. hadoop. mapreduce. lib. input. fileInputFormat; import org. apache. hadoop. mapreduce. lib. output. sequenceFileOutputFormat; import org. apache. hadoop. util. toolRunner; import org. apache. mahout. common. abstractJob; import org. apache. mahout. math. vectorWritable; public class extends actjob {@ Override public int run (String [] args) throws Exception {addInputOption (); addOutputOption (); addOption ("splitCharacter", "SC ", "vector split character, default is ','", ","); if (parseArguments (args) = null) {return-1;} Path input = getInputPath (); path output = getOutputPath (); String SC = getOption ("splitCharacter"); Job job = prepareJob (input, output, FileInputFormat. class, Mapper. class, LongWritable. class, Text. class, null, Text. class, VectorWritable. class, SequenceFileOutputFormat. class); job. getConfiguration (). set ("SC", SC); if (job. waitForCompletion (true) {return 0;} return-1 ;} /*** implement AbstractJob * @ param args * @ throws Exception */public static void main (String [] args) throws Exception {String [] arg = new String [] {"-I", "safdf", "-SC", "scccccccc", "-o ", "sdf"}; ToolRunner. run (new Configuration (), new TFText2VectorWritable (), arg );}}

Related Article

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.