我在我的 CDH 4.2 发行版上运行任何用 scala 编写的 MR 作业时遇到问题。这条线
context.write(...)
导致错误:找到接口 org.apache.hadoop.mapreduce.TaskInputOutputContext,但在 java 中预计类没有问题。任何人都可以帮忙吗?这是完整的示例:
class MyMapper extends Mapper[Object,Text,Text,IntWritable] {
val one = new IntWritable(1)
val word = new Text
override def map(key:Object, value:Text, context:Mapper[Object,Text,Text,IntWritable]#Context) {
context.write(word, one)
}
}
object WordCount {
def main(args:Array[String]):Int = {
val conf = new Configuration()
val job = new Job(conf, "word count")
job.setJarByClass(classOf[MyMapper])
job.setMapperClass(classOf[MyMapper])
job.setNumReduceTasks(0)
job.setOutputKeyClass(classOf[Text])
job.setOutputValueClass(classOf[IntWritable])
FileInputFormat.addInputPath(job, new Path(args(0)))
FileOutputFormat.setOutputPath(job, new Path((args(1))))
if (job.waitForCompletion(true)) 0 else 1
}
}