yaooqinn opened a new pull request #28674:
URL: https://github.com/apache/spark/pull/28674
### What changes were proposed in this pull request?
In 3.0, the new approach in datetime parser can not extract the
week-based-year field, so it goes
idempotently to 1970.
```sql
spark-sql> explain select to_timestamp('1969-01-01', 'YYYY-MM-dd');
== Physical Plan ==
*(1) Project [-28800000000 AS to_timestamp(1969-01-01, YYYY-MM-dd)#37]
+- *(1) Scan OneRowRelation[]
== Physical Plan ==
*(1) Project [-28800000000 AS to_timestamp(2000-01-01, YYYY-MM-dd)#73]
+- *(1) Scan OneRowRelation[]
```
In Legacy mode a.k.a version 2.4, the result will be the last Sunday of the
past year(It is weird too!)
```sql
spark-sql> select to_timestamp('1969-01-01', 'YYYY-MM-dd');
1968-12-29 00:00:00
spark-sql> select to_timestamp('1969-01-02', 'YYYY-MM-dd');
1968-12-29 00:00:00
spark-sql> select to_timestamp('1969-01-03', 'YYYY-MM-dd');
1968-12-29 00:00:00
spark-sql> select to_timestamp('1969-01-04', 'YYYY-MM-dd');
1968-12-29 00:00:00
spark-sql> select to_timestamp('1969-01-05', 'YYYY-MM-dd');
1968-12-29 00:00:00
spark-sql> select to_timestamp('1969-01-06', 'YYYY-MM-dd');
1968-12-29 00:00:00
spark-sql> select to_timestamp('1969-01-07', 'YYYY-MM-dd');
1968-12-29 00:00:00
spark-sql> select to_timestamp('1969-01-31', 'YYYY-MM-dd');
1968-12-29 00:00:00
spark-sql> select to_timestamp('1969-02-28', 'YYYY-MM-dd');
1968-12-29 00:00:00
spark-sql> select to_timestamp('1969-12-28', 'YYYY-MM-dd');
1968-12-29 00:00:00
spark-sql> select to_timestamp('1969-12-31', 'YYYY-MM-dd');
1968-12-29 00:00:00
```
In this PR, I propose to restore the behavior in 2.4 before we have final
conclusion and do not block releasing 3.0. Since in 3.0 it is much weirder.
FYI, Postgres may set a good example here,
https://www.postgresql.org/docs/9.0/functions-formatting.html
> Caution
--
While to_date will reject a mixture of Gregorian and ISO week-numbering date
fields, to_char will not, since output format specifications like YYYY-MM-DD
(IYYY-IDDD) can be useful. But avoid writing something like IYYY-MM-DD; that
would yield surprising results near the start of the year.
### Why are the changes needed?
bugfix and behavior change restoration
### Does this PR introduce _any_ user-facing change?
No, the behavior will be restored.
### How was this patch tested?
<!--
If tests were added, say they were added here. Please make sure to add some
test cases that check the changes thoroughly including negative and positive
cases if possible.
If it was tested in a way different from regular unit tests, please clarify
how you tested step by step, ideally copy and paste-able, so that other
reviewers can test and check, and descendants can verify in the future.
If tests were not added, please describe why they were not added and/or why
it was difficult to add.
-->
added new tests
----------------------------------------------------------------
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]