-
Notifications
You must be signed in to change notification settings - Fork 118
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
Feat: Support Interval Type #3416
base: main
Are you sure you want to change the base?
Conversation
5733d5f
to
3f5bd80
Compare
3f5bd80
to
df6ebe7
Compare
d366c1c
to
f9517a0
Compare
f9517a0
to
f16ae42
Compare
google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITIntervalTest.java
Show resolved
Hide resolved
c201180
to
2b50235
Compare
bea6426
to
b136a58
Compare
google-cloud-spanner/src/main/java/com/google/cloud/spanner/GrpcStruct.java
Show resolved
Hide resolved
google-cloud-spanner/src/main/java/com/google/cloud/spanner/Interval.java
Outdated
Show resolved
Hide resolved
/** Returns the nanoseconds component of the interval. */ | ||
public BigInteger nanos() { | ||
return BigInteger.valueOf(micros()) | ||
.multiply(BigInteger.valueOf(NANOS_PER_MICRO)) | ||
.add(BigInteger.valueOf(nanoFractions())); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this just return the nano fraction? (and then also be renamed?)
Currently, it seems that this method does the exact same as getAsNanos()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nanoFractions() function returns fractional part of microseconds which is in range [-999, 999].
nanos() returns microsecond and nanoFractions() combined.
getAsNanos() returns all the components of Interval - months, days and nanos() combined as nanoseconds.
google-cloud-spanner/src/test/java/com/google/cloud/spanner/IntervalTest.java
Outdated
Show resolved
Hide resolved
public void testEquals() { | ||
Interval interval1 = Interval.fromMonthsDaysMicros(10, 20, 30); | ||
Interval interval2 = Interval.fromMonthsDaysMicros(10, 20, 30); | ||
assertEquals(interval1, interval2); | ||
} | ||
|
||
@Test | ||
public void testHashCode() { | ||
Interval interval1 = Interval.fromMonthsDaysMicros(10, 20, 30); | ||
Interval interval2 = Interval.fromMonthsDaysMicros(10, 20, 30); | ||
assertEquals(interval1.hashCode(), interval2.hashCode()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should cover more variations, and also include verifications for non-equality
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated tests for Equality and HashCode.
google-cloud-spanner/src/test/java/com/google/cloud/spanner/RandomResultSetGenerator.java
Outdated
Show resolved
Hide resolved
import com.google.cloud.spanner.AbortedException; | ||
import com.google.cloud.spanner.ResultSet; | ||
import com.google.cloud.spanner.ResultSets; | ||
import com.google.cloud.spanner.*; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Google code style forbids the use of wildcard imports (https://google.github.io/styleguide/javaguide.html#s3.3.1-wildcard-imports)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.
google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITQueryTest.java
Outdated
Show resolved
Hide resolved
b136a58
to
41b396c
Compare
41b396c
to
f9e6383
Compare
Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:
Fixes #<issue_number_goes_here> ☕️
If you write sample code, please follow the samples format.