Reputation: 1290
I want to convert a Dataframe to Dataset[CC].
case class CC(id: String, value: String)
df.as[CC]
However if in the id or value is null I would like the operation to throw an exception. Is this possible?
Upvotes: 0
Views: 161
Reputation: 2451
maybe this way:
val ds = df.map(s=>{
s.toSeq.foreach(x=>{
if (x == null) throw new Exception("null value: "+s.mkString(","))
})
new CC(s.getString(0),s.getString(1))
})
+----+----+
| _c0| _c1|
+----+----+
| 1| a|
| 2|null|
| 3| b|
|null|null|
| 5|null|
+----+----+
and exception:
`Caused by: java.lang.Exception: null value: 2,null`
Upvotes: 1