0
votes

I am new to Scala. I know the error is something related to Tuple1, Tuple2 initialization but not able to quite grab the exact reason.

Here is the syntax error message I am getting: type mismatch; found : ((Long, Long), Long) required: (((Long, Long), Long)) ⇒ String

and here is the code snippet causing it.

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
          }
      })

How do I create output tuples of (((Long, Long), Long)). Any help will be greatly appreciated. Thanks.

1

1 Answers

3
votes

You created outputTuples just fine, but you didn't create a function from output tuples to a string.

It says it wants type (((Long, Long), Long)) => String, which means it's a function taking ((Long, Long), Long) as an argument and producing a string. Here is one such function:

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

It looks to me like this is supposed to be the argument to p.map.

E.g. you could write

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