zhengruifeng opened a new pull request, #47904:
URL: https://github.com/apache/spark/pull/47904

   ### What changes were proposed in this pull request?
   `StringIndexer` sort arrays in executors
   
   
   ### Why are the changes needed?
   Existing implementation collect all arrays at driver, and then sort them 
with a `ForkJoinPool`.
   
   This PR aims to move sorting from driver to executors.
   
   
   ### Does this PR introduce _any_ user-facing change?
   No
   
   
   ### How was this patch tested?
   CI and manually test:
   ```
   import org.apache.spark.ml.feature.StringIndexer
   
   val numCol = 300
   
   val data = (0 to 10000).map { i =>
     (i, 100 * i)
   }
   var df = data.toDF("id", "label0")
   (1 to numCol).foreach { idx =>
     df = df.withColumn(s"label$idx", col("label0") + 1)
   }
   val inputCols = (0 to numCol).map(i => s"label$i").toArray
   val outputCols = (0 to numCol).map(i => s"labelIndex$i").toArray
   df.cache()
   df.count()
   
   Seq.range(0, 10).foreach(i => new 
StringIndexer().setInputCols(inputCols).setOutputCols(outputCols).setStringOrderType("alphabetDesc").fit(df))
 // warm up
   
   
   val t0 = System.nanoTime()
   Seq.range(0, 10).foreach(i => new 
StringIndexer().setInputCols(inputCols).setOutputCols(outputCols).setStringOrderType("alphabetDesc").fit(df))
   val t1 = System.nanoTime()
   println("Elapsed time: " + (t1 - t0) / 1000000000.0 + "s")
   ```
   
   master:
   ```
   Elapsed time: 12.181134084s
   ```
   
   this PR:
   ```
   Elapsed time: 11.432259833s
   ```
   
   The performance is similar, the main change is that the sort happens in 
executors.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   No


-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to