Skip to content

Supported PostGIS Function: STNumPoints for Geospatial datatypes (#4510)#4673

Open
Gopalverma062 wants to merge 1 commit intobabelfish-for-postgresql:BABEL_6_X_DEVfrom
Gopalverma062:BABEL_6329_STNUMPOINT_6X
Open

Supported PostGIS Function: STNumPoints for Geospatial datatypes (#4510)#4673
Gopalverma062 wants to merge 1 commit intobabelfish-for-postgresql:BABEL_6_X_DEVfrom
Gopalverma062:BABEL_6329_STNUMPOINT_6X

Conversation

@Gopalverma062
Copy link
Copy Markdown
Contributor

Implement STNumPoints GeoSpatial SQL Function

Implemented the STNumPoints GeoSpatial TSQL function that was previously unsupported in Babelfish.


What's Changed

Function Implementation

  • Added sys.STNumPoints(geog sys.GEOGRAPHY) function in geography.sql
  • Delegates to sys.STNumPoints_geography_helper() for valid, non-empty instances
  • Function is marked as IMMUTABLE STRICT PARALLEL SAFE for optimal performance

Error Handling

  • Returns exception for invalid geography instances
  • Returns 0 for empty geography instances
  • Returns actual point count for valid instances

Function Behavior

Input Output
Valid geography instance Integer count of points
Empty geography instance 0
Invalid geography instance Exception

Examples

Point

DECLARE @point geography;
SET @point = geography::STPointFromText('POINT(-122.34900 47.65100)', 4326);
SELECT @point.STNumPoints() AS NumPoints;
-- Output: 1

LineString

DECLARE @line geography;
SET @line = geography::STGeomFromText('LINESTRING(-122.360 47.656, -122.343 47.656, -122.310 47.690)', 4326);
SELECT @line.STNumPoints() AS NumPoints;
-- Output: 3

Polygon

DECLARE @polygon geography;
SET @polygon = geography::STGeomFromText('POLYGON((-122.358 47.653, -122.348 47.649, -122.348 47.658, -122.358 47.658, -122.358 47.653))', 4326);
SELECT @polygon.STNumPoints() AS NumPoints;
-- Output: 5

Empty Instance

DECLARE @empty geography;
SET @empty = geography::STGeomFromText('POINT EMPTY', 4326);
SELECT @empty.STNumPoints() AS NumPoints;
-- Output: 0

Issues Resolved

Task: BABEL-6329

Signed-off by: Gopal verma gopalgv@amazon.com

Authored by: Gopal verma gopalgv@amazon.com


Test Coverage

  • Use case based
  • Boundary conditions
  • Arbitrary inputs
  • Negative test cases

Checklist

  • Commits are signed per the DCO using --signoff
  • Contribution is under Apache 2.0 and PostgreSQL licenses

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.

…elfish-for-postgresql#4510)

Implemented the STNumPoints GeoSpatial TSQL function that was previously unsupported in Babelfish.

BABEL-6329

---------

Co-authored-by: Gopal Verma <gopalgv@amazon.com>
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.

1 participant