title: Create Spark Dataset from a CSV file
body: <p>I would like to create a Spark Dataset from a simple CSV file.  Here are the contents of the CSV file:</p>
  
  <pre><code>name,state,number_of_people,coolness_index
  trenton,nj,"10","4.5"
  bedford,ny,"20","3.3"
  patterson,nj,"30","2.2"
  camden,nj,"40","8.8"
  </code></pre>
  
  <p>Here is the code to make the Dataset:</p>
  
  <pre><code>var location = "s3a://path_to_csv"
  
  case class City(name: String, state: String, number_of_people: Long)
  
  val cities = spark.read
    .option("header", "true")
    .option("charset", "UTF8")
    .option("delimiter",",")
    .csv(location)
    .as[City]
  </code></pre>
  
  <p>Here is the error message: "Cannot up cast <code>number_of_people</code> from string to bigint as it may truncate"</p>
  
  <p>Databricks talks about creating Datasets and this particular error message in <a href="https://databricks.com/blog/2016/01/04/introducing-apache-spark-datasets.html" rel="noreferrer">this blog post</a>.</p>
  
  <blockquote>
    <p>Encoders eagerly check that your data matches the expected schema,
    providing helpful error messages before you attempt to incorrectly
    process TBs of data. For example, if we try to use a datatype that is
    too small, such that conversion to an object would result in
    truncation (i.e. numStudents is larger than a byte, which holds a
    maximum value of 255) the Analyzer will emit an AnalysisException.</p>
  </blockquote>
  
  <p>I am using the <code>Long</code> type, so I didn't expect to see this error message.</p>