When I call RDD.mapValues(...).reduceByKey(...)
my code does not compile. But when I reverse the order, RDD.reduceByKey(...).mapValues(...)
, the code does compile. The types appear to match up.
A complete minimal reproducing example is:
def test[E]() =
new SparkContext().textFile("")
.keyBy(_ ⇒ 0L)
.mapValues(_.asInstanceOf[E])
.reduceByKey((x, _) ⇒ x)
The compilation error is the same as in this question but its remedy doesn't help:
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)
This issue seems to more at the Scala level than Spark. Replacing the type parameter with Int works so it might be a problem with type inference. I am using Spark 2.2.0 with Scala 2.11.