@@ -103,18 +103,20 @@ class ShapeRDD[K: ClassTag, V: ClassTag]
103103 logDebug(" Linker requested" )
104104
105105 val topKMonoid = new TopKMonoid [SparkScoreDoc ](MaxDefaultTopKValue )(SparkScoreDoc .ascending)
106- logDebug(" Collecting query points to driver" )
107- val queries = that.map(pointFunctor).collect()
108- logDebug(" Query points collected to driver successfully" )
109- logDebug(" Broadcasting query points" )
110- val queriesB = partitionsRDD.context.broadcast(queries)
111- logDebug(" Query points broadcasting was successfully" )
112-
113- logDebug(" Compute topK linkage per partition" )
114- val resultsByPart : RDD [(ShapeItemUUID , TopK [SparkScoreDoc ])] = partitionsRDD.flatMap {
115- case partition => queriesB.value.zipWithIndex.par.map { case (queryPoint, index) =>
116- (index.toLong, topKMonoid.build(mapper(queryPoint, partition)))
117- }.toIterator
106+ val queries = that.map(pointFunctor)
107+
108+ val concated : RDD [String ] = queries.zipWithIndex().map(_.swap).mapPartitions { case iter =>
109+ val all = iter.map { case (ind, (x, y)) => s " ${ind}# ${x}# ${y}" }
110+ .reduce( (a, b) => s " ${a}| ${b}" )
111+ Iterator (all)
112+ }
113+ val resultsByPart = concated.cartesian(partitionsRDD)
114+ .flatMap { case (qs, lucene) =>
115+ qs.split('|' ).filter(_.nonEmpty).map { case x =>
116+ val arr = x.split('#' )
117+ (arr(0 ).toLong,
118+ topKMonoid.build(mapper((arr(1 ).toDouble, arr(2 ).toDouble), lucene)))
119+ }
118120 }
119121
120122 logDebug(" Merge topK linkage results" )
0 commit comments