2015-06-14 16 views
0

想知道過濾器是否將數據轉換爲元組?例如在Spark中,過濾器函數是否將數據轉換爲元組?

val filesLines = sc.textFile("file.txt") 
val split_lines = filesLines.map(_.split(";")) 

val filteredData = split_lines.filter(x => x(4)=="Blue") 

//如果我們想要映射數據,它將使用元組格式即。 x._3或X(3)

val blueRecords = filteredData.map(x => x._1, x._2) 

OR

val blueRecords = filteredData.map(x => x(0), x(1)) 

回答

1

不,所有filter如果使用謂詞函數並使用謂詞函數,則該集合中的任何數據點在通過該謂詞時返回false,則不會將它們傳遞迴結果集合。因此,數據remians相同:

filesLines //RDD[String] (lines of the file) 
split_lines //RDD[Array[String]] (lines delimited by semicolon) 
filteredData //RDD[Array[String]] (lines delimited by semicolon where the 5th item is Blue 

因此,使用filteredData,你將不得不使用括號與適當的索引

訪問數據作爲一個數組
1

濾波器不會改變RDD - 濾波後的數據仍然是RDD(陣列[字符串])

相關問題