Spark map 和 flatMap 区别
map: 对RDD每个元素转换
flatMap: 对RDD每个元素转换, 然后再扁平化(即将所有对象合并为一个对象)
Example:
data 有两行数据:
a,b,c
1,2,3
scala>data.map(line1 => line1.split(",")).collect()
res11: Array[Array[String]] = Array(Array(a, b, c), Array(1, 2, 3))
scala>data.flatMap(line1 => line1.split(",")).collect()
res13: Array[String] = Array(a, b, c, 1, 2, 3)