Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ORC-306 Correct pre-1970 timestamps that were off by one second. #220

Closed
wants to merge 1 commit into from

Conversation

omalley
Copy link
Contributor

@omalley omalley commented Feb 27, 2018

No description provided.

Fixes apache#220

Signed-off-by: Owen O'Malley <omalley@apache.org>
@omalley
Copy link
Contributor Author

omalley commented Feb 27, 2018

So the fix detects whether the Timestamp class has the bug or not and then either compensates or doesn't. It also ensures that the TimestampColumnVector.time values are set correctly with the milliseconds on the bottom.

The test does more now. First of all, instead of going from 56.1000 to 56.1999 seconds incrementing by 0.0001, which doesn't reveal the bug, it goes from 56.0000 to 56.1999 seconds incrementing by 0.0002. It also checks the values from the TimestampColumnVector rather than comparing using Timestamp.

@@ -49,6 +50,15 @@
* Factory for creating ORC tree readers.
*/
public class TreeReaderFactory {
// The current JDK has a bug where values of the form:
// YYYY-MM-DD HH:MM:SS.000X is off by a second for dates before 1970.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please link the BUG # for future reference (can be done on commit)?
Also can we run the tests against JDK version with the bug on travis CI to trigger TIMSTAMP_BUG == true code path? The logic for adjusting millis look good to me.

Timestamp ts1 = Timestamp.valueOf("1969-12-25 12:34:56.0001");
Timestamp ts2 = Timestamp.valueOf("1969-12-25 12:34:56.0011");
// Compare the seconds, which should be the same.
TIMESTAMP_BUG = ts1.getTime()/1000 != ts2.getTime()/1000;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in this case getSeconds() would return the same but millis would have changed as ts2 added a whole new millisecond to the time. isn't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getTime() returns the milliseconds after 1970-01-01 00:00:00. So getTime()/1000 should return the seconds, which should be the same.

@omalley
Copy link
Contributor Author

omalley commented Feb 28, 2018

Here is another way to look at the problem with each timestamp's getTime() and getNanos():

Timestamp 1969-12-25 12:34:56.0 as -530704000 and 0
Timestamp 1969-12-25 12:34:56.0001 as -530704000 and 100000
Timestamp 1969-12-25 12:34:56.0011 as -530703999 and 1100000

When we use getTime()/1000 the change happens between .000999999 and .001000000.

If you don't think that Java will change, we could hard code the change to use 999_999 all of the time and not do the test.

@asfgit asfgit closed this in 9c105b9 Mar 2, 2018
asfgit pushed a commit that referenced this pull request Mar 20, 2018
Fixes #220

Signed-off-by: Owen O'Malley <omalley@apache.org>
mustafaiman pushed a commit to mustafaiman/orc that referenced this pull request Nov 18, 2019
Fixes apache#220

Signed-off-by: Owen O'Malley <omalley@apache.org>
(cherry picked from commit 6c4865a)
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>

Change-Id: I60e96cff5e459458065bc5419bc9d4b01da955d7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants