Github user lw-lin commented on a diff in the pull request:
https://github.com/apache/spark/pull/14118#discussion_r70182426
--- Diff:
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/csv/CSVInferSchema.scala
---
@@ -238,59 +238,55 @@ private[csv] object CSVTypeCast {
nullable: Boolean = true,
options: CSVOptions = CSVOptions()): Any = {
- castType match {
- case _: ByteType => if (datum == options.nullValue && nullable) null
else datum.toByte
- case _: ShortType => if (datum == options.nullValue && nullable)
null else datum.toShort
- case _: IntegerType => if (datum == options.nullValue && nullable)
null else datum.toInt
- case _: LongType => if (datum == options.nullValue && nullable) null
else datum.toLong
- case _: FloatType =>
- if (datum == options.nullValue && nullable) {
- null
- } else if (datum == options.nanValue) {
- Float.NaN
- } else if (datum == options.negativeInf) {
- Float.NegativeInfinity
- } else if (datum == options.positiveInf) {
- Float.PositiveInfinity
- } else {
- Try(datum.toFloat)
-
.getOrElse(NumberFormat.getInstance(Locale.getDefault).parse(datum).floatValue())
- }
- case _: DoubleType =>
- if (datum == options.nullValue && nullable) {
- null
- } else if (datum == options.nanValue) {
- Double.NaN
- } else if (datum == options.negativeInf) {
- Double.NegativeInfinity
- } else if (datum == options.positiveInf) {
- Double.PositiveInfinity
- } else {
- Try(datum.toDouble)
-
.getOrElse(NumberFormat.getInstance(Locale.getDefault).parse(datum).doubleValue())
- }
- case _: BooleanType => datum.toBoolean
- case dt: DecimalType =>
- if (datum == options.nullValue && nullable) {
- null
- } else {
+ if (datum == options.nullValue && nullable &&
(!castType.isInstanceOf[StringType])) {
--- End diff --
> ... why StringType is excluded?
Hi @HyukjinKwon, it's just to keep consistency with we did in `spark-csv`
for 1.6. Actually I don't have strong preference here -- maybe we should not
ignore `StringType`? @rxin could you share some thoughts? Thanks!
---
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]