| 71 | | public void map(LongWritable key, Text value, Context context) |
| 72 | | throws IOException, InterruptedException { |
| 73 | | // 將出入資料 原封不動的寫入 輸出 |
| 74 | | context.write((LongWritable) key, (Text) value); |
| 75 | | } |
| | 69 | public void map(LongWritable key, Text value, Context context) |
| | 70 | throws IOException, InterruptedException { |
| | 71 | // 將出入資料 原封不動的寫入 輸出 |
| | 72 | context.write((LongWritable) key, (Text) value); |
| | 73 | } |
| 79 | | static public class HelloReducer extends |
| 80 | | Reducer<LongWritable, Text, LongWritable, Text> { |
| 81 | | public void reduce(LongWritable key, Iterable<Text> values, |
| 82 | | Context context) throws IOException, InterruptedException { |
| 83 | | Text val = new Text(); |
| 84 | | // 取回 val 的資料 |
| 85 | | for (Text str : values) { |
| 86 | | val.set(str.toString()); |
| 87 | | } |
| 88 | | // 將取回的資料引入輸出 |
| 89 | | context.write(key, val); |
| 90 | | } |
| 91 | | } |
| | 77 | static public class HelloReducer extends |
| | 78 | Reducer<LongWritable, Text, LongWritable, Text> { |
| | 79 | public void reduce(LongWritable key, Iterable<Text> values, |
| | 80 | Context context) throws IOException, InterruptedException { |
| | 81 | Text val = new Text(); |
| | 82 | // 取回 val 的資料 |
| | 83 | for (Text str : values) { |
| | 84 | val.set(str.toString()); |
| | 85 | } |
| | 86 | // 將取回的資料引入輸出 |
| | 87 | context.write(key, val); |
| | 88 | } |
| | 89 | } |
| 93 | | public static void main(String[] args) throws IOException, |
| 94 | | InterruptedException, ClassNotFoundException { |
| 95 | | // 引入 $HADOOP_HOME/conf 內控制檔內的資料 |
| 96 | | Configuration conf = new Configuration(); |
| 97 | | // 宣告job 取得conf 並設定名稱 Hadoop Hello World |
| 98 | | Job job = new Job(conf, "Hadoop Hello World"); |
| 99 | | // 設定此運算的主程式 |
| 100 | | job.setJarByClass(HelloHadoop.class); |
| 101 | | // 設定輸入路徑 |
| 102 | | FileInputFormat.setInputPaths(job, "");// 請輸入正確的輸入資料夾 |
| 103 | | // 設定輸出路徑 |
| 104 | | FileOutputFormat.setOutputPath(job, new Path("")); // 請輸入正確的輸出資料夾 |
| 105 | | // 指定定map class |
| 106 | | job.setMapperClass(HelloMapper.class); |
| 107 | | // 指定reduce class |
| 108 | | job.setReducerClass(HelloReducer.class); |
| 109 | | // 開使運算 |
| 110 | | job.waitForCompletion(true); |
| | 91 | public static void main(String[] args) throws IOException, |
| | 92 | InterruptedException, ClassNotFoundException { |
| | 93 | // 引入 $HADOOP_HOME/conf 內控制檔內的資料 |
| | 94 | Configuration conf = new Configuration(); |
| | 95 | // 宣告job 取得conf 並設定名稱 Hadoop Hello World |
| | 96 | Job job = new Job(conf, "Hadoop Hello World"); |
| | 97 | // 設定此運算的主程式 |
| | 98 | job.setJarByClass(HelloHadoop.class); |
| | 99 | // 設定輸入路徑 |
| | 100 | FileInputFormat.setInputPaths(job, "/user/hadoop/input"); |
| | 101 | // 設定輸出路徑 |
| | 102 | FileOutputFormat.setOutputPath(job, new Path("/user/hadoop/output-hh1")); |
| | 103 | // 指定定map class |
| | 104 | job.setMapperClass(HelloMapper.class); |
| | 105 | // 指定reduce class |
| | 106 | job.setReducerClass(HelloReducer.class); |
| | 107 | // 開使運算 |
| | 108 | job.waitForCompletion(true); |