score:3

Accepted answer

seems good to me :-s type inference is far from omniscient. sometimes you need to specify the types explicitly. in my experience, this is especially true when the result type can be anything. some things to try:

  1. my preferred option since you are not touching the key: joinedrdd.mapvalues(x => x._1 + x._2)
  2. add some type information: val d1: double = x._2._1. with some luck, at least the compiler might be more explicit.
  3. define your function separately, assigning types to the parameters, and use if inside: map(myfunc)

also, i've seen some differences between intellij scala plugin and the actual scala compiler. given the errors you are getting and the fact that anyval is the common parent class for both int and double, there is a good chance you don't have doubles to begin with (and the compiler is trying to find a shared parent). do double check that you are getting the type you mention by putting it explicitly. it is very possible that your type confusion occurs before this line.

good luck!

score:2

well, i tried in intellij idea 14 and the type inference is correct, recognizing d1 and d2 as double (this was expected). nonetheless, i usually avoid the type-aware highlighting feature of idea since many times it goes crazy and reports fake results.

as a side note, since you are not changing the key of your rdd, consider using mapvalues instead of map (this provides clarity, as well as performance since it would take advantage of the partitioner of the input rdd and reuse it in the output rdd).


Related Query

More Query from same tag