Skip to content

Commit

Permalink
Infer date type before timestamp type
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxGekk committed Dec 3, 2018
1 parent 45958bd commit a6723f3
Showing 1 changed file with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,18 +150,6 @@ class CSVInferSchema(options: CSVOptions) extends Serializable {
private def tryParseDouble(field: String): DataType = {
if ((allCatch opt field.toDouble).isDefined || isInfOrNan(field)) {
DoubleType
} else {
tryParseTimestamp(field)
}
}

private def tryParseTimestamp(field: String): DataType = {
// This case infers a custom `dataFormat` is set.
if ((allCatch opt options.timestampFormat.parse(field)).isDefined) {
TimestampType
} else if ((allCatch opt DateTimeUtils.stringToTime(field)).isDefined) {
// We keep this for backwards compatibility.
TimestampType
} else {
tryParseDate(field)
}
Expand All @@ -177,6 +165,18 @@ class CSVInferSchema(options: CSVOptions) extends Serializable {
}
if (dateTry.isDefined) {
DateType
} else {
tryParseTimestamp(field)
}
}

private def tryParseTimestamp(field: String): DataType = {
// This case infers a custom `dataFormat` is set.
if ((allCatch opt options.timestampFormat.parse(field)).isDefined) {
TimestampType
} else if ((allCatch opt DateTimeUtils.stringToTime(field)).isDefined) {
// We keep this for backwards compatibility.
TimestampType
} else {
tryParseBoolean(field)
}
Expand Down

0 comments on commit a6723f3

Please sign in to comment.