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

SQL: Add ST_X, ST_Y and ST_GEOMETRY_TYPE functions #41104

Merged
merged 5 commits into from
Apr 22, 2019

Conversation

imotov
Copy link
Contributor

@imotov imotov commented Apr 11, 2019

Adds 3 new geosql functions. The ST_Z functions as well as ST_X and
ST_Y functions for polygons are not supported because of the issues
described in #40908. This support will be added as soon as the
ShapeBuilder issues are resolved.

Relates to #29872

Adds 3 new geosql functions. The ST_Z functions as well as ST_X and
ST_Y functions for polygons are not supported because of the issues
described in elastic#40908. The suppor will be added as soon as the
ShapeBuilder issues are resolved.

Relates to elastic#29872
@imotov imotov added >enhancement :Analytics/Geo Indexing, search aggregations of geo points and shapes :Analytics/SQL SQL querying v8.0.0 labels Apr 11, 2019
@imotov imotov requested review from costin, astefan and matriv April 11, 2019 08:34
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-analytics-geo

@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search

Copy link
Contributor

@astefan astefan left a comment

Choose a reason for hiding this comment

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

In general LGTM. I've added some comments especially related to tests.
Also, I think more tests are needed in QueryTranslatorTests to check the correct query is created for these newly added functions.


.Description:

Returns the type of the `geometry` such as "Point", "Polygon", "MultiPolygon", etc.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you list all of the possibilities (if they are not many), or provide a link to a list of types?


["source","sql",subs="attributes,macros"]
--------------------------------------------------
include-tagged::{sql-specs}/geo/docs.csv-spec[geometrytype]
Copy link
Contributor

Choose a reason for hiding this comment

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

At the moment, on master, the docs tests and samples go into a /docs/docs.csv-spec. Any chance this will go there when the merge with master happens? Or maybe put the geo ones inside a /docs/docs.csv-spec file, so that you don't forget at merging time?

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe it makes sense to have them under /docs/geo.csv-spec but be sure that the file is picked up from our testing framework.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@costin asked me earlier to separate geo-related things into a separate directory as much as possible. I am just following this suggestion. I think moving it into /docs/geo.csv-spec might be a good compromise here.

@@ -137,6 +137,9 @@
* <<sql-functions-geo>>
** <<sql-functions-geo-st-as-wkt>>
** <<sql-functions-geo-st-wkt-to-sql>>
** <<sql-functions-geo-st-geometrytype>>
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 this one has to go before wkt-to-sql? (they should be listed alphabetically for ease of browsing)

@@ -214,3 +214,55 @@ SELECT ST_Distance(ST_WktToSql(NULL), ST_WktToSQL('POINT (-71 42)')) shape;
shape:d
null
;

groupByGeometryType
SELECT COUNT(*) cnt, ST_GeometryType(location) gt FROM geo GROUP BY ST_GeometryType(location);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you also add a test where the alias gt is used as GROUP BY and ORDER BY?

selectFilterByXOfLocation
SELECT city, ST_X(shape) x, ST_Y(shape) y FROM geo WHERE ST_X(location) > 0 ORDER BY ST_Y(location);

city:s | x:d | y:d
Copy link
Contributor

Choose a reason for hiding this comment

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

In this query I would also add as returned columns ST_X(location) and ST_Y(location) just to be easier to double check the results' correctness.

selectFilterByRegionPoint
SELECT city, region FROM geo WHERE ST_X(ST_WKTTOSQL(region_point)) < 0 ORDER BY ST_X(location);

city:s | region:s
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: I would add ST_X(location) in the returned results to double check the correctness of the results.

ASWKT(GeoShape::toString),
X(GeoShape::getX),
Y(GeoShape::getY),
GEOMETRY_TYPE(GeoShape::getGeometryType);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you put this one second in line, please? (considering an alphabetic ordering)


public Double getX() {
Point firstPoint = firstPoint();
if (firstPoint != null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

All this logic could be re-written in a more compact way as return firstPoint != null ? firstPoint.getLon() : null;


public Double getY() {
Point firstPoint = firstPoint();
if (firstPoint != null) {
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 about a more compact way of returning a value.

@@ -150,6 +150,9 @@ class org.elasticsearch.xpack.sql.expression.function.scalar.whitelist.InternalS
String stAswkt(Object)
GeoShape stWktToSql(String)
Copy link
Contributor

Choose a reason for hiding this comment

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

I would order these alphabetically withing the "geo" section.


@Override
public Point visit(MultiLine multiLine) {
return visit((GeometryCollection<?>) multiLine);
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 here and below the cast is unnecessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Without this cast it will go into an infinite loop.

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.

Looks good overall, added also some comments.

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

Copy link
Contributor

@astefan astefan left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@costin costin left a comment

Choose a reason for hiding this comment

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

LGTM

@imotov
Copy link
Contributor Author

imotov commented Apr 15, 2019

@elasticmachine run elasticsearch-ci/1

@imotov imotov merged commit dd07273 into elastic:geosql Apr 22, 2019
@imotov imotov removed the v8.0.0 label Apr 24, 2019
@imotov imotov deleted the geosql-st-xy branch May 1, 2020 22:12
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 :Analytics/SQL SQL querying >enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants