Scala / Hadoop:为Reducer指定上下文
发布时间:2020-12-16 19:17:50 所属栏目:安全 来源:网络整理
导读:在我开始使用Scoobi或Scrunch之前,我想我会尝试使用Hadoop(0.20.1)的 java绑定将WordCount移植到scala(2.9.1). 最初,我有: class Map extends Mapper[LongWritable,Text,IntWritable] { @throws[classOf[IOException]] @throws[classOf[InterruptedExceptio
在我开始使用Scoobi或Scrunch之前,我想我会尝试使用Hadoop(0.20.1)的
java绑定将WordCount移植到scala(2.9.1).
最初,我有: class Map extends Mapper[LongWritable,Text,IntWritable] { @throws[classOf[IOException]] @throws[classOf[InterruptedException]] def map(key : LongWritable,value : Text,context : Context) { //... 编译得很好,但给了我一个运行时错误: java.io.IOException: Type mismatch in key from map: expected org.apache.hadoop.io.Text,recieved org.apache.hadoop.io.LongWritable 环顾四周之后,我发现这是因为我没有定义正确的地图方法(应该由于缺少覆盖而提示),所以我将其修复为: override def map(key : LongWritable,context : Mapper[LongWritable,IntWritable]#Context) { 瞧,没有运行时错误. 但后来我查看了作业输出,并意识到我的减速机没有运行. 所以我查看了我的reducer,并注意到reduce签名与我的mapper有同样的问题: class Reduce extends Reducer[Text,IntWritable,IntWritable] { @throws[classOf[IOException]] @throws[classOf[InterruptedException]] def reduce(key : Text,value : Iterable[IntWritable],context : Context) { //... 所以我猜测由于不匹配而使用了身份减少. 但是当我试图纠正reduce的签名时: override def reduce(key: Text,values : Iterable[IntWritable],context : Reducer[Text,IntWritable]#Context) { 我现在遇到编译器错误: [ERROR] /path/to/src/main/scala/WordCount.scala:32: error: method reduce overrides nothing [INFO] override def reduce(key: Text, 所以我不确定我做错了什么. 解决方法
乍一看,确保值是java.lang.Iterable,而不是scala Iterable.导入java.lang.Iterable,或者:
override def reduce(key: Text,values : java.lang.Iterable[IntWritable],IntWritable]#Context) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |