Uh oh!
There was an error while loading. Please reload this page.
[SPARK-26002][SQL] Fix day of year calculation for Julian calendar days - #23000
[SPARK-26002][SQL] Fix day of year calculation for Julian calendar days#23000attilapiros wants to merge 3 commits into
Conversation
SparkQA
commented
Nov 10, 2018
Test build #98682 has finished for PR 23000 at commit
|
attilapiros
commented
Nov 15, 2018
ping @10110346@gatorsmile |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
squito
commented
Nov 20, 2018
lgtm |
SparkQA
commented
Nov 20, 2018
Test build #99054 has finished for PR 23000 at commit
|
dongjoon-hyun
commented
Dec 17, 2018
Retest this please. |
SparkQA
commented
Dec 17, 2018
Test build #100216 has finished for PR 23000 at commit
|
dongjoon-hyun
commented
Dec 17, 2018
cc @cloud-fan , @gatorsmile , @mgaido91 |
Uh oh!
There was an error while loading. Please reload this page.
cloud-fan
commented
Dec 18, 2018
what was the behavior before this PR? |
@cloud-fan It was off by one (at least at 1500, with each 100 years back in time the difference increases) as I described in the Jira: |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
gatorsmile
commented
Dec 29, 2018
cc @MaxGekk who is touching this |
@gatorsmile Thanx for the ping. Actually current implementation support Proleptic Gregorian calendar even if it is not documented explicitly. Recently we switched on this chronology for parsing/formatting date/timestamps in JSON/CSV datasource (see #23150 and #23196) and in functions (see #23358). If we support the hybrid calendar (Julian + Gregorian) here, it will introduce additional inconsistency. @attilapiros If you need the hybrid calendar for some reasons, you should extend the |
MaxGekk
left a comment
There was a problem hiding this comment.
Just in case, SQL standard counts dates exclusively in the Gregorian calendar, even for years before that calendar was in use.
attilapiros
commented
Jan 2, 2019
@MaxGekk thanks for the explanation, but I still a bit uncertain. My main intention was about correcting the dayOfYear/month/year operators as the result in the following example are very strange (and not consistent with PostgreSQL too): Running the corresponding expressions in PostgreSQL 9.6: Is there any other DBMS I can take as a reference? |
MaxGekk
commented
Jan 2, 2019
I see, we still use hybrid calendar in casting by using java.time API based on Proleptic Gregorian Calendar but such changes look like more heavy. I would guess they will be done to follow SQL standard in the end, so, your fix for Julian calendar will be not needed. At the moment, I agree we need your fix to handle results from stringToTimestamp properly. |
attilapiros
commented
Jan 2, 2019
Ok. Then tomorrow I will add the requested tests and we can progress with this PR. |
SparkQA
commented
Jan 3, 2019
Test build #100692 has finished for PR 23000 at commit
|
attilapiros
commented
Jan 8, 2019
gentle ping @dongjoon-hyun, @cloud-fan, @gatorsmile |
cloud-fan
commented
Jan 8, 2019
thanks, merging to master! |
## What changes were proposed in this pull request?
Fixing leap year calculations for date operators (year/month/dayOfYear) where the Julian calendars are used (before 1582-10-04). In a Julian calendar every years which are multiples of 4 are leap years (there is no extra exception for years multiples of 100).
## How was this patch tested?
With a unit test ("SPARK-26002: correct day of year calculations for Julian calendar years") which focuses to these corner cases.
Manually:
```
scala> sql("select year('1500-01-01')").show()
+------------------------------+
|year(CAST(1500-01-01 AS DATE))|
+------------------------------+
| 1500|
+------------------------------+
scala> sql("select dayOfYear('1100-01-01')").show()
+-----------------------------------+
|dayofyear(CAST(1100-01-01 AS DATE))|
+-----------------------------------+
| 1|
+-----------------------------------+
```
Closesapache#23000 from attilapiros/julianOffByDays.
Authored-by: “attilapiros” <piros.attila.zsolt@gmail.com>
Signed-off-by: Wenchen Fan <wenchen@databricks.com>
What changes were proposed in this pull request?
Fixing leap year calculations for date operators (year/month/dayOfYear) where the Julian calendars are used (before 1582-10-04). In a Julian calendar every years which are multiples of 4 are leap years (there is no extra exception for years multiples of 100).
How was this patch tested?
With a unit test ("SPARK-26002: correct day of year calculations for Julian calendar years") which focuses to these corner cases.
Manually: