2012-03-25 4 views
7

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 

を、私は「wasnので、それがあったことを考え出しました適切なmapメソッドを定義していないので(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], 

だから私は私が間違ってやっているかわからないんだけど。

+0

インポートするか、縮小署名は何ですか? –

+0

@ DanielC.Sobral:それは私の質問です。 – rampion

答えて

11

一見したところ、値はIterableでなくjava.lang.Iterableであることを確認してください。 java.lang.Iterable、または:

override def reduce(key: Text, values : java.lang.Iterable[IntWritable], context : Reducer[Text, IntWritable, Text, IntWritable]#Context) 
+2

これはまさに正しいことです。例はこちらをご覧ください:https://bitbucket.org/jasonbaldridge/fogbow/src/6c24fb2afda4/src/main/scala/fogbow/example/WordCount.scala – dhg

関連する問題