How to restructure the code to avoid the warning: "Adapting the argument list by creating 2-tuples"

The following code has already been tested as working, as I want it: for example, adding a tuple to an existing sequence (also from tuples)

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

However, our build system has it fail on warningturned on and thus produces the code above:

[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 already mentioned - this is what I want. But Travisyou need to make happy. So, what is the right call to sign the same —ie is the desired behavior — and avoid the warnings here?

+4
source share
1 answer

Try to help the compiler by explicitly adding a method call and parentheses.

iter.map { r: Row => 
   r.toSeq.:+( (outColName,locMap(r.getAs[String](inColName))):Any )
}
+1

Source: https://habr.com/ru/post/1667723/


All Articles