Github user HyukjinKwon commented on a diff in the pull request:

    https://github.com/apache/spark/pull/11724#discussion_r56444849
  
    --- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/csv/CSVInferSchema.scala
 ---
    @@ -108,14 +109,38 @@ private[csv] object CSVInferSchema {
       }
     
       private def tryParseDouble(field: String): DataType = {
    -    if ((allCatch opt field.toDouble).isDefined) {
    +    val doubleTry = allCatch opt field.toDouble
    --- End diff --
    
    Ah.. numeric types with fractions can be also `Decimal`. It has precision 
and scale.
    
    ```scala
    import java.math.BigDecimal
    scala> BigDecimal.valueOf(1.1111)
    res4: java.math.BigDecimal = 1.1111
    
    scala> BigDecimal.valueOf(1.1111).precision
    res6: Int = 5
    
    scala> BigDecimal.valueOf(1.1111).scale
    res7: Int = 4
    ```
    
    ```scala
    import java.math.BigDecimal
    scala> BigDecimal.valueOf(1)
    res5: java.math.BigDecimal = 1
    
    scala> BigDecimal.valueOf(1).precision
    res8: Int = 1
    
    scala> BigDecimal.valueOf(1).scale
    res9: Int = 0
    ```
    
    `DoubleType` with fractions can lose precision if it has too many.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to