-
Notifications
You must be signed in to change notification settings - Fork 590
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
[MapD] Add geo spatial datatype support #1666
Conversation
|
I am moving the geospatial types to it own file. now I have a question. what would be the workflow for this implementation? |
|
I moved the geospatial types to it own file. now I have a question. what would be the workflow for this implementation? |
|
@cpcloud @kszucs we decide to remove the dependence of shapely for now, so I moved back again geo spatial data type from geospatial.py to datatype.py and I removed geospatial.py just testing the new data types it seems it is working. but It seems I am missing something related to inference ... could you provide any help? thanks! |
|
@xmnlab Try removing the infer functions above. |
|
@kszucs thanks for the feedback! with out infer function, it raises an error: |
|
I could resolve the problem here:
let me know if this is reasonable or if you prefer another approach. |
|
That sounds good! |
|
@kszucs it seems all tests passed except for azure (mysql installation issue) and python27 (sqlite issues) do you have any idea how to fixed that? |
|
MySQL testing has been disabled on the master. I'm rebasing it. |
5564df6
to
b6c991c
Compare
Codecov Report
@@ Coverage Diff @@
## master #1666 +/- ##
=========================================
- Coverage 89.97% 87.4% -2.57%
=========================================
Files 186 186
Lines 27300 27486 +186
Branches 2311 2344 +33
=========================================
- Hits 24563 24024 -539
- Misses 2335 3050 +715
- Partials 402 412 +10
|
|
Thanks @kszucs !! It seems awesome! |
|
@xmnlab @cpcloud In overall the new datatypes are working, however We'll need a couple of follow-up PRs. The current implementation doesn't reflect the hierarchy between the spatial types: And the implicit casting rules need to be more restrictive as well. |
| __slots__ = () | ||
|
|
||
|
|
||
| class MultiPolygon(GeoSpatial): |
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.
Can you document these types? I think people may wonder how these types map to PostgreSQL's versions of these, since they are pretty similar. Also, these types should be flexible enough to support Postgres's versions. I think the exercise of going through the comparison will be very helpful in determining if this is the right set of types to support databases that support them.
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.
it sounds good .. I will also change Line to Linestring. I will also add srid type information.
ibis/expr/tests/test_value_exprs.py
Outdated
| ] | ||
| ) | ||
| def test_literal_cases(value, expected_type): | ||
| @pytest.mark.parametrize(['value', 'expected_type'], [ |
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.
Can you leave this formatting as is?
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.
OK!
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.
for some unknown reason I lost this ... I am doing that.
ibis/expr/tests/test_value_exprs.py
Outdated
| multipolygon1 = [polygon1, polygon2] | ||
|
|
||
|
|
||
| @pytest.mark.parametrize(['value', 'expected_type'], [ |
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.
Please leave this formatting.
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.
OK .. I am doing that. thanks!
ibis/mapd/operations.py
Outdated
| @@ -330,9 +330,43 @@ def _cross_join(translator, expr): | |||
| return translator.translate(left.join(right, ibis.literal(True))) | |||
|
|
|||
|
|
|||
| def _format_point_value(value): | |||
| return ' '.join([str(v) for v in value]) | |||
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.
You don't need to construct a list when calling str.join.
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.
thanks!
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.
@xmnlab please remove the list comprehension and use a generator instead like Phillip mentioned.
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.
sounds good. sorry I lost that for a unknown reason. I am fixing that again. thanks again!
| @@ -602,6 +603,38 @@ def __str__(self) -> str: | |||
| ) | |||
|
|
|||
|
|
|||
| class GeoSpatial(DataType): | |||
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.
Is there some shared functionality among all child classes of this class? If not, then we should just make the geospatial types subclass from DataType and not tie them together unnecessarily.
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.
I thought to create the GeoSpatial data type just to generalize the functions parameters, for example:
ST_Distance(poly1, ST_GeomFromText('POINT(0 0)'))
where st_distance returns shortest planar distance between geometries
maybe would be better to change GeoSpatial name to Geometry
what do you think?
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.
actually I will think more about this .. postgis use geometry and geography types ...
ibis/mapd/operations.py
Outdated
| elif isinstance(expr, ir.PolygonScalar): | ||
| return "POLYGON({0!s})".format(_format_polygon_value(value)) | ||
| elif isinstance(expr, ir.MultiPolygonScalar): | ||
| return "MULTIPOLYGON({0!s})".format(_format_multipolygon_value(value)) |
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.
You don't need the 0!s in the format spec, just write it as {}.
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.
Thanks @cpcloud I will work on that.
| @@ -602,6 +603,38 @@ def __str__(self) -> str: | |||
| ) | |||
|
|
|||
|
|
|||
| class GeoSpatial(DataType): | |||
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.
actually I will think more about this .. postgis use geometry and geography types ...
|
I was thinking, I will change the geospatial literals to accept 2 new arguments, maybe something like (option 1): when geotype (geography) and srid (4326) are optionals. is this pattern ok for geo types? I am trying to do something more closely to the postgis literal, example: or should I use something like the other ibis types, using () or <> ? Example (option 2): |
|
any thought about the last comment (#1666 (comment)) ? |
|
@xmnlab please rebase |
3a8ebd3
to
7742daf
Compare
| @@ -946,6 +1043,28 @@ def type(self) -> DataType: | |||
| struct : "struct" "<" field ":" type ("," field ":" type)* ">" | |||
|
|
|||
| field : [a-zA-Z_][a-zA-Z_0-9]* | |||
|
|
|||
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.
@xmnlab please add test cases for the newly introduces parsing parts, like the semicolon
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.
So for example add an example parametrization of test_dtype with linestring;<srid>:<geotype>
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.
@xmnlab look the uncovered lines: https://codecov.io/gh/ibis-project/ibis/pull/1666/src/ibis/expr/datatypes.py#L1191
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.
Codecov doesn't redirect properly, see the lines from 1191.
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.
Tests added
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.
thanks @kszucs! let me know if it is missing anything else 👍
|
@xmnlab please add an unreleased version to https://github.com/ibis-project/ibis/blob/a16772aea43a936cadc39046ab96d3f54526ecdf/docs/source/release.rst With an "Experimental GeoSpatial datatype support" (or something like that) entry and a reference to the appropiate issue. |
ba2035d
to
8dfc607
Compare
Moving geospatial data to its own module. Added new changes Added geo data type for mapd Fixed flake8 issue Fixed linestring Added infer for tuple Passed an connected ibis as a fixture Changed ibis_connected fixture Changed fixture scope Refactoring geo spatial data type tests Added initial structure for spatial data support Moving geospatial data to its own module. Added new changes Added geo data type for mapd Fixed flake8 issue Fixed linestring Added infer for tuple Passed an connected ibis as a fixture Changed ibis_connected fixture Changed fixture scope Refactoring geo spatial data type tests
8dfc607
to
6228f08
Compare
Added srid and geotypes fixed tests and pep8 Fixed pep8 issues Fixed linestring test for datatypes Removed the inference tuple function. Fixing geospatial literal for mapd Fixed line -> linestring Added map for geospatial datatypes Fixed pep8 issues Fixed pep8 issues changed line -> linestring Fixed small issues from PR feedback Fixed description for geo type usage.
6228f08
to
479cb54
Compare
| @@ -55,8 +53,7 @@ | |||
|
|
|||
| with suppress(ImportError): | |||
| # pip install ibis-framework[mapd] | |||
| if sys.version_info.major >= 3: | |||
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.
Nice catch!
|
The coverage is good now too. Thanks @xmnlab! |
This PR solves #1665 and solves #1707 Add Geo Spatial functions on the main structure and define these functions inside MapD backend. References: - Quansight/omnisci#21 - https://www.omnisci.com/docs/latest/5_geospatial_functions.html Depends on #1666 ( PR 1666 was used as base for the current PR) # Geospatial functions - Geometry/Geography Constructors - [x] ST_GeomFromText(WKT) - using literals - [x] ST_GeogFromText(WKT) - using literals - Geometry Editors - ~ST_Transform (Returns a new geometry with its coordinates transformed to a different spatial reference system.)~ - ~ST_SetSRID (Sets the SRID on a geometry to a particular integer value.)~ - Geometry Accessors - [x] ST_X (Return the X coordinate of the point, or NULL if not available. Input must be a point.) - [x] ST_Y (Return the Y coordinate of the point, or NULL if not available. Input must be a point.) - [x] ST_XMin (Returns Y minima of a bounding box 2d or 3d or a geometry.) - [x] ST_XMax (Returns X maxima of a bounding box 2d or 3d or a geometry.) - [x] ST_YMin (Returns Y minima of a bounding box 2d or 3d or a geometry.) - [x] ST_YMax (Returns Y maxima of a bounding box 2d or 3d or a geometry.) - [x] ST_StartPoint (Returns the first point of a LINESTRING geometry as a POINT or NULL if the input parameter is not a LINESTRING.) - [x] ST_EndPoint (Returns the last point of a LINESTRING geometry as a POINT or NULL if the input parameter is not a LINESTRING.) - [x] ST_PointN (Return the Nth point in a single linestring in the geometry. Negative values are counted backwards from the end of the LineString, so that -1 is the last point. Returns NULL if there is no linestring in the geometry.) - [x] ST_NPoints (Return the number of points in a geometry. Works for all geometries.) - [x] ST_NRings (If the geometry is a polygon or multi-polygon returns the number of rings. It counts the outer rings as well.) - [x] ST_SRID (Returns the spatial reference identifier for the ST_Geometry) - Spatial Relationships and Measurements - [x] ST_Distance - [x] ST_Contains - [x] ST_Area - [x] ST_Perimeter - [x] ST_Length - [x] ST_MaxDistance - Extra - ~CastToGeography~ TODO: will be added in a new PR. Author: Krisztián Szűcs <szucs.krisztian@gmail.com> Author: Ivan Ogasawara <ivan.ogasawara@gmail.com> Closes #1678 from xmnlab/geospatial_functions and squashes the following commits: 4f94baf [Krisztián Szűcs] update docs conda dependencies 44dfaa6 [Krisztián Szűcs] remove IBIS_TEST_DOWNLOAD_DIRECTORY from the docs container as well a96c0fd [Ivan Ogasawara] Added pymapd dependence from conda a1e177d [Krisztián Szűcs] use pkg_resources to get pymapd's version 2cc2285 [Krisztián Szűcs] fox download path in docker-compose e4d4410 [Krisztián Szűcs] more robost testing data download script; updated requirements bb4c8f4 [Krisztián Szűcs] use the zip github endpoint to download the repository 4c3969c [Ivan Ogasawara] Added more tests
Resolves partial #1665
MapD GEO spatial functions support should be addressed in another PR