Changeset 18 for sample/WordCount.java
- Timestamp:
- Jul 2, 2008, 3:10:09 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sample/WordCount.java
r9 r18 3 3 * Editor: Waue Chen 4 4 * From : NCHC. Taiwn 5 * Last Update Date: 06/13/2008 5 * Last Update Date: 07/02/2008 6 * Upgrade to 0.17 6 7 */ 7 8 … … 40 41 import org.apache.hadoop.mapred.Reporter; 41 42 42 43 43 public class WordCount { 44 44 private String filepath; 45 45 46 private String outputPath; 46 47 public WordCount() {47 48 public WordCount() { 48 49 filepath = "/user/waue/input/"; 49 50 outputPath = "counts1"; 50 51 } 51 public WordCount(String path,String output){ 52 53 public WordCount(String path, String output) { 52 54 filepath = path; 53 55 outputPath = output; 54 56 } 57 55 58 // mapper: emits (token, 1) for every word occurrence 56 59 private static class MapClass extends MapReduceBase implements … … 59 62 // reuse objects to save overhead of object creation 60 63 private final static IntWritable one = new IntWritable(1); 64 61 65 private Text word = new Text(); 62 66 … … 93 97 } 94 98 95 96 99 /** 97 100 * Runs the demo. … … 99 102 public static void main(String[] args) throws IOException { 100 103 WordCount wc = new WordCount(); 101 104 102 105 int mapTasks = 1; 103 106 int reduceTasks = 1; … … 107 110 conf.setNumMapTasks(mapTasks); 108 111 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)); 111 115 conf.setOutputKeyClass(Text.class); 112 116 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)); 114 120 115 121 conf.setMapperClass(MapClass.class); 116 122 conf.setCombinerClass(ReduceClass.class); 117 123 conf.setReducerClass(ReduceClass.class); 118 124 119 125 // Delete the output directory if it exists already 120 126 Path outputDir = new Path(wc.outputPath); 121 FileSystem.get(conf).delete(outputDir); 127 // 0.16 128 FileSystem.get(conf).delete(outputDir,true); 122 129 123 130 JobClient.runJob(conf);
Note: See TracChangeset
for help on using the changeset viewer.