I wrote the following code to take some action based on a field value for each row:
import spark.implicits._
table.map(line =>
column_names.map(column =>
if (line.getAs[Int](column)==0)
println("yes")
)
)
However I encounter the following error:
java.lang.UnsupportedOperationException: No Encoder found for Unit
- array element class: "scala.runtime.BoxedUnit"
- root class: "scala.collection.immutable.List"
I understand that an encoder is required to convert objects and primitives in the Spark InternalRow, but the field that I'm trying to access contains an int, and based on my understanding the corresponding encoder should be available thanks to spark.implicits._.
Could you please tell me what am I missing and what should I do to fix it?