title: Cannot up cast `ordId` from string to int as it may truncate
body: <p>I am trying to read a small file as a Dataset but its giving the  error </p>
  
  <blockquote>
    <p>"Cannot up cast <code>ordId</code> from string to int as it may truncate".</p>
  </blockquote>
  
  <p>Here is the code:</p>
  
  <pre><code>object Main {
    case class Orders(ordId: Int, custId: Int, amount: Float, date: String)
  
    def main(args : Array[String]): Unit ={
  
      val schema = Encoders.product[Orders].schema
  
        val spark = SparkSession.builder
          .master ("local[*]")
          .appName ("")
          .getOrCreate ()
  
  
      val df = spark.read.option("header",true).csv("/mnt/data/orders.txt")
  
  
      import spark.implicits._
      val ds = df.as[Orders]
  
    }
  }
  </code></pre>
  
  <p>orders.txt</p>
  
  <pre><code>ordId,custId,amount,date
  1234,123,400,20190112
  2345,456,600,20190122
  1345,123,500,20190123
  3456,345,800,20190202
  5678,123,600,20190203
  6578,455,900,20190301
  </code></pre>
  
  <p>How can I resolve this error?. Also I would like to know that do I first need to read the file as a Dataframe and then convert to a Dataset?</p>