Add MultiPoint datatype support #4662
Add MultiPoint datatype support #4662Gopalverma062 wants to merge 8 commits intobabelfish-for-postgresql:BABEL_5_X_DEVfrom
Conversation
d85e56b to
5dfc3ce
Compare
| RAISE EXCEPTION '''geography::STMPointFromText'' failed because parameter 2 is not allowed to be null.'; | ||
| ELSIF $1 IS NULL THEN | ||
| RETURN NULL; | ||
| ELSIF $2 < 0 THEN |
There was a problem hiding this comment.
We don't need this check since we already have SRID validity check later on
| RAISE EXCEPTION '''geometry::STMPointFromText'' failed because parameter 2 is not allowed to be null.'; | ||
| ELSIF $1 IS NULL THEN | ||
| RETURN NULL; | ||
| ELSIF $2 < 0 THEN |
| | MPOINT_TOK Z_TOK EMPTY_TOK | ||
| { $$ = pstrdup("MULTIPOINT EMPTY"); } | ||
| | MPOINT_TOK M_TOK EMPTY_TOK | ||
| { $$ = pstrdup("MULTIPOINT EMPTY"); } | ||
| | MPOINT_TOK ZM_TOK EMPTY_TOK | ||
| { $$ = pstrdup("MULTIPOINT EMPTY"); } |
There was a problem hiding this comment.
Why do we need rules for these like : MULTIPOINT M EMPTY, TSQL doesn't allow it, does postgis create these ?
| #define WKB_POINT_TYPE 1 | ||
| #define WKB_LINESTRING_TYPE 2 | ||
| #define WKB_POLYGON_TYPE 3 |
There was a problem hiding this comment.
We can resuse already defined macros e.g.#define POINT_TYPE
There was a problem hiding this comment.
Or better to convert this to an ENUM.
contrib/babelfishpg_common/src/geo.c
Outdated
| StringInfoData output; | ||
|
|
||
| if (!pa) | ||
| return NULL; |
There was a problem hiding this comment.
should we return pstrdup("MULTIPOINT EMPTY") instead similar to rewrite_dim_multipoint_wkt?
|
|
||
|
|
||
| char* | ||
| rewrite_dim_multipoint_wkt(PointArray *pa) |
There was a problem hiding this comment.
This and the above function share a lot of common code, can we extract the logic to helper function?
| #define EMPTY_POINT_Binary "\x01\x04\x00\x00\x00\x00\x00\x00\x00" /* Binary for empty point */ | ||
| #define EMPTY_LINE_Binary "\x01\x02\x00\x00\x00\x00\x00\x00\x00" /* Binary for empty linestring */ | ||
| #define EMPTY_POLYGON_Binary "\x01\x03\x00\x00\x00\x00\x00\x00\x00" /* Binary for empty polygon */ | ||
| #define EMPTY_MULTIPOINT_Binary "\x01\x04\x00\x00\x00\x00\x00\x00\x00" |
There was a problem hiding this comment.
We should rather use _Bytes instead of _Binary
| #define WKB_POINT_TYPE 1 | ||
| #define WKB_LINESTRING_TYPE 2 | ||
| #define WKB_POLYGON_TYPE 3 |
There was a problem hiding this comment.
Or better to convert this to an ENUM.
| @@ -0,0 +1,82 @@ | |||
| # Geometry Views — Properties | |||
There was a problem hiding this comment.
Let's add this new test to lastest/schedule file
|
Let's fix the PR title. |
Description
Currently, Babelfish supports
geometryandgeographyspatial types forPoint,LineString, andPolygongeometries. Attempting to useMultiPointgeometry type results in an "unsupported geometry type" error across all input/output paths including WKT text input, binary (varbinary) conversion, and spatial functions likeSTGeomFromTextandSTMPointFromText.With this change, Babelfish now fully supports the MultiPoint geometry type for both
geometryandgeographydata types. Users can create, store, retrieve, convert, and validate MultiPoint geometries through all existing spatial interfaces, matching T-SQLServer behavior.Why: MultiPoint is a fundamental OGC geometry type used in real-world spatial applications to represent collections of discrete point locations (e.g., sensor networks, store locations, sample sites). Supporting it closes a significant gap in spatial type coverage and moves Babelfish closer to full T-SQL spatial compatibility.
How the code was changed:
WKT Parser (grammar + rewrite functions): Added grammar rules for parsing
MULTIPOINT((x y), ...)andMULTIPOINT Z/M/ZM(...)syntax in both parenthesized and bare coordinate formats. Addedrewrite_multipoint_wkt()andrewrite_dim_multipoint_wkt()functions for WKT normalization.T-SQL CLR Binary ↔ PostGIS WKB conversion (
spatialtypes.c):STROKEfigures andPOINTchild shapes, and conversion from CLR columnar coordinate layout to PostGIS WKB MultiPoint format.Geography validation: Added MultiPoint coordinate validation for latitude/longitude range constraints using
ST_GeometryNPostGIS accessor — consistent with the pattern used for other geometry types.SQL functions (
geometry.sql): AddedSTMPointFromTextfunctions for both geometry and geography types with proper NULL handling, SRID validation, and type checking.Empty geometry handling: Added support for empty MultiPoint in both CLR binary detection (props byte
0x04withEMPTY_COORDpattern andnpoints=0with Z/M flags) and PostGIS WKB output.Test coverage: Added 12–13 MultiPoint test cases across geometry and geography ODBC tests covering 2D, Z, M, ZM, mixed dimensions, NULL coordinate stripping, single-point, empty, and different SRID scenarios.
Issues Resolved
sys.geometryandsys.geographydata typesgeometry::STGeomFromText('MULTIPOINT(...)')now worksgeography::STGeomFromText('MULTIPOINT(...)')now works with latitude/longitude validationgeometry::STMPointFromText()andgeography::STMPointFromText()functions addedvarbinary↔geometry/geography) for MultiPointSTAsText()andSTAsBinary()output for MultiPointMULTIPOINT EMPTY) handling in all pathsTest Scenarios Covered
Use case based -
STGeomFromTextwith geometry and geography typesSTMPointFromTextwith type validationgeometry→varbinary→geometryfor all dimension variantsBoundary conditions -
MULTIPOINT((1 2))— minimum valid collectionMULTIPOINT EMPTY— zero pointsMULTIPOINT((1 2 NULL), (3 4 NULL))stripped to 2DMULTIPOINT((1 2 NULL NULL), (3 4 NULL NULL))stripped to 2DArbitrary inputs -
MULTIPOINT((1 2), (3 4))MULTIPOINT((1 2 3), (4 5 6))MULTIPOINT((1 2 NULL 3), (4 5 NULL 6))MULTIPOINT((1 2 3 4), (5 6 7 8))MULTIPOINT((1 2 3), (4 5))— second point gets Z=NaNMULTIPOINT((1 2 NULL 3), (4 5))— second point gets M=NaNMULTIPOINT((1 2 3 4), (5 6))— second point gets Z=NaN, M=NaNMULTIPOINT(1 2, 3 4)— without inner parenthesesMULTIPOINT((1 2), (3 4))with SRID=0 (geometry only)Negative test cases -
STMPointFromTextwith non-MultiPoint input (e.g.,POINT,LINESTRING) — expects errorSTMPointFromTextwith NULL SRID — expects parameter errorSTMPointFromTextwith negative SRID — expects errorvarbinarydata conversion to MultiPoint — expects conversion errorMinor version upgrade tests -
Major version upgrade tests -
Performance tests -
Tooling impact -
psqlodbctest frameworkClient tests -
Check List
--gopalgv@amazon.comBy submitting this pull request, I confirm that my contribution is under the terms of the Apache 2.0 and PostgreSQL licenses, and grant any person obtaining a copy of the contribution permission to relicense all or a portion of my contribution to the PostgreSQL License solely to contribute all or a portion of my contribution to the PostgreSQL open source project.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.