Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ class JacksonParser(
// In Spark 1.5.0, we store the data as number of days since epoch in string.
// So, we just convert it to Int.
try {
parser.getText.toInt
RebaseDateTime.rebaseJulianToGregorianDays(parser.getText.toInt)
} catch {
case _: NumberFormatException => throw e
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2653,13 +2653,17 @@ abstract class JsonSuite extends QueryTest with SharedSparkSession with TestJson
}
}

test("SPARK-30960: parse date/timestamp string with legacy format") {
val ds = Seq("{'t': '2020-1-12 3:23:34.12', 'd': '2020-1-12 T', 'd2': '12345'}").toDS()
val json = spark.read.schema("t timestamp, d date, d2 date").json(ds)
test("SPARK-30960, SPARK-31641: parse date/timestamp string with legacy format") {
val julianDay = -141704 // 1582-01-01 in Julian calendar
val ds = Seq(
s"{'t': '2020-1-12 3:23:34.12', 'd': '2020-1-12 T', 'd2': '12345', 'd3': '$julianDay'}"
).toDS()
val json = spark.read.schema("t timestamp, d date, d2 date, d3 date").json(ds)
checkAnswer(json, Row(
Timestamp.valueOf("2020-1-12 3:23:34.12"),
Date.valueOf("2020-1-12"),
Date.valueOf(LocalDate.ofEpochDay(12345))))
Date.valueOf(LocalDate.ofEpochDay(12345)),
Date.valueOf("1582-01-01")))
}

test("exception mode for parsing date/timestamp string") {
Expand Down