写Spark代码的时候经常发现rdd没有reduceByKey的方法,这个发生在spark1.2及其以前对版本,因为rdd本身不存在reduceByKey的方法,需要隐式转换成PairRDDFunctions才能访问,因此需要引入Import org.apache.spark.SparkContext._。
创新互联2013年至今,先为宁陵等服务建站,宁陵等地企业,进行企业商务咨询服务。为宁陵企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。
不过到了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的方法
标题路径:https://www.cdcxhl.com/article8/gedhop.html
成都网站建设公司_创新互联,为您提供全网营销推广、营销型网站建设、网站设计公司、ChatGPT、网站设计、微信公众号
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联