簡體   English   中英

如何在JavaPairRDD上使用max方法

[英]How to use max method on JavaPairRDD

因此,我試圖在JavaPairRDD使用max,但無法使其正常工作。

JavaPairRDD<Integer, String> someRdd = (initialisation)

String maxValue = someRdd.max()  //not working

我的代碼: http//ideone.com/0YXCJw

實現描述所需順序的比較器:

import scala.Tuple2;
import java.io.Serializable;

class DummyComparator implements 
      Comparator<Tuple2<Integer, String>>, Serializable {
   public int compare(Tuple2<Integer, String> x, Tuple2<Integer, String> y) {
        return -1;
    }
}

將其傳遞給max方法:

someRdd.max(new DummyComparator());

這就是我用的。

class DummyComparator implements Serializable,  
     Comparator<Tuple2<Integer, String>> {
   @Override
   public int compare(Tuple2<Integer, String> o1, Tuple2<Integer, String> o2) {
         return Integer.compare(o1._1(), o2._1());
   }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM