当前位置:   article > 正文

error:value reduceByKey is not a member of Array[(String, Int)]_error value reducebykey is not a member of array[(

error value reducebykey is not a member of array[(string,int)]
Scala报错value reduceByKey is not a member of Array[(String, Int)]

1.原因在于在spark中,使用scala编程时,没有使用pairRDD

2.错误代码示例:

val book = Array(("spark",2),("hadoop",6),("hadoop",4),("spark",6))
val result = book.reduceByKey(_+_)
  • 1
  • 2

3.修正如下:

val book = Array(("spark",2),("hadoop",6),("hadoop",4),("spark",6))
val rdd = sc.parallelize(book)
val result = book.reduceByKey(_+_)
  • 1
  • 2
  • 3

4.原理分析:【待整理】

  • 什么是pairRDD
  • 为什么需要sc.parallelize()?
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/秋刀鱼在做梦/article/detail/899587
推荐阅读
相关标签
  

闽ICP备14008679号