title: Explicit cast reading .csv with case class Spark 2.1.0
body: <p>I have the following case class:</p>
  
  <pre><code>case class OrderDetails(OrderID : String, ProductID : String, UnitPrice : Double,
                      Qty : Int, Discount : Double)
  </code></pre>
  
  <p>I am trying read this csv: <a href="https://github.com/xsankar/fdps-v3/blob/master/data/NW-Order-Details.csv" rel="noreferrer">https://github.com/xsankar/fdps-v3/blob/master/data/NW-Order-Details.csv</a></p>
  
  <p>This is my code:</p>
  
  <pre><code>val spark = SparkSession.builder.master(sparkMaster).appName(sparkAppName).getOrCreate()
  import spark.implicits._
  val orderDetails = spark.read.option("header","true").csv( inputFiles + "NW-Order-Details.csv").as[OrderDetails]
  </code></pre>
  
  <p>And the error is:</p>
  
  <pre><code> Exception in thread "main" org.apache.spark.sql.AnalysisException: 
   Cannot up cast `UnitPrice` from string to double as it may truncate
   The type path of the target object is:
    - field (class: "scala.Double", name: "UnitPrice")
    - root class: "es.own3dh2so4.OrderDetails"
   You can either add an explicit cast to the input data or choose a higher precision type of the field in the target object;
  </code></pre>
  
  <p>Why can not it be transformed if all fields are "doubles" values? What do not I understand?</p>
  
  <p>Spark version 2.1.0, Scala version 2.11.7</p>