Github user srowen commented on a diff in the pull request:
https://github.com/apache/spark/pull/14118#discussion_r78913621
--- Diff:
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/csv/CSVInferSchema.scala
---
@@ -232,66 +232,62 @@ 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 {
- val value = new BigDecimal(datum.replaceAll(",", ""))
- Decimal(value, dt.precision, dt.scale)
- }
- case _: TimestampType =>
- // This one will lose microseconds parts.
- // See https://issues.apache.org/jira/browse/SPARK-10681.
- Try(options.timestampFormat.parse(datum).getTime * 1000L)
- .getOrElse {
- // If it fails to parse, then tries the way used in 2.0 and
1.x for backwards
- // compatibility.
- DateTimeUtils.stringToTime(datum).getTime * 1000L
+ if (datum == options.nullValue && nullable) {
--- End diff --
Is it possibly worth checking `if (nullable && ...)` to avoid the
comparison if it's not nullable?
---
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]