I am trying to understand how map and flatMap works but got stuck at below piece of code. flatMap() function returns an RDD[Char] but I was expecting the RDD[String] instead. Can someone explain why it yields the RDD[Char] ?
scala> val inputRDD = sc.parallelize(Array(Array("This is Spark"), Array("It is a processing language"),Array("Very fast"),Array("Memory operations")))
scala> val mapRDD = inputRDD.map(x => x(0))
mapRDD: org.apache.spark.rdd.RDD[String] = MapPartitionsRDD[28] at map at <console>:26
scala> mapRDD.collect
res27: Array[String] = Array(This is Spark, It is a processing language, Very fast, Memory operations)
scala> val mapRDD = inputRDD.flatMap(x => x(0))
mapRDD: org.apache.spark.rdd.RDD[Char] = MapPartitionsRDD[29] at flatMap at <console>:26
scala> mapRDD.collect
res28: Array[Char] = Array(T, h, i, s, , i, s, , S, p, a, r, k, I, t, , i, s, , a, , p, r, o, c, e, s, s, i, n, g, , l, a, n, g, u, a, g, e, V, e, r, y, , f, a, s, t, M, e, m, o, r, y, , o, p, e, r, a, t, i, o, n, s)