Github user HyukjinKwon commented on a diff in the pull request: https://github.com/apache/spark/pull/16735#discussion_r98795601 --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/csv/CSVInferSchema.scala --- @@ -140,12 +137,21 @@ private[csv] object CSVInferSchema { } } + private def tryParseDate(field: String, options: CSVOptions): DataType = { + // This case infers a custom `dateFormat` is set. + if ((allCatch opt options.dateFormat.parse(field)).isDefined) { + DateType + } else { + tryParseTimestamp(field, options) + } + } + private def tryParseTimestamp(field: String, options: CSVOptions): DataType = { - // This case infers a custom `dataFormat` is set. + // This case infers a custom `timestampFormat` is set. if ((allCatch opt options.timestampFormat.parse(field)).isDefined) { TimestampType } else if ((allCatch opt DateTimeUtils.stringToTime(field)).isDefined) { - // We keep this for backwords competibility. + // We keep this for backwards compatibility. TimestampType } else { tryParseBoolean(field, options) --- End diff -- Ah, I just checked that changing that line causes test failures. The reason seems the default format in `FastDateFormat`, `yyyy-MM-dd` seems parsing the input , `2015-08-20 15:57:00` fine if we change that line. But if we change this line, then, It seems we are inferring `TimestampType` from `yyyy-MM-dd` in `DateTimeUtils.stringToTime(field)`, which seems not respecting the default format in `dateFormat`, assuming you meant trying `TimestampType` first, which sounds a bit odd to try wider type first.
--- 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 infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org