- map算子:将集合中的每个元素乘2
package cn.spark.study.core import org.apache.spark.{SparkConf, SparkContext} object transformationOpertion { def main(args: Array[String]): Unit = { map() } def map(): Unit ={ val conf = new SparkConf().setAppName("map").setMaster("local") val sc = new SparkContext(conf) val numbers = Array(1,2,3,4,5) val numberRDD = sc.parallelize(numbers,1) val pair = numberRDD.map(x => x * 2) val result = pair.foreach(x => println(x)) } }
结果:
- filter算子:过滤出集合中的偶数
package cn.spark.study.core import org.apache.spark.{SparkConf, SparkContext} object transformationOpertion { def main(args: Array[String]): Uni