// Safe: extract just the field we need into a local variable
val query_ = this.query
rdd.map(x => x.split(query_))
}
}
复制代码
---
关于map
The map transformation takes in a function and applies it to each
element in the RDD with the result of the function being the new value of each element
in the resulting RDD.
意思很简单,自己体会即可!
---
关于map和 filter
例子:
val input = sc.parallelize(List(1, 2, 3, 4))
val result = input.map(x => x*x)
println(result.collect())
复制代码
例子2:
val lines = sc.parallelize(List("hello world", "hi"))
val words = lines.flatMap(line => line.split(" "))