在 Spark 中,过滤器函数是否将数据转换为元组?

In Spark, does the filter function turn the data into tuples?

只是想知道过滤器是否将数据转换为元组?例如

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) 

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

filter 不会改变 RDD - 过滤后的数据仍然是 RDD(Array[String])

不,filter 所做的只是接受一个谓词函数并使用它,这样集合中的任何数据点 return 在通过该谓词时为 false,然后它们就不会被传递返回结果集。因此,数据仍然相同:

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,您必须使用带有适当索引的括号将数据作为数组访问