【发布时间】:2015-02-09 15:37:50
【问题描述】:
我在 java 中使用 spark,我有一个 500 万行的 RDD。有没有一种解决方案可以让我计算我的 RDD 的行数。我试过RDD.count(),但这需要很多时间。我已经看到我可以使用函数fold。但是我没有找到这个函数的java文档。
您能否告诉我如何使用它或告诉我另一种解决方案来获取我的 RDD 的行数。
这是我的代码:
JavaPairRDD<String, String> lines = getAllCustomers(sc).cache();
JavaPairRDD<String,String> CFIDNotNull = lines.filter(notNull()).cache();
JavaPairRDD<String, Tuple2<String, String>> join =lines.join(CFIDNotNull).cache();
double count_ctid = (double)join.count(); // i want to get the count of these three RDD
double all = (double)lines.count();
double count_cfid = all - CFIDNotNull.count();
System.out.println("********** :"+count_cfid*100/all +"% and now : "+ count_ctid*100/all+"%");
谢谢。
【问题讨论】:
标签: java apache-spark