-1
这是一个字数映射缩减作业。我有我自己的InputFormat。Reducer任务未在我的MapReduce作业中调用
个JobExecutor:
val job = new Job(new Configuration())
job.setMapperClass(classOf[CountMapper])
job.setReducerClass(classOf[CountReducer])
job.setJobName("tarun-test-1")
job.setInputFormatClass(classOf[MyInputFormat])
FileInputFormat.setInputPaths(job, new Path(args(0)))
FileOutputFormat.setOutputPath(job, new Path(args(1)))
job.setOutputKeyClass(classOf[Text])
job.setOutputValueClass(classOf[LongWritable])
job.setNumReduceTasks(1)
println("status: " + job.waitForCompletion(true))
映射:
class CountMapper extends Mapper[LongWritable, Text, Text, LongWritable] {
private val valueOut = new LongWritable(1L)
override def map(k: LongWritable, v: Text, context: Mapper[LongWritable, Text, Text, LongWritable]#Context): Unit = {
val str = v.toString
str.split(",").foreach(word => {
val keyOut = new Text(word.toLowerCase.trim)
context.write(keyOut, valueOut)
})
}
}
减速机:
class CountReducer extends Reducer[Text, LongWritable, Text, LongWritable] {
override def reduce(k: Text, values: Iterable[LongWritable], context: Reducer[Text, LongWritable, Text, LongWritable]#Context): Unit = {
println("Inside reduce method..")
val valItr = values.iterator()
var sum = 0L
while (valItr.hasNext) {
sum = sum + valItr.next().get()
}
context.write(k, new LongWritable(sum))
println("done reducing.")
}
}
映射被调用,RecordReader正在读正确基于日志分裂。但是,reducer没有被调用。
你是什么意思你有你自己的InputFormat?它在哪里?你的意思是减少没有被调用?你怎么知道?任何输入/输出?计数器?错误?日志? – vefthym
MyInputFormat是我自己的InputFormat。 InputFormat按预期工作,我看到映射器的输入(键,值)正在被RecordReader正确读取。我将日志记录添加到Map任务,并按预期记录事件。但是,减少日志不会打印并且最终状态为false。 –