@@ -22,20 +22,16 @@ import scala.util.control.Exception.allCatch
22
22
import org .apache .spark .rdd .RDD
23
23
import org .apache .spark .sql .catalyst .analysis .TypeCoercion
24
24
import org .apache .spark .sql .catalyst .expressions .ExprUtils
25
- import org .apache .spark .sql .catalyst .util .{ DateFormatter , TimestampFormatter }
25
+ import org .apache .spark .sql .catalyst .util .TimestampFormatter
26
26
import org .apache .spark .sql .types ._
27
27
28
28
class CSVInferSchema (val options : CSVOptions ) extends Serializable {
29
29
30
30
@ transient
31
- private lazy val timestampFormatter = TimestampFormatter (
31
+ private lazy val timestampParser = TimestampFormatter (
32
32
options.timestampFormat,
33
33
options.timeZone,
34
34
options.locale)
35
- @ transient
36
- private lazy val dateFormatter = DateFormatter (
37
- options.dateFormat,
38
- options.locale)
39
35
40
36
private val decimalParser = {
41
37
ExprUtils .getDecimalParser(options.locale)
@@ -108,7 +104,6 @@ class CSVInferSchema(val options: CSVOptions) extends Serializable {
108
104
compatibleType(typeSoFar, tryParseDecimal(field)).getOrElse(StringType )
109
105
case DoubleType => tryParseDouble(field)
110
106
case TimestampType => tryParseTimestamp(field)
111
- case DateType => tryParseDate(field)
112
107
case BooleanType => tryParseBoolean(field)
113
108
case StringType => StringType
114
109
case other : DataType =>
@@ -164,16 +159,9 @@ class CSVInferSchema(val options: CSVOptions) extends Serializable {
164
159
}
165
160
166
161
private def tryParseTimestamp (field : String ): DataType = {
167
- if ((allCatch opt timestampFormatter.parse(field)).isDefined) {
162
+ // This case infers a custom `dataFormat` is set.
163
+ if ((allCatch opt timestampParser.parse(field)).isDefined) {
168
164
TimestampType
169
- } else {
170
- tryParseDate(field)
171
- }
172
- }
173
-
174
- private def tryParseDate (field : String ): DataType = {
175
- if ((allCatch opt dateFormatter.parse(field)).isDefined) {
176
- DateType
177
165
} else {
178
166
tryParseBoolean(field)
179
167
}
0 commit comments