File tree Expand file tree Collapse file tree 1 file changed +12
-3
lines changed
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/json Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change 1717
1818package org .apache .spark .sql .catalyst .json
1919
20+ import java .text .ParsePosition
2021import java .util .Comparator
2122
2223import scala .util .control .Exception .allCatch
@@ -123,10 +124,18 @@ private[sql] class JsonInferSchema(options: JSONOptions) extends Serializable {
123124 decimalTry.getOrElse(StringType )
124125 case VALUE_STRING =>
125126 val stringValue = parser.getText
126- if ((allCatch opt options.timestampFormat.parse(stringValue)).isDefined) {
127- TimestampType
128- } else if ((allCatch opt options.dateFormat.parse(stringValue)).isDefined) {
127+ val dateTry = allCatch opt {
128+ val pos = new ParsePosition (0 )
129+ options.dateFormat.parse(stringValue, pos)
130+ if (pos.getErrorIndex != - 1 || pos.getIndex != stringValue.length) {
131+ throw new IllegalArgumentException (
132+ s " $stringValue cannot be parsed as ${DateType .simpleString}" )
133+ }
134+ }
135+ if (dateTry.isDefined) {
129136 DateType
137+ } else if ((allCatch opt options.timestampFormat.parse(stringValue)).isDefined) {
138+ TimestampType
130139 } else if ((allCatch opt DateTimeUtils .stringToTime(stringValue)).isDefined) {
131140 // We keep this for backwards compatibility.
132141 TimestampType
You can’t perform that action at this time.
0 commit comments