How to enforce datatype for Spark DataFrame read from json -
when read json (without schema) dataframe, numeric types going long. there way enforce integer type without giving specified json schema?
you can convert dataframe dataset case class
val df = seq((1,"ab"),(3,"ba")).todf("a","b") case class test(a: int, b: string) df.as[test] or duplicate column , recast df.
import org.apache.spark.sql.types.{stringtype} df.withcolumn("newa", 'a.cast(stringtype))
Comments
Post a Comment