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

Change TimeValue back to nanosPerDayUTC #11330

Merged
merged 4 commits into from Mar 23, 2018
Merged

Change TimeValue back to nanosPerDayUTC #11330

merged 4 commits into from Mar 23, 2018

Conversation

fickludd
Copy link
Contributor

@fickludd fickludd commented Mar 21, 2018

This is different from the first implementation though, in that it stores
nanosPerDayUTC in the range -18h to +42h instead of wrapping around to the
next day. This makes the on-disc format directly semantically comparable,
which will be useful if we do predicate push-down in the future.

{
packStructHeader( 2, TIME );
pack( nanosOfDayLocal );
pack( TimeConstants.asValidLocalTime( nanosOfDayUTC ) );
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe this will change the serialized format to be the UTC local time, correct?
Is that really what we want for the BOLT format? I have a feeling that it might be easier for clients if we sent the localtime within the particular offset.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, and when I changed it from UTC to local the first time I broke it too. Was trying to revert that brake, and have communicated with the driver team about it.

In Drivers they're not sure what it the best format to get, as temporal support in a the driver languages is very different. I think they need to find out what works best, and then change this to what they really want. In short, they're on top on it.

But to cause the least chaos, I changed this PR to not change the serialization. It's probably easier if they do everything from now, and I keep my hand off :).

@thobe
Copy link
Contributor

thobe commented Mar 21, 2018

There is a test failure that looks related. In: QueryResultsSerializationTest.shouldFailIfTryingToReturnPropsOfDeletedRelationshipRest

@fickludd
Copy link
Contributor Author

fickludd commented Mar 22, 2018

The QueryResultsSerializationTest does not touch temporals, so it's just flaky. Should be fixed by someone at some point.

@SuppressWarnings( "WeakerAccess" )
public class TimeConstants
{
public static final long NANOS_PER_SECOND = 1_000_000_000L;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are the ones that do fit in an int still defined as a long, requiring casting elsewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Leaving NANOS_PER_SECOND as an int gives some interesting overflow problems if you multiply it with another int, e.g. offsetSeconds. I find these problems much harder to detect, than it is annoying to down-cast to int in the 1 place where that is required. Thus this.

{
}

public static long asValidLocalTime( long nanosPerDayUTC )
Copy link
Contributor

Choose a reason for hiding this comment

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

I find this method confusing. It sounds like it converts UTC to localtime, but it only makes sure to convert a long representing any time from [-18,+42] to [0,24] instead.

Also, the parameter nanosPerDayUTC should maybe just be nanos ?

@@ -246,7 +247,7 @@ private TimeValue unpackTime() throws IOException
{
long nanosOfDayUTC = unpackLong();
int offsetSeconds = unpackInteger();
return time( nanosOfDayUTC, ZoneOffset.ofTotalSeconds( offsetSeconds ) );
return time( nanosOfDayUTC - offsetSeconds * NANOS_PER_SECOND, ZoneOffset.ofTotalSeconds( offsetSeconds ) );
Copy link
Contributor

@lutovich lutovich Mar 22, 2018

Choose a reason for hiding this comment

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

Why is conversion needed here?
I think bolt server should both send and receive local time with offset. Thus conversion is probably only needed in #writeTime() because database stores UTC.

Update: please nvm, I misunderstood the code.

{
packStructHeader( 2, TIME );
pack( nanosOfDayLocal );
pack( nanosOfDayUTC + offsetSeconds * NANOS_PER_SECOND );
Copy link
Contributor

Choose a reason for hiding this comment

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

Would be nice to extract this conversion in a helper method because it's repeated in couple places

import static java.time.temporal.ChronoUnit.DAYS;

@SuppressWarnings( "WeakerAccess" )
public class TimeConstants
Copy link
Contributor

Choose a reason for hiding this comment

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

This class also contains a method, so Constants suffix feels strange. Maybe TimeUtil?

This is different from the first implementation though, in that it stores
nanosPerDayUTC in the range -18h to +42h instead of wrapping around to the
next day. This makes the on-disc format directly semantically comparable,
which will be useful if we do predicate push-down in the future.
@sherfert sherfert merged commit 2887607 into neo4j:3.4 Mar 23, 2018
@fickludd fickludd deleted the 3.4-time-value-in-UTC-again branch May 16, 2018 08:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants