scala开发spark使用程序中的集合创建RDD

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/weixin_45526489/article/details/102722370
package cn.spark.study.core

import org.apache.spark.{SparkConf, SparkContext}


object ParallelizeCollection {
  def main(args: Array[String]): Unit = {

    //创建conf对象
    val conf = new SparkConf()
      .setAppName("ParallelizeCollection")
      .setMaster("local")
    val sc = new SparkContext(conf)

    val numbers = Array(1,2,3,4,5,6,7,8,9)
    
    //要通过并行化集合方式创建RDD,那么就调用SparkContext以及其子类的parallelize()的方法
    val numberRDD = sc.parallelize(numbers,5)
    var sum = numberRDD.reduce(_+_)
    println(sum)
  }


}

猜你喜欢

转载自blog.csdn.net/weixin_45526489/article/details/102722370