作用:求并集. 对源 RDD 和参数 RDD 求并集后返回一个新的 RDDimage.png

    1. import org.apache.spark.rdd.RDD
    2. import org.apache.spark.{SparkConf, SparkContext}
    3. object test {
    4. def main(args: Array[String]): Unit = {
    5. val conf: SparkConf = new SparkConf().setAppName("SparkCoreTest").setMaster("local[*]")
    6. val sc: SparkContext = new SparkContext(conf)
    7. val rdd1: RDD[Int] = sc.makeRDD(List(1, 2, 3, 4), 2)
    8. val rdd2: RDD[Int] = sc.makeRDD(List(4, 5, 6, 7), 3)
    9. //合集
    10. val newRDD: RDD[Int] = rdd1.union(rdd2)
    11. println(newRDD.collect().mkString(",")) //输出: 1,2,3,4,4,5,6,7
    12. sc.stop()
    13. }
    14. }