Skip to content

Implemetation of parse geography and geometry datatype (#4518)#4675

Merged
rishabhtanwar29 merged 1 commit intobabelfish-for-postgresql:BABEL_6_X_DEVfrom
Gopalverma062:BABEL_6329_6x
Mar 20, 2026
Merged

Implemetation of parse geography and geometry datatype (#4518)#4675
rishabhtanwar29 merged 1 commit intobabelfish-for-postgresql:BABEL_6_X_DEVfrom
Gopalverma062:BABEL_6329_6x

Conversation

@Gopalverma062
Copy link
Copy Markdown
Contributor

@Gopalverma062 Gopalverma062 commented Mar 20, 2026

Description

Implemented Parse function support for GeoSpatial TSQL data types that was previously unsupported in Babelfish. The Parse function has been added for both geometry and geography data types.

Changes include:

Function Implementation:

  • Implemented geometry::Parse() and geography::Parse() functions by utilizing PostGIS parsing capabilities with necessary adjustments to ensure TSQL compatibility.

Parser Updates:

  • Added Parse function definitions to the TSQL parser to recognize these new static methods.
  • Ensured proper syntax handling for Parse function, including NVARCHAR parameter types and return values.

Test Cases:

  • Created comprehensive test cases for Parse function, covering various scenarios including basic parsing, empty geometries, NULL handling, whitespace tolerance, case insensitivity, and error conditions.

Error Handling:

  • Implemented appropriate error handling for invalid geometry strings and malformed inputs.

Extending existing functionalities:

  • Added support for parsing empty instances in both geometry and geography datatypes
  • Enhanced CAST operations compatibility with Parse results
  • Added hierarchyid::Parse() support for completeness

Testing:

  • All new Parse functions pass the added test cases.
  • Existing functionality remains unaffected.

Examples:

For geometry::Parse

DECLARE @geomText NVARCHAR(MAX);
SET @geomText = 'POINT(1.0 2.0)';
SELECT geometry::Parse(@geomText).STAsText() AS ParsedGeometry;
GO

Output:

ParsedGeometry
--------------
POINT(1 2)

For geography::Parse

DECLARE @geogText NVARCHAR(MAX);
SET @geogText = 'LINESTRING(0 0, 1 1, 2 2)';
SELECT geography::Parse(@geogText).STAsText() AS ParsedGeography;
GO

Output:

ParsedGeography
---------------
LINESTRING(0 0,1 1,2 2)

For Empty Geometry Parsing

DECLARE @emptyPoint NVARCHAR(MAX);
SET @emptyPoint = 'POINT EMPTY';
SELECT geometry::Parse(@emptyPoint).STAsText() AS ParsedGeometry;
GO

Output:

ParsedGeometry
--------------
POINT EMPTY

Issues Resolved

BABEL 6339

Signed-off by: Gopalgv gopalgv@amazon.com

Authored by: Gopalgv gopalgv@amazon.com


Check List

  • Commits are signed per the DCO using --signoff

By 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.

…-postgresql#4518)

Implemented Parse function support for GeoSpatial TSQL data types that was previously unsupported in Babelfish. The Parse function has been added for both geometry and geography data types.

Changes include:

Implemented geometry::Parse() and geography::Parse() functions by utilizing PostGIS parsing capabilities with necessary adjustments to ensure TSQL compatibility. Added Parse function definitions to the TSQL parser to recognize these new static methods. Ensured proper syntax handling for Parse function, including NVARCHAR parameter types and return values.

Examples:

DECLARE @geomText NVARCHAR(MAX);
SET @geomText = 'POINT(1.0 2.0)';
SELECT geometry::Parse(@geomText).STAsText() AS ParsedGeometry;
GO

ParsedGeometry
--------------
POINT(1 2)


DECLARE @geogText NVARCHAR(MAX);
SET @geogText = 'LINESTRING(0 0, 1 1, 2 2)';
SELECT geography::Parse(@geogText).STAsText() AS ParsedGeography;
GO

ParsedGeography
---------------
LINESTRING(0 0,1 1,2 2)

Task: BABEL-6310

Signed-off by: Gopalgv gopalgv@amazon.com
@rishabhtanwar29 rishabhtanwar29 merged commit ddfccc9 into babelfish-for-postgresql:BABEL_6_X_DEV Mar 20, 2026
48 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants