【发布时间】:2018-08-30 22:04:03
【问题描述】:
当我调用RDD.mapValues(...).reduceByKey(...) 时,我的代码无法编译。但是当我颠倒顺序时,RDD.reduceByKey(...).mapValues(...),代码确实编译了。类型似乎匹配。
一个完整的最小复制示例是:
def test[E]() =
new SparkContext().textFile("")
.keyBy(_ ⇒ 0L)
.mapValues(_.asInstanceOf[E])
.reduceByKey((x, _) ⇒ x)
编译错误与this question 中的相同,但其补救措施没有帮助:
Test.scala:7: error: value reduceByKey is not a member of org.apache.spark.rdd.RDD[(Long, E)]
possible cause: maybe a semicolon is missing before `value reduceByKey'?
.reduceByKey((x, _) ⇒ x)
这个问题似乎比 Spark 更多地出现在 Scala 级别。用 Int 替换类型参数是可行的,因此它可能是类型推断的问题。我将 Spark 2.2.0 与 Scala 2.11 一起使用。
【问题讨论】:
标签: scala apache-spark type-inference