I have to count the repeating values in an array
val arr = Array(1,2,2,3,4,5,5,5)
For example how to count the number of 5s in the array using RDD, Dataframe, Datasets?
I have to count the repeating values in an array
val arr = Array(1,2,2,3,4,5,5,5)
For example how to count the number of 5s in the array using RDD, Dataframe, Datasets?
If you put your Scala array int into Seq
val arr = Seq(1,2,2,3,4,5,5,5).toDF("num")
val counts = arr.groupBy($"num").agg(count($"num"))
scala> counts.show
+---+----------+
|num|count(num)|
+---+----------+
| 1| 1|
| 3| 1|
| 5| 3|
| 4| 1|
| 2| 2|
+---+----------+