eclipse中运行wordcount出错 Invalid DFS directory name

Ping_QC 发布于 2014/06/09 23:38
阅读 344
收藏 0

代码:

package org.apache.hadoop.examples;

import java.io.IOException;
import java.util.Iterator;
import java.util.Map.Entry;
import java.util.StringTokenizer;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.util.GenericOptionsParser;

public class WordCount {

  public static class TokenizerMapper 
       extends Mapper<Object, Text, Text, IntWritable>{
    
    private final static IntWritable one = new IntWritable(1);
    private Text word = new Text();
      
    public 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 static class IntSumReducer 
       extends Reducer<Text,IntWritable,Text,IntWritable> {
    private IntWritable result = new IntWritable();

    public 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 static void main(String[] args) throws Exception {
    Configuration conf = new Configuration();
    conf.set("mapred.job.tracker", "h1:9001");
    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("input"));
    FileOutputFormat.setOutputPath(job, new Path("output"));
    System.exit(job.waitForCompletion(true) ? 0 : 1);
  }
}

错误:


14/06/09 23:29:33 WARN mapred.JobClient: Use GenericOptionsParser for parsing the arguments. Applications should implement Tool for the same.
14/06/09 23:29:33 WARN mapred.JobClient: No job jar file set.  User classes may not be found. See JobConf(Class) or JobConf#setJar(String).
14/06/09 23:29:33 INFO input.FileInputFormat: Total input paths to process : 1
14/06/09 23:29:33 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
14/06/09 23:29:33 WARN snappy.LoadSnappy: Snappy native library not loaded
14/06/09 23:29:33 INFO mapred.JobClient: Running job: job_201406090716_0014
14/06/09 23:29:34 INFO mapred.JobClient:  map 0% reduce 0%
14/06/09 23:29:38 INFO mapred.JobClient: Task Id : attempt_201406090716_0014_m_000002_0, Status : FAILED
java.lang.IllegalArgumentException: Invalid DFS directory name /D:/workspace/WordCount
	at org.apache.hadoop.hdfs.DistributedFileSystem.setWorkingDirectory(DistributedFileSystem.java:128)
	at org.apache.hadoop.mapred.Child$4.run(Child.java:254)
	at java.security.AccessController.doPrivileged(Native Method)
	at javax.security.auth.Subject.doAs(Subject.java:422)
	at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1190)
	at org.apache.hadoop.mapred.Child.main(Child.java:249)

14/06/09 23:29:42 INFO mapred.JobClient: Task Id : attempt_201406090716_0014_m_000002_1, Status : FAILED
#重复n次
14/06/09 23:30:08 INFO mapred.JobClient: Job complete: job_201406090716_0014
14/06/09 23:30:08 INFO mapred.JobClient: Counters: 4
14/06/09 23:30:08 INFO mapred.JobClient:   Job Counters 
14/06/09 23:30:08 INFO mapred.JobClient:     SLOTS_MILLIS_REDUCES=0
14/06/09 23:30:08 INFO mapred.JobClient:     Total time spent by all reduces waiting after reserving slots (ms)=0
14/06/09 23:30:08 INFO mapred.JobClient:     SLOTS_MILLIS_MAPS=33802
14/06/09 23:30:08 INFO mapred.JobClient:     Total time spent by all maps waiting after reserving slots (ms)=0

我在Ubuntu中执行wordcount是没有问题的,

然后在eclipse(windows)里面copy了分src里面的wordcount代码,执行报错了,

/D:/workspace/WordCount这个是我项目的路径

这是要手动设置workingDirectory吗?在哪里设置?

谢谢各位了




加载中
返回顶部
顶部