I have a spark dataframe with below schema:
root
|-- cluster_info: struct (nullable = true)
| |-- cluster_id: string (nullable = true)
| |-- influencers: array (nullable = true)
| | |-- element: struct (containsNull = true)
| | | |-- screenName: string (nullable = true)
And I need to get unique list of screenName and I am doing it using below code. But collect is a very heavy operation, is there a better way to do it.
var namesDF = df.select(concat_ws(",", $"cluster_info.influencers.screenName").as("screenName"))
val influencerNameList: List[String] = namesDF.map(r => r(0).asInstanceOf[String]).collect().toList.mkString(",").split(",").toList.distinct
Please suggest. Thanks in advance.