I'm exploring features of Spark 2.0, and am trying to load a simple csv file
into a dataset.

These are the contents of my file named people.csv:

name,age,occupation
John,21,student
Mark,33,analyst
Susan,27,scientist

Below is my code: 

import org.apache.spark.sql._
val spark =
SparkSession.builder().appName("test").master("local").getOrCreate
val data = spark.read.option("header", true).csv("people.csv")
import spark.implicits._
case class People(name: String, age: Int, occupation: String)
val people = train.as[People]

Running the above gives me the following error:

org.apache.spark.sql.AnalysisException: Cannot up cast `age` from bigint to
int as it may truncate
The type path of the target object is:
- field (class: "scala.Int", name: "age")
- root class: "People"
You can either add an explicit cast to the input data or choose a higher
precision type of the field in the target object;

How do I fix that? Is this not the right way to directly load data from csv
into a dataset using the desired case class?



--
View this message in context: 
http://apache-spark-user-list.1001560.n3.nabble.com/Error-casting-from-data-frame-to-case-class-object-tp27717.html
Sent from the Apache Spark User List mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe e-mail: user-unsubscr...@spark.apache.org

Reply via email to