我遇到了这个错误,我写了这样的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
提前谢谢
答案 0 :(得分:2)
错误提供了答案。您错误地声明了其中一个参数。
编译器指出第三个参数的类型是:
Reducer[Text,IntWritable,ImmutableBytesWritable,Writable]#Context
您的覆盖声明了一个带有此类型的第三个参数的方法:
Reducer[Text, IntWritable, ImmutableBytesWritable, Mutation]#Context
将Mutation
更改为Writable
将允许编译器覆盖正确的方法。
答案 1 :(得分:0)
当你覆盖子类中的某个方法时,这意味着同一个方法必须在具有相同签名的父类中,并且你的程序只在那个方法中失败。
这种错误通常表明子方法中的方法签名与父类中的方法不匹配,因此从技术上讲,你没有覆盖任何东西,因此scala告诉你
[error] /home/ans4175/activator/scala-hbase/src/main/scala/com/example/Hello.scala:85:方法reduce会覆盖任何内容。
注意:类treducer的超类包含以下非最终成员名为reduce: