Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to restructure code to avoid warning: "Adapting argument list by creating a 2-tuple"

The following code has already been verified as working as I want it: i.e. adding a tuple to an existing sequence (also of tuples)

iter.map { r =>     // Iterator of org.apache.spark.sql.Row
   r.toSeq :+ (outColName,locMap(r.getAs[String](inColName)))
}

However our build system has fail on warning enabled and thus errors out the above code with:

[info] 'compiler-interface' not yet compiled for Scala 2.10.6. Compiling...
[info]   Compilation completed in 24.504 s
[error] /home/../Sampling.scala:40: Adapting argument list 
         by creating a 2-tuple: this may not be what you want.
[error]         signature: SeqLike.:+[B >: A, That](elem: B)(implicit bf: scala.collection.generic.CanBuildFrom[Repr,B,That]): That
[error]   given arguments: outColName, locMap(r.getAs[String](inColName))
[error]  after adaptation: SeqLike.:+((outColName, locMap(r.getAs[String](inColName))): (String, Int))
[error]           r.toSeq :+ (outColName,locMap(r.getAs[String](inColName)))
[error]                   ^
[error] one error found

Now - as mentioned - this is what I want. But Travis needs to be made happy. So what is the correct invocation to signfify the same -i.e. this is the desired behavior - and avoid the warnings here?

like image 433
WestCoastProjects Avatar asked Oct 29 '22 13:10

WestCoastProjects


1 Answers

Try to help the compiler by explicitly adding the method invocation and the parenthesis.

iter.map { r: Row => 
   r.toSeq.:+( (outColName,locMap(r.getAs[String](inColName))):Any )
}
like image 84
marios Avatar answered Nov 15 '22 07:11

marios