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

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -