HyukjinKwon opened a new pull request #24437: [SPARK-27512][SQL] Avoid to 
replace ',' in CSV's decimal type inference for backward compatibility
URL: https://github.com/apache/spark/pull/24437
 
 
   ## What changes were proposed in this pull request?
   
   The code below currently infers as decimal but previously it was inferred as 
string.
   
   **In branch-2.4**, type inference path for decimal and parsing data are 
different.
   
   
https://github.com/apache/spark/blob/2a8343121e62aabe5c69d1e20fbb2c01e2e520e7/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/csv/UnivocityParser.scala#L153
   
   
https://github.com/apache/spark/blob/c284c4e1f6f684ca8db1cc446fdcc43b46e3413c/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/csv/CSVInferSchema.scala#L125
   
   So the code below:
   
   ```scala
   scala> spark.read.option("delimiter", "|").option("inferSchema", 
"true").csv(Seq("1,2").toDS).printSchema()
   ```
   
   produced string as its type.
   
   ```
   root
    |-- _c0: string (nullable = true)
   ```
   
   **In the current master**, it now infers decimal as below:
   
   ```
   root
    |-- _c0: decimal(2,0) (nullable = true)
   ```
   
   It happened after https://github.com/apache/spark/pull/22979 because, now 
after this PR, we only have one way to parse decimal:
   
   
https://github.com/apache/spark/blob/7a83d71403edf7d24fa5efc0ef913f3ce76d88b8/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/ExprUtils.scala#L92
   
   **After the fix:**
   
   ```
   root
    |-- _c0: string (nullable = true)
   ```
   
   This PR proposes to restore the previous behaviour back in `CSVInferSchema`.
   
   ## How was this patch tested?
   
   Manually tested and unit tests were added.
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

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

Reply via email to