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

    https://github.com/apache/spark/pull/22979#discussion_r232487559
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/csv/UnivocityParser.scala
 ---
    @@ -149,8 +156,8 @@ class UnivocityParser(
     
         case dt: DecimalType => (d: String) =>
           nullSafeDatum(d, name, nullable, options) { datum =>
    -        val value = new BigDecimal(datum.replaceAll(",", ""))
    -        Decimal(value, dt.precision, dt.scale)
    +        val bigDecimal = 
decimalParser.parse(datum).asInstanceOf[BigDecimal]
    --- End diff --
    
    > is it safe that we assume this Number is BigDecimal?
    
    I am not absolutely sure that it always return `BigDecimal`. Found this at 
https://docs.oracle.com/javase/8/docs/api/java/text/DecimalFormat.html#parse(java.lang.String,java.text.ParsePosition)
 :
    ```
    If isParseBigDecimal() is true, values are returned as BigDecimal objects. 
The values are the ones constructed by BigDecimal.BigDecimal(String) for 
corresponding strings in locale-independent format. The special cases negative 
and positive infinity and NaN are returned as Double instances holding the 
values of the corresponding Double constants.
    ```
    So, `isParseBigDecimal()` returns `true` when `setParseBigDecimal` was 
called with `true` as in the PR.
    
    > Looks there are some possibilities that it can return other types.
    
    In that case we just fail with a cast exception and the record will be 
handled as a bad record. or you want to see more clear message in the exception?


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to