运行基本Hadoop代码时出错
我正在运行hadoop代码,该代码在作业中具有分区器类。但是,当我运行命令运行基本Hadoop代码时出错
hadoop jar Sort.jar SecondarySort inputdir outputdir
我收到写着
class KeyPartitioner not org.apache.hadoop.mapred.Partitioner.
我已经确保了KeyPartitioner类扩展了分区程序类运行时错误,但为什么我会收到这个错误?
这里是驱动程序代码:
JobConf conf = new JobConf(getConf(), SecondarySort.class);
conf.setJobName(SecondarySort.class.getName());
conf.setJarByClass(SecondarySort.class);
conf.setInputFormat(TextInputFormat.class);
conf.setOutputFormat(TextOutputFormat.class);
conf.setMapOutputKeyClass(StockKey.class);
conf.setMapOutputValueClass(Text.class);
conf.setPartitionerClass((Class<? extends Partitioner<StockKey, DoubleWritable>>) KeyPartitioner.class);
conf.setMapperClass((Class<? extends Mapper<LongWritable, Text, StockKey, DoubleWritable>>) StockMapper.class);
conf.setReducerClass((Class<? extends Reducer<StockKey, DoubleWritable, Text, Text>>) StockReducer.class);
这里是分区类的代码:
public class KeyPartitioner extends Partitioner<StockKey, Text> {
@Override
public int getPartition(StockKey arg0, Text arg1, int arg2) {
int partition = arg0.name.hashCode() % arg2;
return partition;
}
}
注意,有两个partitioners在Hadoop中:
org.apache.hadoop.mapreduce.Partitioner
org.apache.hadoop.mapred.Partitioner
确保您的KeyPartitioner
类实现了第二个接口,而不是第一个抽象类秒。
编辑:你要设置的输入和输出文件夹:
FileInputFormat.addInputPath(conf, new Path(args[0]));
FileOutputFormat.setOutputPath(conf, new Path(args[1]));
谢谢!正确更改了导入语句。现在出现一个新的错误: - >输出目录未在JobConf中设置。 – 2012-07-08 14:35:58
@Ahishek Shivkumar:看我的编辑。 – Tudor 2012-07-08 15:11:50
在新的['Hadoop - 权威指南'](http://shop.oreilly.com/product/0636920021773.do)中有关于新API的完整部分,本书中的示例也基于新的API。会建议拿到这本书。 – 2012-07-09 07:23:01
将代码粘贴 - 无码那也只能是胡乱猜测。 – 2012-07-08 14:13:49
向我们显示导入列表。 – Tudor 2012-07-08 14:17:17
谢谢。进口报表相应地改变为@Tudor下面的答案。现在弹出一个新的错误 - >输出目录未在JobConf中设置。 – 2012-07-08 14:37:40