What is the meaning for reduceByKey(_ ++ _)

Viewed 4411

Recently I had scenario to store the the data in keyValue Pair and came across a function reduceByKey(_ ++ _) . This is more of shorthand syntax. I am not able to understand what this actually means.

Ex: reduceBykey(_ + _) means reduceByKey((a,b)=>(a+b))

So reduceByKey(_ ++ _) means ??

I am able to create Key value pair out of data using reduceByKey(_ ++ _).

val y = sc.textFile("file:///root/My_Spark_learning/reduced.txt")

y.map(value=>value.split(","))
  .map(value=>(value(0),value(1),value(2)))
  .collect
  .foreach(println)

(1,2,3)
(1,3,4)
(4,5,6)
(7,8,9)

y.map(value=>value.split(","))
  .map(value=>(value(0),Seq(value(1),value(2))))
  .reduceByKey(_ ++ _)
  .collect
  .foreach(println)

(1,List(2, 3, 3, 4))
(4,List(5, 6))
(7,List(8, 9))
2 Answers
Related