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

Geo: Adds a set of no dependency geo classes for JDBC driver #36477

Merged
merged 16 commits into from
Jan 15, 2019

Conversation

imotov
Copy link
Contributor

@imotov imotov commented Dec 11, 2018

This set of geo classes is meant to be used in the JDBC driver to represent geo data and possibly as an intermediate format to pass geo shapes for indexing in #35320.

Relates to #35767 and #35320

nknize and others added 2 commits December 11, 2018 17:15
Removes all math and WKB parser and refactors WKT parser
@imotov imotov added >enhancement :Analytics/Geo Indexing, search aggregations of geo points and shapes v7.0.0 labels Dec 11, 2018
@imotov imotov requested review from nknize and iverase December 11, 2018 13:56
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-analytics-geo

@imotov imotov changed the title Adds a set of no dependency geo classes for JDBC driver Geo: Adds a set of no dependency geo classes for JDBC driver Dec 11, 2018
Copy link
Contributor

@alpar-t alpar-t left a comment

Choose a reason for hiding this comment

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

I'm missing some context here, but left some questions around the build.

}
}

jarHell.enabled = false
Copy link
Contributor

@alpar-t alpar-t Dec 11, 2018

Choose a reason for hiding this comment

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

Why don't we want to check for jar hell ?


testCompile "com.carrotsearch.randomizedtesting:randomizedtesting-runner:${versions.randomizedrunner}"
testCompile "junit:junit:${versions.junit}"
testCompile "org.hamcrest:hamcrest-all:${versions.hamcrest}"
Copy link
Contributor

Choose a reason for hiding this comment

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

Aren't these transitive dependencies of the test framework ?

@alpar-t alpar-t added the :Delivery/Build Build or test infrastructure label Dec 11, 2018
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra

testCompile "junit:junit:${versions.junit}"
testCompile "org.hamcrest:hamcrest-all:${versions.hamcrest}"

if (isEclipse == false || project.path == ":libs:x-content-tests") {
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be :libs:geo-tests which needs to be defined in settings.gradle to keep eclipse happy.

Note to self: We could simplify this setup for the latest Eclipse version (gradle/gradle#4802).

}

dependencies {
compile "org.elasticsearch:elasticsearch-core:${version}"
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this needed ? Couldn't find any code that uses it.

Copy link
Contributor

@alpar-t alpar-t left a comment

Choose a reason for hiding this comment

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

Thanks @imotov this look much better.
Left some more comments, sorry I didn't notice the publishing in the first round.


apply plugin: 'elasticsearch.build'
apply plugin: 'nebula.maven-base-publish'
apply plugin: 'nebula.maven-scm'
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we planning to publish this jar e.x to maven central ?
Note that we'll have to update the release manager in that case.
We should only configure publishing if we do plan to publish 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.

That's a good question. Its content will be shipped as a part of fat jdbc jar for SQL, but it will also used inside elasticsearch itself for geo operations. So that probably means that it needs to be published, correct?

Copy link
Contributor

Choose a reason for hiding this comment

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

That's right, don't forget to add it to release manager.

}

dependencies {
if (isEclipse == false || project.path == ":libs:x-geo-tests") {
Copy link
Contributor

Choose a reason for hiding this comment

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

the project should be :libs:geo-tests and it needs to be created in settings.gradle

@@ -95,6 +95,7 @@ if (isEclipse) {
projects << 'libs:x-content-tests'
projects << 'libs:secure-sm-tests'
projects << 'libs:grok-tests'
projects << 'libs:geo-tests'
Copy link
Contributor

Choose a reason for hiding this comment

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

There's another conditional for eclipse, line 104 that needs to be updated.

Copy link
Contributor

@alpar-t alpar-t left a comment

Choose a reason for hiding this comment

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

Thanks @imotov . One nit, the build LGMT otherwise.

apply plugin: 'nebula.maven-base-publish'
apply plugin: 'nebula.maven-scm'

archivesBaseName = 'elasticsearch-geo'
Copy link
Contributor

Choose a reason for hiding this comment

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

NIT: you could have project(':libs:geo').name = "elasticsearch-geo" in settings.gradle instead of this. That would make the publishing block bellow unnecessary and it has the advantage of showing the module name in the IDE as well.

@imotov
Copy link
Contributor Author

imotov commented Jan 2, 2019

@elasticmachine run gradle build tests 2

@iverase
Copy link
Contributor

iverase commented Jan 8, 2019

Thanks, let's wait for Nick's review before merging

Copy link
Contributor

@nknize nknize left a comment

Choose a reason for hiding this comment

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

LGTM. I left a couple minor comments that I think could be added in a future PR so we don't hold this up any longer. The big thing would be to start moving our random geometry generators to lucene's GeoTestUtil. Lets open a separate issue for that.

/**
* Basic reusable geo-spatial utility methods
*/
public final class GeoUtils {
Copy link
Contributor

Choose a reason for hiding this comment

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

There's also o.e.common.geo.GeoUtils I think we'll want to figure out how to best reconcile the two so that there aren't duplicate GeoUtils in two different packages.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree. I renamed it to GeometryUtils when I made changed its visibility.

package org.elasticsearch.geo.geometry;

/**
* Support class for creating of geometry Visitors
Copy link
Contributor

Choose a reason for hiding this comment

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

Lets add some good javadocs here to clearly explain the design concept.

return new Point(randomLat(), randomLon());
}

public static LinearRing randomLinearRing() {
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 we should reuse lucene's GeoTestUtil for creating these random geometries. There was a lot of work put in to making sure the test suite creates adversarial geometries that have a tendency to expose weaknesses in the API. I don't think that should hold up the PR, though. So lets create a separate issue to migrate some of the random geometry generators over to lucene's geo test suite.

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 opened #37278 as a follow-up.

import org.elasticsearch.geo.utils.WellKnownText;
import org.elasticsearch.test.ESTestCase;

public class LinearRingTests extends ESTestCase {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is it not extending the BaseGeometryTestCase ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah Ignore... I see it's not supported by WKT...

this.maxLat = maxLat;
empty = false;
if (maxLat < minLat) {
throw new IllegalArgumentException("max lat cannot be less than min lat");
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't be a check for minLon maxLon as well?

Copy link
Contributor

Choose a reason for hiding this comment

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

Nope, it is perfectly valid to have minLon > maxLon, it just means that the Rectangle crosses the dateline.

package org.elasticsearch.geo.geometry;

/**
* Support class for creating of geometry Visitors.
Copy link
Contributor

Choose a reason for hiding this comment

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

you could remove of.

public class LinearRing extends Line {
public static final LinearRing EMPTY = new LinearRing();


Copy link
Contributor

Choose a reason for hiding this comment

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

Minor: you could remove this empty line.



private LinearRing() {

Copy link
Contributor

Choose a reason for hiding this comment

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

same here.

public static final MultiLine EMPTY = new MultiLine();

private MultiLine() {

Copy link
Contributor

Choose a reason for hiding this comment

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

same here.

public static final MultiPolygon EMPTY = new MultiPolygon();

private MultiPolygon() {

Copy link
Contributor

Choose a reason for hiding this comment

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

and here.

tokenizer.wordChars('-', '-');
tokenizer.wordChars('+', '+');
tokenizer.wordChars('.', '.');
tokenizer.whitespaceChars(0, ' ');
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is 0 a whitespaceChar ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not only 0. Basically this line means that everything between 0 and will be treated as a whitespace character. This is to ignore all control characters below space including new line, line feed, tabs, new page etc. by treating it as a whitespace character. I have decided to leave it as is instead of configuring each a subset of character manually since this is the default behavior of StreamTokenizer, but we can be more restrictive here and allow only spaces, tabs and line feeds as suggested in the standard @iverase, @nknize what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

The standard seems to only allow spaces, tabs or line feeds to improve readability so let's do as recommended.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you!

@imotov
Copy link
Contributor Author

imotov commented Jan 11, 2019

@matriv I pushed the changes that you have requested. Could you take another look?

Copy link
Contributor

@matriv matriv left a comment

Choose a reason for hiding this comment

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

LGTM. Thank you for your patience.

@imotov imotov merged commit 6f91f06 into elastic:master Jan 15, 2019
@karussell
Copy link

I'm curious why not use JTS instead? (BSD-like license, actively maintained, solid implementation, wide spread adoption, without dependencies, ...)

@karussell
Copy link

Sorry, looks like this is answered in #35767:

JTS Geometry. This is what H2 is currently using. One problem with this solution is that we will have to require or ship JTS library and we will not be able to release GEOSQL until H2GIS 1.5.0 is released. We are using H2GIS for testing it and it is still using JTS 1.14 at the moment, the rest of ES is using JTS 1.15. So, if we cannot ship JDBC with JTS 1.14, but we cannot test it with JTS 1.15

@imotov imotov deleted the issue-35767-libs-geo branch May 1, 2020 22:18
@mark-vieira mark-vieira added the Team:Delivery Meta label for Delivery team label Nov 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Analytics/Geo Indexing, search aggregations of geo points and shapes :Delivery/Build Build or test infrastructure >enhancement Team:Delivery Meta label for Delivery team v7.0.0-beta1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants