RDD无reduceByKey方法
2015-05-05 16:40
429 查看
写Spark代码的时候经常发现rdd没有reduceByKey的方法,这个发生在spark1.2及其以前对版本,因为rdd本身不存在reduceByKey的方法,需要隐式转换成PairRDDFunctions才能访问,因此需要引入Import org.apache.spark.SparkContext._。
不过到了spark1.3的版本后,隐式转换的放在rdd的object中,这样就会自动被引入,不需要显式引入。
至于什么是隐式转换,简单来讲就是scala偷梁换柱换柱,让隔壁老王来干你干不了的事情了。
不过到了spark1.3的版本后,隐式转换的放在rdd的object中,这样就会自动被引入,不需要显式引入。
* Defines implicit functions that provide extra functionalities on RDDs of specific types. * For example, [[RDD.rddToPairRDDFunctions]] converts an RDD into a [[PairRDDFunctions]] for * key-value-pair RDDs, and enabling extra functionalities such as [[PairRDDFunctions.reduceByKey]]. */ object RDD { // The following implicit functions were in SparkContext before 1.3 and users had to // `import SparkContext._` to enable them. Now we move them here to make the compiler find // them automatically. However, we still keep the old functions in SparkContext for backward // compatibility and forward to the following functions directly. implicit def rddToPairRDDFunctions[K, V](rdd: RDD[(K, V)]) (implicit kt: ClassTag[K], vt: ClassTag[V], ord: Ordering[K] = null): PairRDDFunctions[K, V] = { new PairRDDFunctions(rdd) }
至于什么是隐式转换,简单来讲就是scala偷梁换柱换柱,让隔壁老王来干你干不了的事情了。
相关文章推荐
- rdd没有reduceByKey的方法
- Spark RDD/Core 编程 API入门系列之map、filter、textFile、cache、对Job输出结果进行升和降序、union、groupByKey、join、reduce、look
- Spark RDD中Transformation的combineByKey、reduceByKey,join详解
- RDD Transformation——reduceByKey
- spark2.x由浅入深深到底系列六之RDD api reduceByKey与foldByKey对比
- sparkrdd自动转换能用pairfun(否则无法用reducebykey,groupbykey)
- SparkStreaming找不到reduceByKey的解决方法
- Spark RDD/Core 编程 API入门系列 之rdd案例(map、filter、flatMap、groupByKey、reduceByKey、join、cogroupy等)(四)
- SparkStreaming找不到reduceByKey的解决方法
- RDD键值转换操作(3)–groupByKey、reduceByKey、reduceByKeyLocally
- 大数据IMF传奇行动绝密课程第17课:RDD案例(join、cogroup、reduceByKey、groupByKey等)
- Spark算子:RDD键值转换操作(3)–groupByKey、reduceByKey、reduceByKeyLocally
- spark RDD,reduceByKey vs groupByKey
- pair RDD groupByKey countByKey countByValue aggregateByKey reduceByKey 测试
- Spark RDD/Core 编程 API入门系列之map、filter、textFile、cache、对Job输出结果进行升和降序、union、groupByKey、join、reduce、lookup(一)
- Spark RDD/Core 编程 API入门系列 之rdd案例(map、filter、flatMap、groupByKey、reduceByKey、join、cogroupy等)(四)
- spark RDD算子(六)之键值对聚合操作reduceByKey,foldByKey,排序操作sortByKey
- RDD应用API---flatMap、map、reduceByKey、collect、foreach
- Spark wordcount 编译错误 -- reduceByKey is not a member of RDD
- Spark算子:RDD键值转换操作(3)–groupByKey、reduceByKey、reduceByKeyLocally