大家好! 我有一個計劃關於日食的Hadoop,源代碼是:爲什麼我接下來不能處理我的hadoop程序?
public class TokenizerMapper extends Mapper<Object, Text, Text, IntWritable> {
private final static IntWritable one = new IntWritable(1);
private Text word = new Text();
protected void map(Object key, Text value, Context context) throws IOException, InterruptedException {
StringTokenizer itr = new StringTokenizer(value.toString());
while(itr.hasMoreTokens()) {
word.set(itr.nextToken());
context.write(word, one);
}
}
}
public class IntSumReducer extends Reducer<Text, IntWritable, Text, IntWritable> {
private IntWritable result = new IntWritable();
@Override
protected void reduce(Text key, Iterable<IntWritable> values,
Context context) throws IOException, InterruptedException {
int sum = 0;
for(IntWritable val : values) {
sum += val.get();
}
result.set(sum);
context.write(key, result);
}
}
public class WordCount {
public static void main(String[] args) throws Exception {
Configuration conf = new Configuration();
String[] oargs = new GenericOptionsParser(conf, args).getRemainingArgs();
if(oargs.length != 2) {
System.err.println("Usage: word count <in> <out>");
}
System.out.println("input: "+oargs[0]);
System.out.println("output: "+oargs[1]);
Job job = new Job(conf, "word count");
job.setJarByClass(WordCount.class);
job.setMapperClass(TokenizerMapper.class);
job.setCombinerClass(IntSumReducer.class);
job.setReducerClass(IntSumReducer.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class);
FileInputFormat.addInputPath(job, new Path(oargs[0]));
FileOutputFormat.setOutputPath(job, new Path(oargs[1]));
System.out.println("==============================");
System.out.println("start ...");
boolean flag = job.waitForCompletion(true);
System.out.println(flag);
System.out.println("end ...");
System.out.println("==============================");
}
}
和結果,請查看日誌:
[email protected] /cygdrive/f/develop/hadoop/hadoop-1.0.3
$ ./bin/hadoop jar ./jar/wordcount.jar /tmp/input /tmp/output
input: /tmp/input
output: /tmp/output
==============================
start ...
12/07/25 14:59:17 INFO input.FileInputFormat: Total input paths to process : 2
12/07/25 14:59:17 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
12/07/25 14:59:17 WARN snappy.LoadSnappy: Snappy native library not loaded
12/07/25 14:59:17 INFO mapred.JobClient: Running job: job_201207251447_0001
12/07/25 14:59:18 INFO mapred.JobClient: map 0% reduce 0%
日誌不下去,永遠停在那裏。爲什麼?
我使用Windows XP系統中的cygwin軟件以本地模式運行代碼。
「do it next」是什麼意思?你期望它應該做什麼?通常你必須等到你的集羣處理這個工作並返回給你,這就是'waitForCompletion'的含義。如果你的工作不成功,你現有的JVM。 – 2012-07-23 08:03:57
您是否可以發佈任何應該運行的兩個地圖任務的任務日誌?您可以通過作業跟蹤器web ui訪問這些URL,http:// localhost:50030 – 2012-07-25 10:27:48