Skip to content

Add support for point type #283

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

Merged
merged 1 commit into from
Jun 16, 2020
Merged

Conversation

avinash-anand
Copy link
Contributor

@avinash-anand avinash-anand commented May 23, 2020

Make sure that:

  • You have read the contribution guidelines.
  • You have created a feature request first to discuss your contribution intent. Please reference the feature request ticket number in the pull request.
  • You use the code formatters provided here and have them applied to your changes. Don't submit any formatting related changes.
  • You submit test cases (unit or integration tests) that back your changes.

Issue description

related to issue previously opened support for geometric types - #282

New Public APIs

Additional context

@pivotal-issuemaster
Copy link

@avinash-anand Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.

@pivotal-issuemaster
Copy link

@avinash-anand Thank you for signing the Contributor License Agreement!

@Squiry
Copy link
Collaborator

Squiry commented May 23, 2020

  1. If you want driver to know about your codec you should add it to DefaultCodecs.
  2. There are integration test of builtin types in AbstractCodecIntegrationTests, you should add one for point. Probably this will force you to support FORMAT_TEXT.

Are you going to add support for other geometric types here too?

* <p>This implements a version of java.awt.Point, except it uses double to represent the coordinates.</p>
*/
public class Point {
public double x;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we really need this to be mutable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I referred PGpoint of pgjdbc. there it is mentioned as public. I think that perhaps it represents a 2D-point, hence, instead of adding both getters & setters, this value is made mutable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can make it private and generate a getter/setter for it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Those should be rather immutable fields (private final without setters). Thinking of values as atomic and immutable value types is useful as a single point (and future geo types) cannot be changed partially but each update to a point requires a new value object instance.

double x = Double.parseDouble(coordinatesAsString[0]);
double y = Double.parseDouble(coordinatesAsString[1]);
return new Point(x, y);
} catch (NumberFormatException | NullPointerException | ArrayIndexOutOfBoundsException e) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

We don't catch NumberFormatException in Numeric codecs and catching NullPointerException and ArrayIndexOutOfBoundsException looks kind of weird.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually NumberFormatException was caught in pgjdbc, i thought, the same should be done here as well. Also, these other exceptions were also possible if we receive invalid data, hence caught these exceptions. I can remove it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

What @Squiry said. Let's see whether we have a need for handling such cases at all.

@avinash-anand
Copy link
Contributor Author

  1. If you want driver to know about your codec you should add it to DefaultCodecs.

Sorry, my bad. I'll do it.

  1. There are integration test of builtin types in AbstractCodecIntegrationTests, you should add one for point. Probably this will force you to support FORMAT_TEXT.

Sure. I'll add this test. In pgjdbc, it was marked as binary, hence i forced binary format.

Are you going to add support for other geometric types here too?

Yes, I will add for line and polygon as well. Actually, I started with Point as it was small and simple.

Also, could you please let me know what steps I need to follow to run mvn clean verify locally. On my machine, I got some error. Hence, I ran single test from IDE.

@avinash-anand
Copy link
Contributor Author

@Squiry , @mp911de - There is one issue when i was trying to implement point_array codec and the abstract-array-codec splits incoming data with comma as delimiter. since point is represented as (x,y), it is splitting at wrong place. we may have to look into this as well.

* @param x integer amount to add on the x axis
* @param y integer amount to add on the y axis
*/
public void translate(int x, int y) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Those mutation-like methods should return a new instance of Point. Applying mutation to objects always opens up paths for potential bugs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These methods were present in original driver, so I added it as it is. Do you think these methods should be part of this class now or should I remove them?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Using PGJDBC as a starting point is fine. With the introduction of geo-types to r2dbc-postgressql, we have a chance to improve the actual design. Let's keep these methods in the type but change these to return a new instance.

* @param p Point to move to
* @see java.awt.Point
*/
public void setLocation(java.awt.Point p) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should not use AWT at all.

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, I was thinking the same. I'll remove this.

@mp911de mp911de self-assigned this May 28, 2020
@mp911de mp911de modified the milestone: 0.8.3.RELEASE May 28, 2020
@mp911de
Copy link
Collaborator

mp911de commented May 28, 2020

There are a few issues, though:

  • Binary parsing uses 8-byte float representation (see Double.doubleToRawLongBits(…))
  • Running the tests fails with [08P01] insufficient data left in message))
  • Some files miss license headers

@avinash-anand
Copy link
Contributor Author

There are a few issues, though:

  • Binary parsing uses 8-byte float representation (see Double.doubleToRawLongBits(…))
  • Running the tests fails with [08P01] insufficient data left in message))

I'll try to fix this today.

  • Some files miss license headers

I'll fix this today.

@avinash-anand
Copy link
Contributor Author

@mp911de - I have fixed the test and updated the files with license. Thanks for pointing out the errors. For some reason, in my local machine - mvn clean verify isn't able to run. I always get below error:-
org.apache.maven.surefire.booter.SurefireBooterForkException: There was an error in the forked process. I can individually run test files in IDE.

Please let me know if anymore changes are needed.

@avinash-anand
Copy link
Contributor Author

@mp911de - Please let me know if this PR is eligible for merging or it needs some changes?

@mp911de
Copy link
Collaborator

mp911de commented Jun 3, 2020

Let me come back by next week to you.

@avinash-anand
Copy link
Contributor Author

Let me come back by next week to you.

@mp911de - Let me know if now is a good time to review this PR?

@mp911de
Copy link
Collaborator

mp911de commented Jun 16, 2020

The code looks good. We will polish up the remaining issues during the merge. Can you please rebase your code, squash all commits into a single commit, and force-push your branch?

@mp911de mp911de added the type: enhancement A general enhancement label Jun 16, 2020
@mp911de mp911de added this to the 0.8.4.RELEASE milestone Jun 16, 2020
@mp911de mp911de changed the title feature: adding support for point type Add support for point type Jun 16, 2020
@avinash-anand
Copy link
Contributor Author

@mp911de - done.

mp911de pushed a commit that referenced this pull request Jun 16, 2020
mp911de added a commit that referenced this pull request Jun 16, 2020
Make Point final and reduce PointCodec visibility. Introduce factory method for Point type. Update documentation.

[resolves #283][#282]
@mp911de mp911de merged commit 69d1258 into pgjdbc:master Jun 16, 2020
@mp911de
Copy link
Collaborator

mp911de commented Jun 16, 2020

Thank you for your contribution. That's merged, polished, and backported now.

@avinash-anand avinash-anand deleted the issue-282-point branch June 16, 2020 10:46
avinash-anand pushed a commit to avinash-anand/r2dbc-postgresql that referenced this pull request Jul 25, 2020
Make Point final and reduce PointCodec visibility. Introduce factory method for Point type. Update documentation.

[resolves pgjdbc#283][pgjdbc#282]
avinash-anand pushed a commit to avinash-anand/r2dbc-postgresql that referenced this pull request Jul 25, 2020
Make Point final and reduce PointCodec visibility. Introduce factory method for Point type. Update documentation.

[resolves pgjdbc#283][pgjdbc#282]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants