0
我是新來的scala,學習它爲apache-spark。我在斯卡拉寫了一個簡單的功能graphXgraphX代碼中的scala類型不匹配錯誤
def foo(edge: EdgeTriplet[Map[Long, Double], Double]): Iterator[(VertexId, Map[Long, Double])] = {
val m = edge.srcAttr
for((k, v) <- m){
if (v + edge.attr < edge.dstAttr.getOrElse(k, 10.0))
Iterator(edge.dstId, Map(k -> v + edge.attr))
else
Iterator.empty
}
}
錯誤
Name: Compile Error
Message: <console>:37: error: type mismatch;
found : Double
required: String
Iterator(edge.dstId, Map(k -> v + edge.attr))
^
<console>:35: error: type mismatch;
found : Unit
required: Iterator[(org.apache.spark.graphx.VertexId, Map[Long,Double])]
(which expands to) Iterator[(Long, Map[Long,Double])]
for((k, v) <- m){
^
StackTrace:
爲什麼Scala是治療v爲字符串?第二個錯誤的原因是什麼?
編輯代碼通過@Alexey的建議後,我收到提示
Name: Compile Error
Message: <console>:30: error: type mismatch;
found : scala.collection.immutable.Map[org.apache.spark.graphx.VertexId,scala.collection.immutable.Map[Long,Double]]
(which expands to) scala.collection.immutable.Map[Long,scala.collection.immutable.Map[Long,Double]]
required: Iterator[(org.apache.spark.graphx.VertexId, Map[Long,Double])]
(which expands to) Iterator[(Long, Map[Long,Double])]
(k, v) <- edge.srcAttr
^
StackTrace:
如果有幫助,我是從這個code
第一個錯誤已經解決了,感謝您的解決方案。仍然在尋找第二個解決方案 – ashwinids
請參閱編輯答案。我原來並沒有發現它。 –
請你可以寫解決方案的完整代碼到第二個問題,因爲我得到的錯誤不匹配:Iterable [Any],需要Iterator [(Long,Map [Long,Double])] – ashwinids