博客
关于我
Spark 系列3—— 弹性式数据集RDDs
阅读量:117 次
发布时间:2019-02-26

本文共 2516 字,大约阅读时间需要 8 分钟。

RDD??

Resilient Distributed Dataset?RDD??Spark??????????????????????????????RDD????????

  • ???????RDD?????????Partitions???????????????????????????????????????????????CPU????

  • ?????RDD??compute???????????

  • ?????RDD??????????????????????????????????????????????????????????????????????????????

  • ??????Key-Value???RDD??????????????????????HashPartitioner?RangePartitioner???

  • ?????????????????????Spark?????????????????????????????

  • RDD[T]???????

    // ?????????def compute(split: Partition, context: TaskContext): Iterator[T]// ??????protected def getPartitions: Array[Partition]// ??????protected def getDependencies: Seq[Dependency[_]] = deps// ????????protected def getPreferredLocations(split: Partition): Seq[String] = Nil// ??????????@transient val partitioner: Option[Partitioner] = None

    ??RDD

    RDD???????????

  • ???????

    ??Spark shell??????????

    spark-shell --master local[4]

    ??Scala????

    val conf = new SparkConf().setAppName("Spark shell").setMaster("local[4]")val sc = new SparkContext(conf)

    ??RDD????????

    val data = Array(1, 2, 3, 4, 5)val dataRDD = sc.parallelize(data) // ?????val dataRDD = sc.parallelize(data, 2) // ?????
  • ????????

    ??????????

    val fileRDD = sc.textFile("/usr/file/emp.txt")fileRDD.take(1)

    ?????

    • ???????????????????????
    • ??????????????
  • textFile?wholeTextFiles

    • textFile???RDD[String]???????????
    • wholeTextFiles???RDD[(String, String)]???????????
      ???
    def textFile(path: String, minPartitions: Int = defaultMinPartitions): RDD[String] = withScope {...}def wholeTextFiles(path: String, minPartitions: Int = defaultMinPartitions): RDD[(String, String)] = {...}

  • RDD??

    RDD???????transformations?????actions??????????????????action???????

    val list = List(1, 2, 3)sc.parallelize(list).map(_ * 10).foreach(println)// ???10 20 30

    ??RDD

    Spark??????????????????

  • MEMORY_ONLY??????????JVM??????????????
  • MEMORY_AND_DISK????????????????????
  • MEMORY_ONLY_SER????????????Java?Scala????????
  • MEMORY_AND_DISK_SER???MEMORY_ONLY_SER????????????
  • DISK_ONLY????????
  • ????????MEMORY_ONLY_2?MEMORY_AND_DISK_2???????????????
  • ?????

    • persist(StorageLevel)??????
    • cache()????persist(MEMORY_ONLY)?

    ?????

    • Spark????????????LRU?????
    • ?????RDD.unpersist()?

    Shuffle???

  • Shuffle??

    Shuffle???????????????I/O?????????????RDD?????????????spark.local.dir???????

  • ??Shuffle???

    • ?????repartition?coalesce?
    • ByKey???groupByKey?reduceByKey??countByKey???
    • ?????cogroup?join?
  • ???????

    • ??????????????????????????
    • ????????????????????Shuffle?????????

  • DAG?????

    RDD????????DAG?Spark???????????

    • ??????????????????
    • ???????Shuffle????????

    ??????????????RDD????????Spark?????

    转载地址:http://ogmk.baihongyu.com/

    你可能感兴趣的文章
    PHP设计模式之----观察者模式
    查看>>
    php设计模式之装饰器模式
    查看>>
    R&Python Data Science系列:数据处理(5)--字符串函数基于R(一)
    查看>>
    PHP设计模式:观察者模式
    查看>>
    php访问mysql(1)
    查看>>
    php详细学习1
    查看>>
    php语言优劣
    查看>>
    PHP语言最优雅的支付SDK扩展包
    查看>>
    PHP请求https域名发生segment fault段错误
    查看>>
    PHP读写XML文件
    查看>>
    PHP读写XML文件
    查看>>
    R&Python Data Science 系列:数据处理(3)
    查看>>
    php读取xml 数据库字段超长处理
    查看>>
    php课程 12-40 抽象类的作用是什么
    查看>>
    php课程 4-16 数组自定义函数(php数组->桶)
    查看>>
    PHP调用接口用post方法传送json数据
    查看>>
    php转化IP为整形
    查看>>
    php输出数据到csv文件
    查看>>
    php输出语句
    查看>>
    php运行原理详细说明
    查看>>