MaxGekk opened a new pull request #28824:
URL: https://github.com/apache/spark/pull/28824
### What changes were proposed in this pull request?
1. Set the given time zone as the first parameter of
`RebaseDateTime`.`rebaseJulianToGregorianMicros()` and
`rebaseGregorianToJulianMicros()` to Java 7 `GregorianCalendar`.
```scala
val cal = new Calendar.Builder()
// `gregory` is a hybrid calendar that supports both the Julian and
Gregorian calendar systems
.setCalendarType("gregory")
...
.setTimeZone(tz)
.build()
```
This makes the instance of the calendar independent from the default JVM
time zone.
2. Change type of the first parameter from `ZoneId` to `TimeZone`. This
allows to avoid unnecessary conversion from `TimeZone` to `ZoneId`, for example
in
```scala
def rebaseJulianToGregorianMicros(micros: Long): Long = {
...
if (rebaseRecord == null || micros < rebaseRecord.switches(0)) {
rebaseJulianToGregorianMicros(timeZone.toZoneId, micros)
```
and back to `TimeZone` inside of `rebaseJulianToGregorianMicros(zoneId:
ZoneId, ...)`
3. Modify tests in `RebaseDateTimeSuite`, and set the default JVM time zone
only for functions that depend on it.
### Why are the changes needed?
1. Ignoring passed parameter and use a global variable is bad practice.
2. Dependency from the global state doesn't allow to run the function in
parallel otherwise there is non-zero probability that the function may return
wrong result if the default JVM is changed during their execution.
3. This open opportunity for parallelisation of JSON files generation
`gregorian-julian-rebase-micros.json` and
`julian-gregorian-rebase-micros.json`. Currently, the tests `generate
'gregorian-julian-rebase-micros.json'` and `generate
'julian-gregorian-rebase-micros.json'` generates the JSON files by iterating
over all time zones sequentially w/ step of 1 week. Due to the large step, we
can miss some spikes in diffs between 2 calendars (Java 8 Gregorian and Java 7
hybrid calendars) as the PR https://github.com/apache/spark/pull/28787 fixed.
### Does this PR introduce _any_ user-facing change?
No
### How was this patch tested?
By running existing tests from `RebaseDateTimeSuite`.
----------------------------------------------------------------
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]