Github user HyukjinKwon commented on a diff in the pull request:
https://github.com/apache/spark/pull/11724#discussion_r56785216
--- 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 --
I see. There is a problem here.
- The maximum precision supported in Spark `DecimalType` is 38.
- In Spark `DecimalType`, `scale` cannot be more than `precision`, meaning
there should not be such a value, `0.xxx..` for Spark `DecimalType`.
Now I cannot think of more than three options below:
- Try `DecimalType` first. In this case, some basic number with fractions
such as `1.1` will be inferred as `DecimalType`.
- Try `DecimalType` first and let `DecimalType` do not treat numbers with
fractions by checking `scale`.
- Try `DoubleType` first and check the precision loss.
- If it loses, try `DecimalType`
- If it fails to be parsed as `DecimalType` (due to both conditions in
`DecimalType` above), then infer this as `DoubleType` allowing the precision
loss.
If none of them is preferable, then I will close this as I cannot come up
with a better idea.
---
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]