Changeset 18 for sample/WordCount.java


Ignore:
Timestamp:
Jul 2, 2008, 3:10:09 PM (16 years ago)
Author:
waue
Message:

upgrade 0.16 to 0.17

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sample/WordCount.java

    r9 r18  
    33 * Editor: Waue Chen
    44 * From :  NCHC. Taiwn
    5  * Last Update Date: 06/13/2008
     5 * Last Update Date: 07/02/2008
     6 * Upgrade to 0.17
    67 */
    78
     
    4041import org.apache.hadoop.mapred.Reporter;
    4142
    42 
    4343public class WordCount {
    4444  private String filepath;
     45
    4546  private String outputPath;
    46  
    47   public WordCount(){
     47
     48  public WordCount() {
    4849    filepath = "/user/waue/input/";
    4950    outputPath = "counts1";
    5051  }
    51   public WordCount(String path,String output){
     52
     53  public WordCount(String path, String output) {
    5254    filepath = path;
    5355    outputPath = output;
    5456  }
     57
    5558  // mapper: emits (token, 1) for every word occurrence
    5659  private static class MapClass extends MapReduceBase implements
     
    5962    // reuse objects to save overhead of object creation
    6063    private final static IntWritable one = new IntWritable(1);
     64
    6165    private Text word = new Text();
    6266
     
    9397  }
    9498
    95  
    9699  /**
    97100   * Runs the demo.
     
    99102  public static void main(String[] args) throws IOException {
    100103    WordCount wc = new WordCount();
    101    
     104
    102105    int mapTasks = 1;
    103106    int reduceTasks = 1;
     
    107110    conf.setNumMapTasks(mapTasks);
    108111    conf.setNumReduceTasks(reduceTasks);
    109 
    110     conf.setInputPath(new Path(wc.filepath));
     112    // 0.16
     113    // conf.setInputPath(new Path(wc.filepath));
     114    Convert.setInputPath(conf, new Path(wc.filepath));
    111115    conf.setOutputKeyClass(Text.class);
    112116    conf.setOutputValueClass(IntWritable.class);
    113     conf.setOutputPath(new Path(wc.outputPath));
     117    // 0.16
     118    // conf.setOutputPath(new Path(wc.outputPath));
     119    Convert.setOutputPath(conf, new Path(wc.outputPath));
    114120
    115121    conf.setMapperClass(MapClass.class);
    116122    conf.setCombinerClass(ReduceClass.class);
    117123    conf.setReducerClass(ReduceClass.class);
    118    
     124
    119125    // Delete the output directory if it exists already
    120126    Path outputDir = new Path(wc.outputPath);
    121     FileSystem.get(conf).delete(outputDir);
     127    // 0.16
     128    FileSystem.get(conf).delete(outputDir,true);
    122129
    123130    JobClient.runJob(conf);
Note: See TracChangeset for help on using the changeset viewer.