felixcheung commented on a change in pull request #25442: [SPARK-28722][ML] 
Change sequential label sorting in StringIndexer fit to parallel
URL: https://github.com/apache/spark/pull/25442#discussion_r313713261
 
 

 ##########
 File path: mllib/src/main/scala/org/apache/spark/ml/feature/StringIndexer.scala
 ##########
 @@ -213,32 +221,36 @@ class StringIndexer @Since("1.4.0") (
     val labelsArray = $(stringOrderType) match {
       case StringIndexer.frequencyDesc =>
         val sortFunc = StringIndexer.getSortFunc(ascending = false)
-        countByValue(dataset, inputCols).map { counts =>
+        val orgStrings = countByValue(dataset, inputCols).toSeq
+        ThreadUtils.parmap(orgStrings, "sortingStringLabels", 8) { counts =>
           counts.toSeq.sortWith(sortFunc).map(_._1).toArray
-        }
+        }.toArray
       case StringIndexer.frequencyAsc =>
         val sortFunc = StringIndexer.getSortFunc(ascending = true)
-        countByValue(dataset, inputCols).map { counts =>
+        val orgStrings = countByValue(dataset, inputCols).toSeq
+        ThreadUtils.parmap(orgStrings, "sortingStringLabels", 8) { counts =>
           counts.toSeq.sortWith(sortFunc).map(_._1).toArray
-        }
+        }.toArray
       case StringIndexer.alphabetDesc =>
-        import dataset.sparkSession.implicits._
         dataset.persist()
-        val labels = inputCols.map { inputCol =>
-          
dataset.select(inputCol).na.drop().distinct().sort(dataset(s"$inputCol").desc)
-            .as[String].collect()
-        }
+        val selectedCols = getSelectedCols(dataset, 
inputCols).map(collect_set(_))
+        val allLabels = dataset.select(selectedCols: _*)
+          .collect().toSeq.flatMap(_.toSeq).asInstanceOf[Seq[Seq[String]]]
 
 Review comment:
   so this can be selecting a large number of columns and collecting it all to 
the driver for distinct/sort? isn't this possibly very slow if we have billions 
of record?

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

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

Reply via email to