score:3
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:
- my preferred option since you are not touching the key:
joinedrdd.mapvalues(x => x._1 + x._2)
- add some type information:
val d1: double = x._2._1
. with some luck, at least the compiler might be more explicit. - 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).
Source: stackoverflow.com
Related Query
- Scala wrong type inference
- Scala String vs java.lang.String - type inference
- Different type inference for `def` and `val` in Scala
- What are the differences between the type inference of Scala and C++11?
- Scala type inference on overloaded method
- Why does Scala type inference fail here?
- Scala Tuple type inference in Java
- Generic type inference in Scala
- Type inference for a scala combinator calculus data model
- Scala type inference for existential types and type members
- scala type inference with _ place holder
- Scala type inference working with Slick Table
- Scala : Does variable type inference affect performance?
- Scala type inference question
- Scala type inference fails to note that these types are identical, whatever they are
- Scala for-comprehension type inference
- Scala Type Inference Issues with Parametric Function
- scala 2.9: plans for type inference of function parameters with default arguments?
- Scala pattern matching and type inference
- Type inference and pattern maching in Scala
- Scala type inference breaking down in obvious setting?
- Type Inference in Haskell v. Scala
- Scala currying and type inference
- Type inference changes in Scala 3
- A compiling error about scala type inference
- Scala type inference failure on "? extends" in Java code
- Complex Scala Type Inference w/ Lambda Expressions
- Why type inference failed in Scala when using implicit conversion on return value of Option.getOrElse?
- Scala type inference for both a generic type and it's type parameter - why doesn't it work?
- Type inference in generic curried method in Scala
More Query from same tag
- Could not find or load main class sbt-assembly executable jar
- Akka event bus with typed actor
- IntelliJ scala console, interactive developement
- Filter out struct of null values from an array of structs in spark dataframe
- Fold over HList with unknown Types
- Deploy lift application on Tomcat
- No implementation for play.modules.reactivemongo.ReactiveMongoApi was bound
- How do I get IntelliJ autocomplete to include implicit conversions/classes by default
- Different types of data in a same column in Parquet partition
- How to cut a long ScalaTest spec to pieces
- scala's type checker doesn't recognize types in abstract path-dependent classes scenario
- Creating a CanBuildFrom in Scala
- Access first default parameter value while supplying the rest
- Play Framework without dependency injection?
- I18n in Play Framework 2.4.0
- How to add an element to the end of a seq in scala?
- scala actors vs threads and blocking IO
- Convert spark row object to java pojo
- What is right way to store and retrieve sensitive and non-sensitive constants?
- Why does maxBy return only single item?
- Scala's mutable.ListBuffer seems to use List's tail function yet it is documented as having linear complexity?
- Plot a dataframe in scala using WISP
- How do I use the sbt-native-packager with multiple projects
- using a partial function for catch block with scala
- scalate does not compile templates in tomcat
- How to change the number of cores used in code?
- Nesting Regex within Option match
- Java/Scala BigInteger Pasting
- scala Future to run sequential jobs
- How does HList.foldRight look for implicits when used in the implementation of a type class?