Fixed #35803 -- Added support for Collect, GeoHash, and IsValid on MariaDB 11.7+.

This commit is contained in:
Mariusz Felisiak 2024-09-27 22:26:35 +02:00 committed by Sarah Boyce
parent 0b7edb9fcd
commit c77573716a
5 changed files with 51 additions and 28 deletions

View File

@ -71,7 +71,10 @@ class MySQLOperations(BaseSpatialOperations, DatabaseOperations):
models.Union, models.Union,
] ]
is_mariadb = self.connection.mysql_is_mariadb is_mariadb = self.connection.mysql_is_mariadb
if is_mariadb or self.connection.mysql_version < (8, 0, 24): if is_mariadb:
if self.connection.mysql_version < (11, 7):
disallowed_aggregates.insert(0, models.Collect)
elif self.connection.mysql_version < (8, 0, 24):
disallowed_aggregates.insert(0, models.Collect) disallowed_aggregates.insert(0, models.Collect)
return tuple(disallowed_aggregates) return tuple(disallowed_aggregates)
@ -105,7 +108,8 @@ class MySQLOperations(BaseSpatialOperations, DatabaseOperations):
} }
if self.connection.mysql_is_mariadb: if self.connection.mysql_is_mariadb:
unsupported.remove("PointOnSurface") unsupported.remove("PointOnSurface")
unsupported.update({"GeoHash", "IsValid"}) if self.connection.mysql_version < (11, 7):
unsupported.update({"GeoHash", "IsValid"})
return unsupported return unsupported
def geo_db_type(self, f): def geo_db_type(self, f):

View File

@ -360,7 +360,7 @@ Lookup Type PostGIS Oracle MariaDB MySQL [#]_ S
:lookup:`exact <same_as>` X X X X X B :lookup:`exact <same_as>` X X X X X B
:lookup:`intersects` X X X X X B :lookup:`intersects` X X X X X B
:lookup:`isempty` X :lookup:`isempty` X
:lookup:`isvalid` X X X X :lookup:`isvalid` X X X (≥ 11.7) X X
:lookup:`overlaps` X X X X X B :lookup:`overlaps` X X X X X B
:lookup:`relate` X X X X C :lookup:`relate` X X X X C
:lookup:`same_as` X X X X X B :lookup:`same_as` X X X X X B
@ -406,10 +406,10 @@ Function PostGIS Oracle MariaDB MySQL
:class:`ForcePolygonCW` X X :class:`ForcePolygonCW` X X
:class:`FromWKB` X X X X X :class:`FromWKB` X X X X X
:class:`FromWKT` X X X X X :class:`FromWKT` X X X X X
:class:`GeoHash` X X X (LWGEOM/RTTOPO) :class:`GeoHash` X X (≥ 11.7) X X (LWGEOM/RTTOPO)
:class:`Intersection` X X X X X :class:`Intersection` X X X X X
:class:`IsEmpty` X :class:`IsEmpty` X
:class:`IsValid` X X X X :class:`IsValid` X X X (≥ 11.7) X X
:class:`Length` X X X X X :class:`Length` X X X X X
:class:`LineLocatePoint` X X :class:`LineLocatePoint` X X
:class:`MakeValid` X X (LWGEOM/RTTOPO) :class:`MakeValid` X X (LWGEOM/RTTOPO)
@ -431,20 +431,19 @@ Aggregate Functions
------------------- -------------------
The following table provides a summary of what GIS-specific aggregate functions The following table provides a summary of what GIS-specific aggregate functions
are available on each spatial backend. Please note that MariaDB does not are available on each spatial backend.
support any of these aggregates, and is thus excluded from the table.
.. currentmodule:: django.contrib.gis.db.models .. currentmodule:: django.contrib.gis.db.models
======================= ======= ====== ============ ========== ======================= ======= ====== ========== ============ ==========
Aggregate PostGIS Oracle MySQL SpatiaLite Aggregate PostGIS Oracle MariaDB MySQL SpatiaLite
======================= ======= ====== ============ ========== ======================= ======= ====== ========== ============ ==========
:class:`Collect` X X (≥ 8.0.24) X :class:`Collect` X X (≥ 11.7) X (≥ 8.0.24) X
:class:`Extent` X X X :class:`Extent` X X X
:class:`Extent3D` X :class:`Extent3D` X
:class:`MakeLine` X X :class:`MakeLine` X X
:class:`Union` X X X :class:`Union` X X X
======================= ======= ====== ============ ========== ======================= ======= ====== ========== ============ ==========
.. rubric:: Footnotes .. rubric:: Footnotes
.. [#fnwkt] *See* Open Geospatial Consortium, Inc., `OpenGIS Simple Feature Specification For SQL <https://portal.ogc.org/files/?artifact_id=829>`_, Document 99-049 (May 5, 1999), at Ch. 3.2.5, p. 3-11 (SQL Textual Representation of Geometry). .. [#fnwkt] *See* Open Geospatial Consortium, Inc., `OpenGIS Simple Feature Specification For SQL <https://portal.ogc.org/files/?artifact_id=829>`_, Document 99-049 (May 5, 1999), at Ch. 3.2.5, p. 3-11 (SQL Textual Representation of Geometry).

View File

@ -393,7 +393,7 @@ Creates geometry from `Well-known text (WKT)`_ representation. The optional
.. class:: GeoHash(expression, precision=None, **extra) .. class:: GeoHash(expression, precision=None, **extra)
*Availability*: `MySQL *Availability*: MariaDB, `MySQL
<https://dev.mysql.com/doc/refman/en/spatial-geohash-functions.html#function_st-geohash>`__, <https://dev.mysql.com/doc/refman/en/spatial-geohash-functions.html#function_st-geohash>`__,
`PostGIS <https://postgis.net/docs/ST_GeoHash.html>`__, SpatiaLite `PostGIS <https://postgis.net/docs/ST_GeoHash.html>`__, SpatiaLite
(LWGEOM/RTTOPO) (LWGEOM/RTTOPO)
@ -406,6 +406,10 @@ result.
__ https://en.wikipedia.org/wiki/Geohash __ https://en.wikipedia.org/wiki/Geohash
.. versionchanged:: 5.2
MariaDB 11.7+ support was added.
``GeometryDistance`` ``GeometryDistance``
==================== ====================
@ -444,13 +448,17 @@ geometry. Returns ``True`` if its value is empty and ``False`` otherwise.
.. class:: IsValid(expr) .. class:: IsValid(expr)
*Availability*: `MySQL *Availability*: MariaDB, `MySQL
<https://dev.mysql.com/doc/refman/en/spatial-convenience-functions.html#function_st-isvalid>`__, <https://dev.mysql.com/doc/refman/en/spatial-convenience-functions.html#function_st-isvalid>`__,
`PostGIS <https://postgis.net/docs/ST_IsValid.html>`__, Oracle, SpatiaLite `PostGIS <https://postgis.net/docs/ST_IsValid.html>`__, Oracle, SpatiaLite
Accepts a geographic field or expression and tests if the value is well formed. Accepts a geographic field or expression and tests if the value is well formed.
Returns ``True`` if its value is a valid geometry and ``False`` otherwise. Returns ``True`` if its value is a valid geometry and ``False`` otherwise.
.. versionchanged:: 5.2
MariaDB 11.7+ support was added.
``Length`` ``Length``
========== ==========

View File

@ -370,8 +370,8 @@ Example::
``isvalid`` ``isvalid``
----------- -----------
*Availability*: MySQL, `PostGIS <https://postgis.net/docs/ST_IsValid.html>`__, *Availability*: MariaDB, MySQL,
Oracle, SpatiaLite `PostGIS <https://postgis.net/docs/ST_IsValid.html>`__, Oracle, SpatiaLite
Tests if the geometry is valid. Tests if the geometry is valid.
@ -379,12 +379,16 @@ Example::
Zipcode.objects.filter(poly__isvalid=True) Zipcode.objects.filter(poly__isvalid=True)
========================== ================================================================ =================================== ================================================================
Backend SQL Equivalent Backend SQL Equivalent
========================== ================================================================ =================================== ================================================================
MySQL, PostGIS, SpatiaLite ``ST_IsValid(poly)`` MariaDB, MySQL, PostGIS, SpatiaLite ``ST_IsValid(poly)``
Oracle ``SDO_GEOM.VALIDATE_GEOMETRY_WITH_CONTEXT(poly, 0.05) = 'TRUE'`` Oracle ``SDO_GEOM.VALIDATE_GEOMETRY_WITH_CONTEXT(poly, 0.05) = 'TRUE'``
========================== ================================================================ =================================== ================================================================
.. versionchanged:: 5.2
MariaDB 11.7+ support was added.
.. fieldlookup:: overlaps .. fieldlookup:: overlaps
@ -876,8 +880,8 @@ Example:
.. class:: Collect(geo_field, filter=None) .. class:: Collect(geo_field, filter=None)
*Availability*: `PostGIS <https://postgis.net/docs/ST_Collect.html>`__, MySQL, *Availability*: `PostGIS <https://postgis.net/docs/ST_Collect.html>`__,
SpatiaLite MariaDB, MySQL, SpatiaLite
Returns a ``GEOMETRYCOLLECTION`` or a ``MULTI`` geometry object from the geometry Returns a ``GEOMETRYCOLLECTION`` or a ``MULTI`` geometry object from the geometry
column. This is analogous to a simplified version of the :class:`Union` column. This is analogous to a simplified version of the :class:`Union`
@ -889,6 +893,10 @@ caring about dissolving boundaries.
MySQL 8.0.24+ support was added. MySQL 8.0.24+ support was added.
.. versionchanged:: 5.2
MariaDB 11.7+ support was added.
``Extent`` ``Extent``
~~~~~~~~~~ ~~~~~~~~~~

View File

@ -102,7 +102,11 @@ Minor features
* :lookup:`coveredby` lookup is now supported on MySQL. * :lookup:`coveredby` lookup is now supported on MySQL.
* :lookup:`coveredby` lookup is now supported on MariaDB 11.7+. * :lookup:`coveredby` and :lookup:`isvalid` lookups,
:class:`~django.contrib.gis.db.models.Collect` aggregation, and
:class:`~django.contrib.gis.db.models.functions.GeoHash` and
:class:`~django.contrib.gis.db.models.functions.IsValid` database functions
are now supported on MariaDB 11.7+.
:mod:`django.contrib.messages` :mod:`django.contrib.messages`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~