Changeset 9 for sample/WordCount.java


Ignore:
Timestamp:
Jun 13, 2008, 5:45:02 PM (16 years ago)
Author:
waue
Message:

comment

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sample/WordCount.java

    r8 r9  
    1 /*
    2  * map reduce sample code
     1/**
     2 * Program: WordCount.java
     3 * Editor: Waue Chen
     4 * From :  NCHC. Taiwn
     5 * Last Update Date: 06/13/2008
     6 */
     7
     8/**
     9 * Purpose :
     10 *  Store the result of WordCount.java from Hbase to Hadoop file system
     11 *
     12 * HowToUse :
     13 *  Make sure Hadoop file system is running correctly.
     14 *  Put text file on the directory "/local_src/input"
     15 *  You can use the instruction to upload "/local_src/input" to HDFS input dir
     16 *    $ bin/hadoop dfs -put /local_src/input input
     17 *  Then modify the $filepath parameter in construtor to be correct and run this code.
     18 * 
     19 *
     20 * Check Result:
     21 *  inspect http://localhost:50070 by web explorer
    322 */
    423package tw.org.nchc.code;
     
    2342
    2443public class WordCount {
    25 
     44  private String filepath;
     45  private String outputPath;
     46 
     47  public WordCount(){
     48    filepath = "/user/waue/input/";
     49    outputPath = "counts1";
     50  }
     51  public WordCount(String path,String output){
     52    filepath = path;
     53    outputPath = output;
     54  }
    2655  // mapper: emits (token, 1) for every word occurrence
    2756  private static class MapClass extends MapReduceBase implements
     
    6998   */
    7099  public static void main(String[] args) throws IOException {
    71     String filename = "/user/waue/input/";
    72     String outputPath = "sample-counts";
    73     int mapTasks = 20;
     100    WordCount wc = new WordCount();
     101   
     102    int mapTasks = 1;
    74103    int reduceTasks = 1;
    75 
    76104    JobConf conf = new JobConf(WordCount.class);
    77105    conf.setJobName("wordcount");
     
    80108    conf.setNumReduceTasks(reduceTasks);
    81109
    82     conf.setInputPath(new Path(filename));
     110    conf.setInputPath(new Path(wc.filepath));
    83111    conf.setOutputKeyClass(Text.class);
    84112    conf.setOutputValueClass(IntWritable.class);
    85     conf.setOutputPath(new Path(outputPath));
     113    conf.setOutputPath(new Path(wc.outputPath));
    86114
    87115    conf.setMapperClass(MapClass.class);
     
    90118   
    91119    // Delete the output directory if it exists already
    92     Path outputDir = new Path(outputPath);
     120    Path outputDir = new Path(wc.outputPath);
    93121    FileSystem.get(conf).delete(outputDir);
    94122
Note: See TracChangeset for help on using the changeset viewer.