-3

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?

Mario Galic
  • 47,285
  • 6
  • 56
  • 98
Chaitanya
  • 63
  • 1
  • 2
  • 10

1 Answers1

1

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|
+---+----------+
howie
  • 2,587
  • 3
  • 27
  • 43