ORC-1671: update timestamp doc in specfication#1867
ORC-1671: update timestamp doc in specfication#1867Jefffrey wants to merge 1 commit intoapache:mainfrom
Conversation
| * Note that if writer timezone is set, 1 January 2015 is according to | ||
| this timezone and not according to UTC |
There was a problem hiding this comment.
IIUC, writer timezone field is mandatory if there is any timestamp type:
orc/java/core/src/java/org/apache/orc/impl/WriterImpl.java
Lines 559 to 565 in 513922a
There was a problem hiding this comment.
Thanks, I think I'll add this to the spec as well (maybe proto too, in the other repo?)
| Due to ORC-763, values before the UNIX epoch which have nanoseconds greater | ||
| than 999,999 are adjusted to have 1 second less. |
There was a problem hiding this comment.
According to
Lines 350 to 352 in 9b79de9
| First we must adjust the DATA value to be relative to the UNIX epoch. The ORC | ||
| epoch is 1 January 2015 00:00:00 US/Pacific, since we must take into account the writer | ||
| timezone. This translates to 1 January 2015 08:00:00 UTC, as US/Pacific is equivalent | ||
| to a -08:00 offset from UTC at that date (no daylight savings). The number of seconds | ||
| from 1 January 1970 00:00:00 UTC to 1 January 2015 08:00:00 UTC is 1,420,099,200. This is | ||
| added to the DATA value to produce a value of -20,751,903. As this is before the | ||
| UNIX epoch (since it is negative), and the SECONDARY value, 199,900,000, is | ||
| greater than 999,999, then this DATA value is adjusted to become -20,751,904 | ||
| (1 second subtracted). | ||
|
|
||
| This value by itself represents 5 May 1969 19:34:56.1999, which now needs to be adjusted | ||
| from US/Pacific (the writer's timezone) to UTC (the reader's timezone). As the value is | ||
| within daylight savings for US/Pacific, 7 hours are subtracted to give the final value | ||
| of 5 May 1969 12:34:56.1999. |
There was a problem hiding this comment.
I'm kinda unclear on how this exactly works, I'm just going off the C++ implementation here:
Lines 335 to 348 in 9b79de9
Happy to be corrected if my understanding or wording is inaccurate anywhere 👍
There was a problem hiding this comment.
Basically here it tries to mimic the behavior on the Java side: https://github.com/apache/orc/blob/main/java/core/src/java/org/apache/orc/impl/TreeReaderFactory.java#L1280-L1295
There was a problem hiding this comment.
Similarly, I'm not inclined to add these details to the specs if we are not 100% sure about it.
| * **Timestamp** is a date and time without a time zone, which does not change based on the time zone of the reader. | ||
| * **Timestamp** is a date and time without a time zone, where the timestamp value is stored in the writer timezone | ||
| encoded at the stripe level, if present. ORC readers will read this value back into the reader's timezone. Usually | ||
| both writer and reader timezones default to UTC, however older ORC files may contain non-UTC writer timezones |
There was a problem hiding this comment.
Usually
both writer and reader timezones default to UTC, however older ORC files may contain non-UTC writer timezones`
The main purpose of this timestamp type is to restore the wall clock time regardless of the reader time zone. IIRC, the Java implementation uses the writer local time zone instead of UTC. Due to insufficient C++ time zone utility support in earlier days, the C++ code by default uses UTC as the writer time zone to avoid complexity.
There was a problem hiding this comment.
I see. I was confused as from the discussion/comments here: apache/arrow#34591
It suggested that the reader's timezone was important when deserializing the values
There was a problem hiding this comment.
IMHO, we'd better not expose the implementation detail here. The original summary and the table below well explains what to expect from users.
There was a problem hiding this comment.
I'm not sure I agree with that, as this timestamp type has been a great source of confusion for me when attempting to implement an ORC to Arrow reader in Rust.
For example, in the test file TestOrcFile.testDate2038.orc, according to PyArrow (which uses the ORC C++ reader underneath), the first value is:
>> from pyarrow import orc
>>> orc.read_table("/home/jeffrey/Code/orc/examples/TestOrcFile.testDate2038.orc")[0][0]
<pyarrow.TimestampScalar: '2038-05-05T12:34:56.100000000'>The underlying integer value for the DATA stream is 736_601_696 seconds (let's ignore nanoseconds). When adding this to 1 Jan 2015 00:00:00, regardless of timezone, we get 5 May 2038 11:34:56. Which seems... surprising.
This isn't at all what I would expect hence my confusion (perhaps I just don't understand properly how DST factors into this). But diving into the internals and seeing reader & writer timezone offsets being considered when decoding the timestamp value just adds to the confusion, especially as that contradicts the specification.
I was hoping to open up some discussion on clarifying the exact definition for this timestamp type as part of this PR.
There was a problem hiding this comment.
Sorry for the late reply. If you find any inconsistent behavior between C++ and Java sides, please refer to the Java implementation as reference. We need to fix any issue on the C++ side.
There was a problem hiding this comment.
I'll try check more into this to confirm my understanding 👍
Moving to draft in the meantime
What changes were proposed in this pull request?
Updating timestamp specification documentation to be more accurate to the implementation.
Why are the changes needed?
Timestamp specification is not clear on some nuances of it's implementation. Pulling knowledge from the following for these updates:
How was this patch tested?
Was this patch authored or co-authored using generative AI tooling?
No