您好,登錄后才能下訂單哦!
寫Spark代碼的時候經常發現rdd沒有reduceByKey的方法,這個發生在spark1.2及其以前對版本,因為rdd本身不存在reduceByKey的方法,需要隱式轉換成PairRDDFunctions才能訪問,因此需要引入Import org.apache.spark.SparkContext._。
不過到了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偷梁換柱換柱,讓隔壁老王來干你干不了的事情了。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。