Java 运行基本Hadoop代码时出错
我正在运行一个hadoop代码,该代码在作业中有一个partitioner类。但是,当我运行命令时Java 运行基本Hadoop代码时出错,java,hadoop,mapreduce,hdfs,Java,Hadoop,Mapreduce,Hdfs,我正在运行一个hadoop代码,该代码在作业中有一个partitioner类。但是,当我运行命令时 hadoop jar Sort.jar SecondarySort inputdir outputdir 我得到一个运行时错误,它说 class KeyPartitioner not org.apache.hadoop.mapred.Partitioner. 我已经确保KeyPartitioner类已经扩展了Partitioner类,但是为什么会出现这个错误呢 以下是驾驶员代码: JobCon
hadoop jar Sort.jar SecondarySort inputdir outputdir
我得到一个运行时错误,它说
class KeyPartitioner not org.apache.hadoop.mapred.Partitioner.
我已经确保KeyPartitioner类已经扩展了Partitioner类,但是为什么会出现这个错误呢
以下是驾驶员代码:
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);
JobConf conf=newjobconf(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注意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]));
粘贴代码-如果没有代码,这只是一个猜测。向我们显示导入列表。谢谢。导入语句会根据下面@Tudor的答案进行相应更改。现在会弹出一个新错误,说->输出目录未在JobConf中设置。谢谢!正确更改了导入语句。现在出现一个新错误:->输出目录未在JobC中设置在新的API中有一整节介绍新的API,书中的示例也基于新的API。建议您阅读这本书。
FileInputFormat.addInputPath(conf, new Path(args[0]));
FileOutputFormat.setOutputPath(conf, new Path(args[1]));