【问题标题】:Scala MapReduce : [error] method reduce overrides nothingScala MapReduce:[错误]方法reduce什么都不覆盖
【发布时间】:2015-03-06 03:24:34
【问题描述】:

我遇到了这个错误,我这样写了我的 TableReducer 代码:

class treducer extends TableReducer[Text, IntWritable, ImmutableBytesWritable]{
    override def reduce(key: Text, values: java.lang.Iterable[IntWritable], context:Reducer[Text, IntWritable, ImmutableBytesWritable, Mutation]#Context){
        var i=0
        for (v <- values) {
          i += v.get()
        }
        val put = new Put(Bytes.toBytes(key.toString()))  // be sure to comment on toString.getBytes
        put.add(Families.cf.bytes , Qualifiers.count.bytes, Bytes.toBytes(i))

        context.write(null, put)
    }
}

使用此导入:

import org.apache.hadoop.hbase.HBaseConfiguration
import org.apache.hadoop.hbase.client.HBaseAdmin
import org.apache.hadoop.hbase.client.HTable
import org.apache.hadoop.hbase.util.Bytes
import org.apache.hadoop.hbase.client.Put
import org.apache.hadoop.hbase.client.Get
import java.io.IOException
import org.apache.hadoop.conf.Configuration
import org.apache.hadoop.hbase._
import org.apache.hadoop.hbase.client._
import org.apache.hadoop.hbase.io._
import org.apache.hadoop.hbase.mapreduce._
import org.apache.hadoop.io._
import scala.collection.JavaConversions._
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat
import org.apache.hadoop.mapreduce.Job
import org.apache.hadoop.mapreduce.Mapper
import org.apache.hadoop.mapreduce.ReduceContext
import org.apache.hadoop.mapreduce.Reducer

但是得到了这个错误:

[error] /home/ans4175/activator/scala-hbase/src/main/scala/com/example/Hello.scala:85: method reduce overrides nothing.
[error] Note: the super classes of class treducer contain the following, non final members named reduce:
[error] protected[package mapreduce] def reduce(x$1: org.apache.hadoop.io.Text,x$2: Iterable[org.apache.hadoop.io.IntWritable],x$3: org.apache.hadoop.mapreduce.Reducer[org.apache.hadoop.io.Text,org.apache.hadoop.io.IntWritable,org.apache.hadoop.hbase.io.ImmutableBytesWritable,org.apache.hadoop.io.Writable]#Context): Unit
[error]     override def reduce(key: Text, values: java.lang.Iterable[IntWritable], context:Reducer[Text, IntWritable, ImmutableBytesWritable, Mutation]#Context){
[error]                  ^
[error] one error found
[error] (compile:compile) Compilation failed

我不知道是什么问题。我已经像这个帖子一样关注了 https://github.com/rawg/scala-hbase-wordcount/blob/master/src/main/scala/WordCountReducer.scala, https://github.com/vadimbobrov/calc/blob/master/src/main/scala/com/os/job/InterpolatorReducer.scala

提前谢谢你

【问题讨论】:

  • 将所有导入添加到您的代码中,以便我们检查您正在导入的内容。
  • 好的,我已经添加了我的导入行

标签: scala hadoop mapreduce hbase


【解决方案1】:

当您覆盖子类中的某些方法时,这意味着父类中必须存在具有相同签名的相同方法,而您的程序仅在该方法中失败。

这种错误通常表明子类中的方法签名与父类中的签名不匹配,因此从技术上讲,您没有覆盖任何内容,因此 scala 告诉您

[错误] /home/ans4175/activator/scala-hbase/src/main/scala/com/example/Hello.scala:85:reduce 方法不会覆盖任何内容。
注意:类 treducer 的超类包含以下名为 reduce 的非最终成员:

【讨论】:

  • 但我正在覆盖 TableReducer (HBase) 的 reduce 方法,它也是从 Reducer (Hadoop) 扩展而来的。我错过了什么重要的东西吗?
【解决方案2】:

错误提供了您的答案。您错误地声明了其中一个论点。

编译器已经指出第三个参数的类型是:

Reducer[Text,IntWritable,ImmutableBytesWritable,Writable]#Context

您的覆盖声明了一个带有此类型第三个参数的方法:

Reducer[Text, IntWritable, ImmutableBytesWritable, Mutation]#Context

Mutation 更改为Writable 将允许编译器覆盖正确的方法。

【讨论】:

  • 先生,它仍然无法编译。
  • 那么您所做的更改并没有解决重载问题。也许它需要一个 scala Iterable 而不是 Java Iterable?无论问题是什么,都可以通过使参数和返回类型与 reduce 方法的基类签名一致来解决。
  • reduce 方法的基类签名是什么,先生?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多