You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by falaki <gi...@git.apache.org> on 2016/04/05 21:00:31 UTC
[GitHub] spark pull request: [SPARK-14143] Options for parsing NaNs, Infini...
Github user falaki commented on a diff in the pull request:
https://github.com/apache/spark/pull/11947#discussion_r58596297
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/csv/CSVInferSchema.scala ---
@@ -177,35 +177,57 @@ private[csv] object CSVTypeCast {
datum: String,
castType: DataType,
nullable: Boolean = true,
- nullValue: String = ""): Any = {
+ params: CSVOptions = CSVOptions()): Any = {
- if (datum == nullValue && nullable && (!castType.isInstanceOf[StringType])) {
- null
- } else {
- castType match {
- case _: ByteType => datum.toByte
- case _: ShortType => datum.toShort
- case _: IntegerType => datum.toInt
- case _: LongType => datum.toLong
- case _: FloatType => Try(datum.toFloat)
- .getOrElse(NumberFormat.getInstance(Locale.getDefault).parse(datum).floatValue())
- case _: DoubleType => Try(datum.toDouble)
- .getOrElse(NumberFormat.getInstance(Locale.getDefault).parse(datum).doubleValue())
- case _: BooleanType => datum.toBoolean
- case dt: DecimalType =>
+ castType match {
+ case _: ByteType => if (datum == params.byteNullValue && nullable) null else datum.toByte
+ case _: ShortType => if (datum == params.shortNullValue && nullable) null else datum.toShort
+ case _: IntegerType => if (datum == params.integerNullValue && nullable) null else datum.toInt
+ case _: LongType => if (datum == params.longNullValue && nullable) null else datum.toLong
+ case _: FloatType =>
+ if (datum == params.floatNullValue && nullable) {
+ null
+ } else if (datum == params.floatNaNValue) {
+ Float.NaN
+ } else if (datum == params.floatNegativeInf) {
+ Float.NegativeInfinity
+ } else if (datum == params.floatPositiveInf) {
+ Float.PositiveInfinity
+ } else {
+ Try(datum.toFloat)
+ .getOrElse(NumberFormat.getInstance(Locale.getDefault).parse(datum).floatValue())
+ }
+ case _: DoubleType =>
+ if (datum == params.doubleNullValue && nullable) {
+ null
+ } else if (datum == params.doubleNaNValue) {
+ Double.NaN
+ } else if (datum == params.doubleNegativeInf) {
+ Double.NegativeInfinity
+ } else if (datum == params.doublePositiveInf) {
+ Double.PositiveInfinity
+ } else {
+ Try(datum.toDouble)
--- End diff --
I think in this case, in a private and unexposed method, this seem OK. There are many other instances of it in `CSVInferSchema`
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org