使用collect()方法查询数据
查看sq_dist和sort_data的结果
sq_dist.collect
sort_data.collect
代码3-9 collect(PartialFunction)操作方法示例
定义一个函数one
val one:PartialFunction[Int, String] = {case 1 => "one";case _ => "other"}
创建RDD
val data = sc.parallelize(List(2, 3, 1))
使用collect()方法,将one函数作为参数
data.collect(one).collect
使用flatMap()方法转换数据
代码3-10 flatMap()方法示例
创建RDD
val test = sc.parallelize(List("How are you", "I am fine", "What about you"))
查看RDD
test.collect
使用map分割字符串后,再查看RDD
test.map(x => x.split(" ")).collect
使用flatMap分割字符串后,再查看RDD
test.flatMap(x => x.split(" ")).collect