我在Scala中有一个任务,到目前为止,这么好。一切编译除了这一点:Scala mapValues()类型不匹配
@transient val aggs = msgs.transform { rdd =>
val ts = rdd.map(quote => quote.ts).max() /// maximum of timestamp in the rdd
rdd.map{ q =>
((q.symbol,q.ts),(q.price,ts)) /// ((String, Long), (Double, Long)) structure
}
}
.reduceByKey{ (x,y) => (x._1 + y._1, x._2 + y._2) } // returns (Double, Long)
.mapValues((x: Double,y: Long) => (y.toDouble/x.toDouble)) // (Double, Long) => (Double)
.map{ case ((s,t),v) => (s,t,v)}
这件作品我卡上是mapValues()的匿名函数
:95: error: type mismatch;
found : (Double, Long) => Double
required: ((Double, Long)) => ?
任何人都可以点我在正确的方向?
我想也许是因为'mapValues'你给了你的输入一个特定的情况,但是如果它是默认情况,它会返回什么? –