MaxGekk commented on a change in pull request #28345:
URL: https://github.com/apache/spark/pull/28345#discussion_r415364663
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/DateFormatter.scala
##########
@@ -66,7 +66,8 @@ trait LegacyDateFormatter extends DateFormatter {
def formatDate(d: Date): String
override def parse(s: String): Int = {
- val micros = DateTimeUtils.millisToMicros(parseToDate(s).getTime)
+ val julianMicros = DateTimeUtils.millisToMicros(parseToDate(s).getTime)
+ val micros = RebaseDateTime.rebaseJulianToGregorianMicros(julianMicros)
DateTimeUtils.microsToDays(micros)
Review comment:
An alternative approach is to use toJavaDate:
```scala
fromJavaDate(new java.sql.Date(parseToDate(s).getTime))
```
I would guess, it is faster.
##########
File path:
sql/catalyst/src/test/scala/org/apache/spark/sql/util/DateFormatterSuite.scala
##########
@@ -47,45 +48,54 @@ class DateFormatterSuite extends SparkFunSuite with
SQLHelper {
}
test("roundtrip date -> days -> date") {
- Seq(
- "0050-01-01",
- "0953-02-02",
- "1423-03-08",
- "1969-12-31",
- "1972-08-25",
- "1975-09-26",
- "2018-12-12",
- "2038-01-01",
- "5010-11-17").foreach { date =>
- DateTimeTestUtils.outstandingTimezonesIds.foreach { timeZone =>
- withSQLConf(SQLConf.SESSION_LOCAL_TIMEZONE.key -> timeZone) {
- val formatter = DateFormatter(getZoneId(timeZone))
- val days = formatter.parse(date)
- val formatted = formatter.format(days)
- assert(date === formatted)
+ LegacyBehaviorPolicy.values.foreach { parserPolicy =>
+ withSQLConf("spark.sql.legacy.timeParserPolicy" ->
parserPolicy.toString) {
+ Seq(
+ "0050-01-01",
+ "0953-02-02",
+ "1582-10-15",
Review comment:
nit: move 1582 after 1423
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]