2016-02-26 92 views
0

我是Scala的新手。我知道这个错误是与Tuple1,Tuple2初始化相关的东西,但不能完全理解确切的原因。这个scala错误是什么意思:“type mismatch; found :(((Long,Long),Long),)required:(((Long,Long),Long))⇒String”

这里是我得到的语法错误消息: 类型不匹配;发现:((Long,Long),Long)required :(((Long,Long),Long))⇒字符串

这里是导致它的代码片段。

dedupedRDD = iterateRDD.mapPartitions(p => { 
     var minVal = 0L 
     p.map { 
      val tpl = p.next() 
      val key = tpl._1._1 
      val value = tpl._2 
      var outputTuple : Tuple2[Tuple2[Long, Long],Long] = null 
      if(key != prevKey){ 
       if(value < key){ 
       minVal = value; 
       outputTuple = ((minVal, key) , key) 
       newEdgeCounter.add(1L); 
       }else{ 
       minVal = key; 
       outputTuple = ((minVal,value), value) 
       } 
      }else{ 
       outputTuple = ((minVal, value), value) 
      } 
      prevKey = key; 
      outputTuple 
      } 
     }) 

如何创建(((龙,龙),龙))的输出元组。 任何帮助将不胜感激。谢谢。

回答

3

你创建outputTuples就好了,但是你没有从输出元组创建一个函数到一个字符串。

它表示它想要类型(((Long, Long), Long)) => String,这意味着它是一个函数,它将((Long, Long), Long)作为参数并生成一个字符串。这里有一个这样的功能:

val lll2s = (lll: ((Long, Long), Long)) => { 
    (lll._1._1 + lll._1._2 + lll._2).toString 
} 

它看起来对我这样应该是参数p.map

例如你可以写

p.map{ case ((a1, a2), b) => 
    // Your code here---easy to access tuple components because you named them 
    // Do something that produces a String 
} 
+0

我会同意@Rex Kerr。你需要输出一个字符串,而不是输出一个元组(var outputTuple)。你需要做一些创建一个字符串的东西。 –