spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [spark] zhengruifeng commented on a change in pull request #27947: [SPARK-31182][CORE][ML] PairRDD support aggregateByKeyWithinPartitions
Date Wed, 18 Mar 2020 09:21:00 GMT
zhengruifeng commented on a change in pull request #27947: [SPARK-31182][CORE][ML] PairRDD
support aggregateByKeyWithinPartitions
URL: https://github.com/apache/spark/pull/27947#discussion_r394203694
 
 

 ##########
 File path: mllib/src/main/scala/org/apache/spark/ml/feature/RobustScaler.scala
 ##########
 @@ -204,17 +204,18 @@ object RobustScaler extends DefaultParamsReadable[RobustScaler] {
       }.reduceByKey { case (s1, s2) => s1.merge(s2) }
     } else {
       val scale = math.max(math.ceil(math.sqrt(vectors.getNumPartitions)).toInt, 2)
-      vectors.mapPartitionsWithIndex { case (pid, iter) =>
-        val p = pid % scale
-        iter.flatMap { vec =>
-          Iterator.tabulate(numFeatures)(i => ((p, i), vec(i)))
-        }.filter(!_._2.isNaN)
-      }.aggregateByKey(
+      vectors.flatMap { vec =>
+        vec.iterator.filterNot(_._2.isNaN)
+      }.aggregateByKeyWithinPartitions(
         new QuantileSummaries(QuantileSummaries.defaultCompressThreshold, relativeError))(
         seqOp = (s, v) => s.insert(v),
         combOp = (s1, s2) => s1.compress.merge(s2.compress)
-      ).map { case ((_, i), s) => (i, s)
-      }.reduceByKey { case (s1, s2) => s1.compress.merge(s2.compress) }
+      ).mapPartitionsWithIndex { case (pid, iter) =>
+        val p = pid % scale
+        iter.map { case (col, s) => ((p, col), s.compress) }
 
 Review comment:
   here we can trigger compression at the _map_ side

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Mime
View raw message