Idea里面MapReduce设置FileInputFormat参数格式变化
huft 发布时间:2019-01-21 13:16:04 浏览50 评论0- hdfs
- path
- Mapreduce
- IDEA
摘要: MapReduce新手跑wordcount时可能遇见的小错误吧
我们随便百度一个经典的MapReduce程序----wordcount的时候,在设置job文件输入路径和输出路径参数时,会看到别的博主会这么写:
Configuration conf = new Configuration();
Job wordCountJob = Job.getInstance(conf);
//省略。。。。
FileInputFormat.setInputPaths(wordCountJob,"hdfs://192.168.77.70:9000/wordcount/srcdata/");
FileOutputFormat.setOutputPath(wordCountJob, new Path("hdfs://192.168.77.70:9000/wordcount/output/"));
但是我在Idea里面复制粘贴编译时,其实是报错的。这是因为,它在版本中要求FileInputFormat调用的方法名是addInputPath且第一个参数是JobConf型,同样FileOutputFormat调用的输出名是setOutputPath,参数也是JobConf型。所以这个时候要进行强转,具体做法如下:
FileInputFormat.addInputPath((JobConf)wordCountJob.getConfiguration(),new Path(args[0]));
FileOutputFormat.setOutputPath((JobConf)wordCountJob.getConfiguration(),new Path(args[1])); 【云栖快讯】云栖专辑 | 阿里开发者们的20个感悟,一通百通 详情请点击
- 分享到: