map: 對(duì)RDD每個(gè)元素轉(zhuǎn)換
flatMap: 對(duì)RDD每個(gè)元素轉(zhuǎn)換, 然后再扁平化(即將所有對(duì)象合并為一個(gè)對(duì)象)
Example:
data 有兩行數(shù)據(jù):
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)