比如对于传统读写hadoop数据方式:
sc.textFile(“hdfs://...”).flatMap(_.split(“ ”)).map(_, 1).reduceByKey(_ + _).map(x => (x._2, x._1)).sortByKey(false).map(x => (x._2, x_1)).saveAsTextFile(“hdfs://…")
实际执行在action中,因为数据在hadoop中分三份放,读取出来是充分并行的,直接在hadoop上进行。
但是SequoiaDB似乎没有类似textFile这样的方式,我想到的只能这样(java表达):
List> list = new ArrayList>();
DBCursor cursor = cl.query(where, field, null, null);
while(cursor.hasNext()) {
BSONObject o = cursor.getNext();
String key = (String)o.get("Key");
String value = (String)o.get("Value");
list.add(new Tuple2(key, value));
}
JavaPairRDD inputRDD = sc.parallelizePairs(list );
result = inputRDD.mapPartitions(...).reduce(...);
这个准备inputRDD数据源的过程其实是在driver单进程进行,太浪费时间了,有没有好的解决方案。