在我開始使用Scoobi或Scrunch之前,我曾試着使用Hadoop(0.20.1)的java綁定將WordCount移植到scala(2.9.1)。Scala/Hadoop:指定Reducer的上下文
我本來:
class Map extends Mapper[LongWritable, Text, 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
環視了一下之後,我想通了,那是因爲我沒」 t定義了適當的方法(應該已經被缺少override
提示),所以我將它固定爲:
override def map(key : LongWritable, value : Text,
context : Mapper[LongWritable, Text, Text, IntWritable]#Context) {
並且瞧,沒有運行時錯誤。
但後來我看着工作輸出,並意識到我的減速機沒有運行。
所以我看着我減速,並注意到reduce
簽名有同樣的問題我的映射:
class Reduce extends Reducer[Text, IntWritable, Text, IntWritable] {
@throws[classOf[IOException]]
@throws[classOf[InterruptedException]]
def reduce(key : Text, value : Iterable[IntWritable], context : Context) {
//...
所以我猜reduce
正在因爲不匹配所用的身份。
但是,當我試圖糾正reduce
簽名:
override def reduce(key: Text, values : Iterable[IntWritable],
context : Reducer[Text, IntWritable, Text, IntWritable]#Context) {
我現在有一個編譯器錯誤:
[ERROR] /path/to/src/main/scala/WordCount.scala:32: error: method reduce overrides nothing
[INFO] override def reduce(key: Text, values : Iterable[IntWritable],
所以我不知道我做錯了。
減少簽名應該是什麼? – 2012-03-25 02:12:25
@ DanielC.Sobral:這是我的問題。 – rampion 2012-03-25 02:14:37