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

Feat: Support Interval Type #3416

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

sagarwaal
Copy link

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:

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

Fixes #<issue_number_goes_here> ☕️

If you write sample code, please follow the samples format.

@sagarwaal sagarwaal requested review from a team as code owners October 18, 2024 07:55
@product-auto-label product-auto-label bot added size: xl Pull request size is extra large. api: spanner Issues related to the googleapis/java-spanner API. labels Oct 18, 2024
@sagarwaal sagarwaal changed the title Add support for Interval in Java Client Feat: Support Interval Type Oct 22, 2024
google-cloud-spanner/pom.xml Outdated Show resolved Hide resolved
google-cloud-spanner/pom.xml Show resolved Hide resolved
Comment on lines 72 to 105
/** Returns the nanoseconds component of the interval. */
public BigInteger nanos() {
return BigInteger.valueOf(micros())
.multiply(BigInteger.valueOf(NANOS_PER_MICRO))
.add(BigInteger.valueOf(nanoFractions()));
}
Copy link
Collaborator

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().

Copy link
Author

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.

Comment on lines 175 to 179
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());
}
Copy link
Collaborator

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

Copy link
Author

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.

import com.google.cloud.spanner.AbortedException;
import com.google.cloud.spanner.ResultSet;
import com.google.cloud.spanner.ResultSets;
import com.google.cloud.spanner.*;
Copy link
Collaborator

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)

Copy link
Author

Choose a reason for hiding this comment

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

fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: spanner Issues related to the googleapis/java-spanner API. size: xl Pull request size is extra large.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants