zoukankan      html  css  js  c++  java
  • 4.3 高效的算子、分区算子

    groupByKey和reduceByKey

    1.groupByKey是没有combine过程
        combineByKeyWithClassTag[CompactBuffer[V]](createCombiner, mergeValue, mergeCombiners, partitioner, mapSideCombine = false)
    2.reduceByKey有combine过程
        combineByKeyWithClassTag[V]((v: V) => v, func, func, partitioner) //mapSideCombine默认是true
        1、如果v是数字运算,如wordcount减少网络传输次数
        2、如果v是List[],对v进行收集,因为只收集v所以可以节省空间

    注意:reduceByKey不能改变 v 的返回值类型

              两者都可重新指定分区

    repartition 和 coalesce

    rdd.repartition(n)调用的就是coalesce,始终进行shuffle操作。 
    如果是减少分区,推荐使用coalesce,可以指定是否进行shuffle操作,默认是false即不分区
    通过coalesce增加分区时,必须指定shuffle为true,否则分区数不变。
    渐变 --> 突变
  • 相关阅读:
    组合模式
    过滤器模式
    桥接模式
    适配器模式
    原型模式
    建造者模式
    抽象工厂
    工厂方法
    静态工厂
    单例模式
  • 原文地址:https://www.cnblogs.com/lybpy/p/9774863.html
Copyright © 2011-2022 走看看