Skip to content

Add STLength support for geography and geometry types#4468

Open
Gopalverma062 wants to merge 12 commits intobabelfish-for-postgresql:BABEL_5_X_DEVfrom
Gopalverma062:BABEL_6310_STLENGTH
Open

Add STLength support for geography and geometry types#4468
Gopalverma062 wants to merge 12 commits intobabelfish-for-postgresql:BABEL_5_X_DEVfrom
Gopalverma062:BABEL_6310_STLENGTH

Conversation

@Gopalverma062
Copy link
Contributor

@Gopalverma062 Gopalverma062 commented Jan 21, 2026

Description

Implemented STLength() GeoSpatial TSQL function that was previously unsupported in Babelfish.

Changes

Function Implementation

  • Implemented STLength() function by utilizing PostGIS functions where appropriate
  • Made necessary adjustments to ensure TSQL compatibility

Parser Updates

  • Added function definitions to the TSQL parser to recognize the new function
  • Ensured proper syntax handling including parameter types and return values

Test Cases

  • Created comprehensive test cases covering various scenarios
  • Added edge case testing for validation

Error Handling

  • Implemented appropriate error handling for invalid inputs and edge cases

Extended Existing Functionalities

  • Added support for empty instances in geography datatypes
  • Fixed binary string handling for dump and restore tests

Testing

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

@Mohitraj-g Mohitraj-g closed this Jan 21, 2026
@Mohitraj-g Mohitraj-g reopened this Jan 21, 2026
Signed-off-by: Gopal Verma <[email protected]>
CREATE VIEW TestGeospatialMethods_empty_ValFromGeomTemp AS SELECT location.STIsEmpty() FROM TestGeospatialMethods_SPATIALPOINTGEOM_dttemp ORDER BY location.STX;

CREATE VIEW TestGeospatialMethods_empty_TextFromGeomTemp AS SELECT location.STIsEmpty() AS Dimension FROM TestGeospatialMethods_SPATIALPOINTGEOG_dttemp ORDER BY location.Lat; No newline at end of file
CREATE VIEW TestGeospatialMethods_empty_TextFromGeomTemp AS SELECT location.STIsEmpty() AS Dimension FROM TestGeospatialMethods_SPATIALPOINTGEOG_dttemp ORDER BY location.Lat;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unnecessary change, please remove this.

@Mohitraj-g
Copy link
Contributor

Add expected output files as well.

@Mohitraj-g
Copy link
Contributor

Mohitraj-g commented Jan 21, 2026

Please fix the PR description.

Comment on lines +58 to +59
IF geom IS NULL THEN
RETURN NULL;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think marking the function strict already makes sure to return NULL or NULL input so this check seems unnecessary.

Comment on lines +445 to +446
IF geom IS NULL THEN
RETURN NULL;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

CREATE OR REPLACE FUNCTION sys.STPerimeter_helper(sys.GEOMETRY)
RETURNS float8
AS '$libdir/postgis-3','LWGEOM_perimeter2d_poly'
LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's also add sys.STLength(geom sys.GEOGRAPHY) and sys.STLength_helper(geom sys.GEOGRAPHY) functions here.

RETURN geom;
ELSE
RAISE EXCEPTION 'Expected "POLYGON" at Position 1. The input has %', $1;
END IF;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change should come into spatial_types--5.5.0--5.6.0.sql instead. Lets remove these changes from this file.

STDIMENSION: 'STDimension';
STDISJOINT: 'STDisjoint';
STDISTANCE: 'STDistance';
STREDUCE: 'STReduce';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's only add STLENGTH for now. Also, let's not mark the comments as resolved until we actually fix them.

@@ -951,4 +951,164 @@ Select CAST(CAST('POINT EMPTY' as varchar(100)) AS geography).STAsText();
go
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's also add expected output files.

@coveralls
Copy link
Collaborator

coveralls commented Jan 23, 2026

Pull Request Test Coverage Report for Build 21511153874

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 24 unchanged lines in 2 files lost coverage.
  • Overall coverage increased (+0.03%) to 76.991%

Files with Coverage Reduction New Missed Lines %
contrib/babelfishpg_tsql/src/collation.c 1 80.99%
contrib/babelfishpg_tds/src/backend/tds/tdsbulkload.c 23 85.99%
Totals Coverage Status
Change from base Build 21071680503: 0.03%
Covered Lines: 52728
Relevant Lines: 68486

💛 - Coveralls

-------------------------------------------------------
-- STLength
CREATE OR REPLACE FUNCTION sys.STLength(geom sys.GEOMETRY)
RETURNS float8
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have we verified whether it is float4 or float8?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes i have verified it

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.

4 participants