2017-03-01 5 views
0

私はSparkを初めて使用しています。私は、IDE(Eclipseのネオン)は、次のメッセージ私はこの問題を解決するにはどうすればよい Spark Java - なぜTuple2はマップの関数の引数になりませんか?


Multiple markers at this line 
- The method map(Function<Tuple2<Detection,Detection>,R>) in the type 
AbstractJavaRDDLike<Tuple2<Detection,Detection>,JavaPairRDD<Detection,Detection>> is not applicable for the arguments (new 
Function<Tuple2<Detection,Detection>,Segment>(){}) 
- The type new Function<Tuple2<Detection,Detection>,Segment>(){} must implement the inherited abstract method 
Function<Tuple2<Detection,Detection>,Segment>.apply(Tuple2<Detection,Detection>) 
を示し、次のJavaコード

JavaPairRDD<Detection, Detection> allCombinations = currentLevelNodes.cartesian(nextLevelNodes); 

allCombinations.map(new Function<Tuple2<Detection, Detection>, Segment>(){ 
    public Segment call(Tuple2<Detection, Detection> combination){ 
    Segment segment = new Segment(); 
    Detection a = combination._1(); 
    Detection b = combination._2(); 
    segment.distance = Math.sqrt(Math.pow((a.x)-(b.x), 2) + Math.pow((a.y)-(b.y), 2)); 

    return segment; 
    } 
}); 


を書かれていますか?

+0

エラーはあなたがcall()を実装していると言いますが、代わりにapply()を実装する必要があります。ラムダを使うとあなたの人生が楽になります – Jack

+0

また、マッピング関数の引数としてJavaPairRDDの代わりにTuple2を使うことはできますか? – Jack

+0

関数名 "call"を "apply"に変更しようとしましたが、それでも最初の行メッセージが表示されます。 – lucienlo

答えて

0

ラムダ式を使用してこの問題を解決しました。

この私のサンプルコード

JavaPairRDD<Detection,Detection> allCombinations = currentLevelNodes.cartesian(nextLevelNodes); 

JavaRDD<Segment> segmentRDD = allCombinations.map(tuple -> new Segment(tuple._1, tuple._2)); 


と私は、コンストラクタに

public Segment(Detection a, Detection b){ 
    this.distance = Math.sqrt(Math.pow(a.x-b.x, 2)+Math.pow(a.y-b.y, 2)); 
} 


を追加し、それが作品です。

+0

この回答は私のような誰かを助けることを願っています – lucienlo

関連する問題