Test the MapReduce program on the local file system

Source: Internet
Author: User

In the process of developing a MapReduce program, you can first test the program on the local file system, rather than initially on HDFs, which is easier to debug.

with the as an example of the Maxtemperature program in the authoritative Hadoop guide, the entire project includes the following 3 source files, followed by the mapper program, the reducer program, and the Job startup program:

Maxtemperaturemapper.java, Maxtemperaturereducer.java,maxtemperaturedriver.java


The code for Maxtemperaturemapper.java and Maxtemperaturereducer.java can be found in the installation and use of Mrunit.


Maxtemperaturedriver.java

Import Org.apache.hadoop.conf.configured;import Org.apache.hadoop.fs.path;import org.apache.hadoop.io.IntWritable ; Import Org.apache.hadoop.io.text;import Org.apache.hadoop.mapreduce.job;import Org.apache.hadoop.mapreduce.lib.input.fileinputformat;import Org.apache.hadoop.mapreduce.lib.output.fileoutputformat;import Org.apache.hadoop.util.tool;import Org.apache.hadoop.util.toolrunner;public class Maxtemperaturedriver extends configured implements Tool {public int run ( String[] args) throws Exception {if (args.length! = 2) {System.err.printf ("Usage:%s [generic options] <input> <ou Tput>\n ", GetClass (). Getsimplename ()); Toolrunner.printgenericcommandusage (system.err); return-1;} Job Job = new Job (getconf (), "Max temperature"), Job.setjarbyclass (GetClass ()); Fileinputformat.addinputpath (Job, New Path (Args[0])); Fileoutputformat.setoutputpath (Job, New Path (args[1)); Job.setmapperclass (Maxtemperaturemapper.class); Job.setcombinerclass (Maxtemperaturereducer.class); Job.setreducerclass (MaxteMperaturereducer.class); Job.setoutputkeyclass (Text.class); Job.setoutputvalueclass (IntWritable.class); return Job.waitforcompletion (True)? 0:1;} public static void Main (string[] args) throws Exception {int exitCode = Toolrunner.run (New Maxtemperaturedriver (), args); S Ystem.exit (ExitCode);}}

The steps to execute the test program in Eclipse are as follows:

Select File maxtemperaturedriver.java--> right-click Run as-->run configurations-->new Launch configuration--> Select arguments to populate the program arguments with the input and output paths in the local file system, for example

File:///home/hadoop/inputfile:///home/hadoop/output
Click Apply--> to click Run.


After execution, you can determine whether the program is correct based on the contents of the output file.


Test the MapReduce program on the local file system

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.