diff --git a/contrib/babelfishpg_common/sql/geography.sql b/contrib/babelfishpg_common/sql/geography.sql index 00ad2c7f97d..d39c0ff814e 100644 --- a/contrib/babelfishpg_common/sql/geography.sql +++ b/contrib/babelfishpg_common/sql/geography.sql @@ -433,6 +433,19 @@ CREATE OR REPLACE FUNCTION sys.STDimension(geom sys.GEOGRAPHY) END; $$ LANGUAGE plpgsql IMMUTABLE STRICT PARALLEL SAFE; +--STNumPoints +CREATE OR REPLACE FUNCTION sys.STNumPoints(geog sys.GEOGRAPHY) + RETURNS integer + AS $$ + BEGIN + IF sys.STIsValid(geog) = 0 THEN + RAISE EXCEPTION 'The geography instance is not valid'; + ELSE + RETURN sys.STNumPoints_helper(geog); + END IF; + END; +$$ LANGUAGE plpgsql IMMUTABLE STRICT PARALLEL SAFE; + --Parse CREATE OR REPLACE FUNCTION sys.Geography__Parse(geography_tagged_text sys.NVARCHAR) RETURNS sys.GEOGRAPHY @@ -665,6 +678,11 @@ CREATE OR REPLACE FUNCTION sys.STDimension_helper(sys.GEOGRAPHY) AS '$libdir/postgis-3','LWGEOM_dimension' LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE; +CREATE OR REPLACE FUNCTION sys.STNumPoints_helper(sys.GEOGRAPHY) + RETURNS integer + AS '$libdir/postgis-3', 'LWGEOM_npoints' + LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE; + CREATE OR REPLACE FUNCTION sys.STIntersects_helper(geom1 sys.GEOGRAPHY, geom2 sys.GEOGRAPHY) RETURNS sys.BIT AS '$libdir/postgis-3','ST_Intersects' diff --git a/contrib/babelfishpg_common/sql/geometry.sql b/contrib/babelfishpg_common/sql/geometry.sql index e5ec6d71908..08c141af1cb 100644 --- a/contrib/babelfishpg_common/sql/geometry.sql +++ b/contrib/babelfishpg_common/sql/geometry.sql @@ -462,6 +462,19 @@ CREATE OR REPLACE FUNCTION sys.Geometry__Parse(geometry_tagged_text sys.NVARCHAR END; $$ LANGUAGE plpgsql STRICT IMMUTABLE PARALLEL SAFE; +--STNumPoints +CREATE OR REPLACE FUNCTION sys.STNumPoints(geom sys.GEOMETRY) + RETURNS integer + AS $$ + BEGIN + IF STIsValid(geom) = 0 THEN + RAISE EXCEPTION 'The geometry instance is not valid'; + ELSE + RETURN sys.STNumPoints_helper(geom); + END IF; + END; + $$ LANGUAGE plpgsql IMMUTABLE STRICT PARALLEL SAFE; + -- STDisjoint -- Checks if two geometries have no points in common CREATE OR REPLACE FUNCTION sys.STDisjoint(geom1 sys.GEOMETRY, geom2 sys.GEOMETRY) @@ -656,6 +669,11 @@ CREATE OR REPLACE FUNCTION sys.STDimension_helper(sys.GEOMETRY) RETURNS integer AS '$libdir/postgis-3','LWGEOM_dimension' LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE; + +CREATE OR REPLACE FUNCTION sys.STNumPoints_helper(sys.GEOMETRY) + RETURNS integer + AS '$libdir/postgis-3','LWGEOM_npoints' + LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE; CREATE OR REPLACE FUNCTION sys.STIntersects_helper(geom1 sys.GEOMETRY, geom2 sys.GEOMETRY) RETURNS sys.BIT diff --git a/contrib/babelfishpg_common/sql/upgrades/spatial_types--5.5.0--5.6.0.sql b/contrib/babelfishpg_common/sql/upgrades/spatial_types--5.5.0--5.6.0.sql index 1a6c7621827..dd3a205f3b1 100644 --- a/contrib/babelfishpg_common/sql/upgrades/spatial_types--5.5.0--5.6.0.sql +++ b/contrib/babelfishpg_common/sql/upgrades/spatial_types--5.5.0--5.6.0.sql @@ -1,6 +1,45 @@ ------------------------------------------------------- ---- Include changes related to spatial types here ---- ------------------------------------------------------- + +--STNumPoints +-- geometry + +CREATE OR REPLACE FUNCTION sys.STNumPoints(geom sys.GEOMETRY) + RETURNS integer + AS $$ + BEGIN + IF STIsValid(geom) = 0 THEN + RAISE EXCEPTION 'The geometry instance is not valid'; + ELSE + RETURN sys.STNumPoints_helper(geom); + END IF; + END; + $$ LANGUAGE plpgsql IMMUTABLE STRICT PARALLEL SAFE; + +CREATE OR REPLACE FUNCTION sys.STNumPoints_helper(sys.GEOMETRY) + RETURNS integer + AS '$libdir/postgis-3','LWGEOM_npoints' + LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE; + +-- Geography + +CREATE OR REPLACE FUNCTION sys.STNumPoints(geog sys.GEOGRAPHY) + RETURNS integer + AS $$ + BEGIN + IF sys.STIsValid(geog) = 0 THEN + RAISE EXCEPTION 'The geography instance is not valid'; + ELSE + RETURN sys.STNumPoints_helper(geog); + END IF; + END; +$$ LANGUAGE plpgsql IMMUTABLE STRICT PARALLEL SAFE; + +CREATE OR REPLACE FUNCTION sys.STNumPoints_helper(sys.GEOGRAPHY) + RETURNS integer + AS '$libdir/postgis-3', 'LWGEOM_npoints' + LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE; --parse --Geometry CREATE OR REPLACE FUNCTION sys.Geometry__Parse(geometry_tagged_text sys.NVARCHAR) diff --git a/contrib/babelfishpg_tsql/antlr/TSqlLexer.g4 b/contrib/babelfishpg_tsql/antlr/TSqlLexer.g4 index 4f65c6e42f2..b12f14a6f19 100644 --- a/contrib/babelfishpg_tsql/antlr/TSqlLexer.g4 +++ b/contrib/babelfishpg_tsql/antlr/TSqlLexer.g4 @@ -986,6 +986,7 @@ STISCLOSED: 'STIsClosed'; STISEMPTY: 'STIsEmpty'; STISVALID: 'STIsValid'; STLINEFROMTEXT: 'STLineFromText'; +STNUMPOINTS: 'STNumPoints'; STOP: S T O P; STOPAT: S T O P A T; STOPATMARK: S T O P A T M A R K; diff --git a/contrib/babelfishpg_tsql/antlr/TSqlParser.g4 b/contrib/babelfishpg_tsql/antlr/TSqlParser.g4 index f280a1e1180..ef62c976fed 100644 --- a/contrib/babelfishpg_tsql/antlr/TSqlParser.g4 +++ b/contrib/babelfishpg_tsql/antlr/TSqlParser.g4 @@ -3946,6 +3946,7 @@ geospatial_func_no_arg | STISCLOSED | STISEMPTY | STISVALID + | STNUMPOINTS ; geospatial_func_arg @@ -5088,6 +5089,7 @@ keyword | STISEMPTY | STISVALID | STLINEFROMTEXT + | STNUMPOINTS | STOP | STOPAT | STOPATMARK diff --git a/test/JDBC/expected/Numeric_Decimal_tests.out b/test/JDBC/expected/Numeric_Decimal_tests.out index 85fdacfaec4..98ed26cc5d2 100644 --- a/test/JDBC/expected/Numeric_Decimal_tests.out +++ b/test/JDBC/expected/Numeric_Decimal_tests.out @@ -4884,34 +4884,38 @@ GO -- GEOMETRY -> NUMERIC SELECT CAST(GEOMETRY::STGeomFromText('LINESTRING(0 0, 1 1, 2 2)', 0).STNumPoints() AS NUMERIC(10,0)); GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: syntax error at or near ".")~~ +~~START~~ +numeric +3 +~~END~~ -- GEOMETRY -> DECIMAL SELECT CAST(GEOMETRY::STGeomFromText('LINESTRING(0 0, 1 1, 2 2)', 0).STNumPoints() AS DECIMAL(10,0)); GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: syntax error at or near ".")~~ +~~START~~ +numeric +3 +~~END~~ -- GEOGRAPHY -> NUMERIC/DECIMAL (using STNumPoints() method) -- GEOGRAPHY -> NUMERIC SELECT CAST(GEOGRAPHY::STGeomFromText('LINESTRING(-122.34 47.65, -122.35 47.66)', 4326).STNumPoints() AS NUMERIC(10,0)); GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: syntax error at or near ".")~~ +~~START~~ +numeric +2 +~~END~~ -- GEOGRAPHY -> DECIMAL SELECT CAST(GEOGRAPHY::STGeomFromText('LINESTRING(-122.34 47.65, -122.35 47.66)', 4326).STNumPoints() AS DECIMAL(10,0)); GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: syntax error at or near ".")~~ +~~START~~ +numeric +2 +~~END~~ -- ROWVERSION/TIMESTAMP -> NUMERIC/DECIMAL @@ -5807,33 +5811,37 @@ GO -- GEOMETRY -> NUMERIC using CONVERT SELECT CONVERT(NUMERIC(10,0), GEOMETRY::STGeomFromText('LINESTRING(0 0, 1 1, 2 2)', 0).STNumPoints()); GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: syntax error at or near ".")~~ +~~START~~ +numeric +3 +~~END~~ -- GEOMETRY -> DECIMAL using CONVERT SELECT CONVERT(DECIMAL(10,0), GEOMETRY::STGeomFromText('LINESTRING(0 0, 1 1, 2 2)', 0).STNumPoints()); GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: syntax error at or near ".")~~ +~~START~~ +numeric +3 +~~END~~ -- GEOGRAPHY -> NUMERIC using CONVERT SELECT CONVERT(NUMERIC(10,0), GEOGRAPHY::STGeomFromText('LINESTRING(-122.34 47.65, -122.35 47.66)', 4326).STNumPoints()); GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: syntax error at or near ".")~~ +~~START~~ +numeric +2 +~~END~~ -- GEOGRAPHY -> DECIMAL using CONVERT SELECT CONVERT(DECIMAL(10,0), GEOGRAPHY::STGeomFromText('LINESTRING(-122.34 47.65, -122.35 47.66)', 4326).STNumPoints()); GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: syntax error at or near ".")~~ +~~START~~ +numeric +2 +~~END~~ -- ROWVERSION/TIMESTAMP -> NUMERIC/DECIMAL using CONVERT diff --git a/test/JDBC/expected/Test-spatial-functions-3-vu-cleanup.out b/test/JDBC/expected/Test-spatial-functions-3-vu-cleanup.out index 56f1c67de89..a382e0526e0 100644 --- a/test/JDBC/expected/Test-spatial-functions-3-vu-cleanup.out +++ b/test/JDBC/expected/Test-spatial-functions-3-vu-cleanup.out @@ -1,3 +1,21 @@ +USE TestSTNumPoints_DB; + +DROP VIEW STNumPoints_geog_view_db; +DROP VIEW STNumPoints_geom_view_db; + +DROP TABLE STNumPoints_geog_test_db; +DROP TABLE STNumPoints_geom_test_db; + +USE MASTER; + +DROP VIEW STNumPoints_geog_view; +DROP VIEW STNumPoints_geom_view; + +DROP TABLE STNumPoints_geog_test; +DROP TABLE STNumPoints_geom_test; + +DROP DATABASE TestSTNumPoints_DB; + USE TestGeospatialParse_DB DROP TABLE TestGeospatialParse_GeometryTable3 diff --git a/test/JDBC/expected/Test-spatial-functions-3-vu-prepare.out b/test/JDBC/expected/Test-spatial-functions-3-vu-prepare.out index 5363d55fdff..180494c5361 100644 --- a/test/JDBC/expected/Test-spatial-functions-3-vu-prepare.out +++ b/test/JDBC/expected/Test-spatial-functions-3-vu-prepare.out @@ -1,3 +1,195 @@ +CREATE DATABASE TestSTNumPoints_DB; + +USE TestSTNumPoints_DB; + +CREATE TABLE STNumPoints_geom_test_db ( ID INT PRIMARY KEY, geom_type VARCHAR(50), geom geometry); + +INSERT INTO STNumPoints_geom_test_db (ID, geom_type, geom) VALUES (1, 'Point', geometry::STPointFromText('POINT(0 0)', 0)); +~~ROW COUNT: 1~~ + +INSERT INTO STNumPoints_geom_test_db (ID, geom_type, geom) VALUES (2, 'Point with SRID', geometry::STPointFromText('POINT(-122.349 47.651)', 4326)); +~~ROW COUNT: 1~~ + +INSERT INTO STNumPoints_geom_test_db (ID, geom_type, geom) VALUES (3, 'Point constructor', geometry::Point(3.0, 4.0, 4326)); +~~ROW COUNT: 1~~ + +INSERT INTO STNumPoints_geom_test_db (ID, geom_type, geom) VALUES (4, 'LineString 2pts', geometry::STGeomFromText('LINESTRING(0 0, 1 1)', 0)); +~~ROW COUNT: 1~~ + +INSERT INTO STNumPoints_geom_test_db (ID, geom_type, geom) VALUES (5, 'LineString 3pts', geometry::STGeomFromText('LINESTRING(0 0, 1 1, 2 2)', 0)); +~~ROW COUNT: 1~~ + +INSERT INTO STNumPoints_geom_test_db (ID, geom_type, geom) VALUES (6, 'LineString 5pts', geometry::STGeomFromText('LINESTRING(0 0, 1 1, 2 2, 3 3, 4 4)', 0)); +~~ROW COUNT: 1~~ + +INSERT INTO STNumPoints_geom_test_db (ID, geom_type, geom) VALUES (7, 'Polygon triangle', geometry::STGeomFromText('POLYGON((0 0, 1 0, 0 1, 0 0))', 0)); +~~ROW COUNT: 1~~ + +INSERT INTO STNumPoints_geom_test_db (ID, geom_type, geom) VALUES (8, 'Polygon square', geometry::STGeomFromText('POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))', 0)); +~~ROW COUNT: 1~~ + +INSERT INTO STNumPoints_geom_test_db (ID, geom_type, geom) VALUES (9, 'Polygon with hole', geometry::STGeomFromText('POLYGON((0 0, 10 0, 10 10, 0 10, 0 0), (2 2, 8 2, 8 8, 2 8, 2 2))', 0)); +~~ROW COUNT: 1~~ + +INSERT INTO STNumPoints_geom_test_db (ID, geom_type, geom) VALUES (10, 'Empty Point', geometry::STGeomFromText('POINT EMPTY', 0)); +~~ROW COUNT: 1~~ + +INSERT INTO STNumPoints_geom_test_db (ID, geom_type, geom) VALUES (11, 'Empty LineString', geometry::STGeomFromText('LINESTRING EMPTY', 0)); +~~ROW COUNT: 1~~ + +INSERT INTO STNumPoints_geom_test_db (ID, geom_type, geom) VALUES (12, 'Empty Polygon', geometry::STGeomFromText('POLYGON EMPTY', 0)); +~~ROW COUNT: 1~~ + +INSERT INTO STNumPoints_geom_test_db (ID, geom_type, geom) VALUES (13, 'Point Z', geometry::STGeomFromText('POINT Z(1 2 3)', 0)); +~~ROW COUNT: 1~~ + +INSERT INTO STNumPoints_geom_test_db (ID, geom_type, geom) VALUES (14, 'Empty Point', geometry::STGeomFromText('POINT EMPTY', 0)); +~~ROW COUNT: 1~~ + +INSERT INTO STNumPoints_geom_test_db (ID, geom_type, geom) VALUES (15, 'Empty LineString', geometry::STGeomFromText('LINESTRING EMPTY', 0)); +~~ROW COUNT: 1~~ + +INSERT INTO STNumPoints_geom_test_db (ID, geom_type, geom) VALUES (16, 'Empty Polygon', geometry::STGeomFromText('POLYGON EMPTY', 0)); +~~ROW COUNT: 1~~ + + +CREATE TABLE STNumPoints_geog_test_db ( ID INT PRIMARY KEY, geog_type VARCHAR(50), geog geography ); + +INSERT INTO STNumPoints_geog_test_db (ID, geog_type, geog) VALUES (1, 'Point', geography::STPointFromText('POINT(-122.349 47.651)', 4326)); +~~ROW COUNT: 1~~ + +INSERT INTO STNumPoints_geog_test_db (ID, geog_type, geog) VALUES (2, 'Point constructor', geography::Point(47.651, -122.349, 4326)); +~~ROW COUNT: 1~~ + +INSERT INTO STNumPoints_geog_test_db (ID, geog_type, geog) VALUES (3, 'LineString 2pts', geography::STGeomFromText('LINESTRING(-122.36 47.65, -122.34 47.66)', 4326)); +~~ROW COUNT: 1~~ + +INSERT INTO STNumPoints_geog_test_db (ID, geog_type, geog) VALUES (4, 'LineString 3pts', geography::STGeomFromText('LINESTRING(-122.36 47.65, -122.34 47.66, -122.32 47.67)', 4326)); +~~ROW COUNT: 1~~ + +INSERT INTO STNumPoints_geog_test_db (ID, geog_type, geog) VALUES (5, 'LineString 5pts', geography::STGeomFromText('LINESTRING(-122.36 47.65, -122.35 47.66, -122.34 47.67, -122.33 47.68, -122.32 47.69)', 4326)); +~~ROW COUNT: 1~~ + +INSERT INTO STNumPoints_geog_test_db (ID, geog_type, geog) VALUES (6, 'Polygon triangle', geography::STGeomFromText('POLYGON((-122.36 47.65, -122.34 47.65, -122.35 47.67, -122.36 47.65))', 4326)); +~~ROW COUNT: 1~~ + +INSERT INTO STNumPoints_geog_test_db (ID, geog_type, geog) VALUES (7, 'Polygon square', geography::STGeomFromText('POLYGON((-122.36 47.65, -122.34 47.65, -122.34 47.67, -122.36 47.67, -122.36 47.65))', 4326)); +~~ROW COUNT: 1~~ + +INSERT INTO STNumPoints_geog_test_db (ID, geog_type, geog) VALUES (8, 'Empty Point', geography::STGeomFromText('POINT EMPTY', 4326)); +~~ROW COUNT: 1~~ + +INSERT INTO STNumPoints_geog_test_db (ID, geog_type, geog) VALUES (9, 'Empty LineString', geography::STGeomFromText('LINESTRING EMPTY', 4326)); +~~ROW COUNT: 1~~ + +INSERT INTO STNumPoints_geog_test_db (ID, geog_type, geog) VALUES (10, 'Point Z', geography::STGeomFromText('POINT Z(-122.349 47.651 100)', 4326)); +~~ROW COUNT: 1~~ + +INSERT INTO STNumPoints_geog_test_db (ID, geog_type, geog) VALUES (11, 'Empty Point', geography::STGeomFromText('POINT EMPTY', 4326)); +~~ROW COUNT: 1~~ + +INSERT INTO STNumPoints_geog_test_db (ID, geog_type, geog) VALUES (12, 'Empty LineString', geography::STGeomFromText('LINESTRING EMPTY', 4326)); +~~ROW COUNT: 1~~ + + +CREATE VIEW STNumPoints_geom_view_db AS SELECT ID, geom_type, geom.STNumPoints() AS num_points FROM STNumPoints_geom_test_db; + +CREATE VIEW STNumPoints_geog_view_db AS SELECT ID, geog_type, geog.STNumPoints() AS num_points FROM STNumPoints_geog_test_db; + +USE MASTER + +CREATE TABLE STNumPoints_geom_test ( ID INT PRIMARY KEY, geom_type VARCHAR(50), geom geometry ); + +INSERT INTO STNumPoints_geom_test (ID, geom_type, geom) VALUES (1, 'Point', geometry::STPointFromText('POINT(0 0)', 0)); +~~ROW COUNT: 1~~ + +INSERT INTO STNumPoints_geom_test (ID, geom_type, geom) VALUES (2, 'Point with SRID', geometry::STPointFromText('POINT(-122.349 47.651)', 4326)); +~~ROW COUNT: 1~~ + +INSERT INTO STNumPoints_geom_test (ID, geom_type, geom) VALUES (3, 'Point constructor', geometry::Point(3.0, 4.0, 4326)); +~~ROW COUNT: 1~~ + +INSERT INTO STNumPoints_geom_test (ID, geom_type, geom) VALUES (4, 'LineString 2pts', geometry::STGeomFromText('LINESTRING(0 0, 1 1)', 0)); +~~ROW COUNT: 1~~ + +INSERT INTO STNumPoints_geom_test (ID, geom_type, geom) VALUES (5, 'LineString 3pts', geometry::STGeomFromText('LINESTRING(0 0, 1 1, 2 2)', 0)); +~~ROW COUNT: 1~~ + +INSERT INTO STNumPoints_geom_test (ID, geom_type, geom) VALUES (6, 'LineString 5pts', geometry::STGeomFromText('LINESTRING(0 0, 1 1, 2 2, 3 3, 4 4)', 0)); +~~ROW COUNT: 1~~ + +INSERT INTO STNumPoints_geom_test (ID, geom_type, geom) VALUES (7, 'Polygon triangle', geometry::STGeomFromText('POLYGON((0 0, 1 0, 0 1, 0 0))', 0)); +~~ROW COUNT: 1~~ + +INSERT INTO STNumPoints_geom_test (ID, geom_type, geom) VALUES (8, 'Polygon square', geometry::STGeomFromText('POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))', 0)); +~~ROW COUNT: 1~~ + +INSERT INTO STNumPoints_geom_test (ID, geom_type, geom) VALUES (9, 'Polygon with hole', geometry::STGeomFromText('POLYGON((0 0, 10 0, 10 10, 0 10, 0 0), (2 2, 8 2, 8 8, 2 8, 2 2))', 0)); +~~ROW COUNT: 1~~ + +INSERT INTO STNumPoints_geom_test (ID, geom_type, geom) VALUES (10, 'Empty Point', geometry::STGeomFromText('POINT EMPTY', 0)); +~~ROW COUNT: 1~~ + +INSERT INTO STNumPoints_geom_test (ID, geom_type, geom) VALUES (11, 'Empty LineString', geometry::STGeomFromText('LINESTRING EMPTY', 0)); +~~ROW COUNT: 1~~ + +INSERT INTO STNumPoints_geom_test (ID, geom_type, geom) VALUES (12, 'Empty Polygon', geometry::STGeomFromText('POLYGON EMPTY', 0)); +~~ROW COUNT: 1~~ + +INSERT INTO STNumPoints_geom_test (ID, geom_type, geom) VALUES (13, 'Point Z', geometry::STGeomFromText('POINT Z(1 2 3)', 0)); +~~ROW COUNT: 1~~ + +INSERT INTO STNumPoints_geom_test (ID, geom_type, geom) VALUES (14, 'Empty Point', geometry::STGeomFromText('POINT EMPTY', 0)); +~~ROW COUNT: 1~~ + +INSERT INTO STNumPoints_geom_test (ID, geom_type, geom) VALUES (15, 'Empty LineString', geometry::STGeomFromText('LINESTRING EMPTY', 0)); +~~ROW COUNT: 1~~ + +INSERT INTO STNumPoints_geom_test (ID, geom_type, geom) VALUES (16, 'Empty Polygon', geometry::STGeomFromText('POLYGON EMPTY', 0)); +~~ROW COUNT: 1~~ + + +CREATE TABLE STNumPoints_geog_test ( ID INT PRIMARY KEY, geog_type VARCHAR(50), geog geography ); +INSERT INTO STNumPoints_geog_test (ID, geog_type, geog) VALUES (1, 'Point', geography::STPointFromText('POINT(-122.349 47.651)', 4326)); +~~ROW COUNT: 1~~ + +INSERT INTO STNumPoints_geog_test (ID, geog_type, geog) VALUES (2, 'Point constructor', geography::Point(47.651, -122.349, 4326)); +~~ROW COUNT: 1~~ + +INSERT INTO STNumPoints_geog_test (ID, geog_type, geog) VALUES (3, 'LineString 2pts', geography::STGeomFromText('LINESTRING(-122.36 47.65, -122.34 47.66)', 4326)); +~~ROW COUNT: 1~~ + +INSERT INTO STNumPoints_geog_test (ID, geog_type, geog) VALUES (4, 'LineString 3pts', geography::STGeomFromText('LINESTRING(-122.36 47.65, -122.34 47.66, -122.32 47.67)', 4326)); +~~ROW COUNT: 1~~ + +INSERT INTO STNumPoints_geog_test (ID, geog_type, geog) VALUES (5, 'LineString 5pts', geography::STGeomFromText('LINESTRING(-122.36 47.65, -122.35 47.66, -122.34 47.67, -122.33 47.68, -122.32 47.69)', 4326)); +~~ROW COUNT: 1~~ + +INSERT INTO STNumPoints_geog_test (ID, geog_type, geog) VALUES (6, 'Polygon triangle', geography::STGeomFromText('POLYGON((-122.36 47.65, -122.34 47.65, -122.35 47.67, -122.36 47.65))', 4326)); +~~ROW COUNT: 1~~ + +INSERT INTO STNumPoints_geog_test (ID, geog_type, geog) VALUES (7, 'Polygon square', geography::STGeomFromText('POLYGON((-122.36 47.65, -122.34 47.65, -122.34 47.67, -122.36 47.67, -122.36 47.65))', 4326)); +~~ROW COUNT: 1~~ + +INSERT INTO STNumPoints_geog_test (ID, geog_type, geog) VALUES (8, 'Empty Point', geography::STGeomFromText('POINT EMPTY', 4326)); +~~ROW COUNT: 1~~ + +INSERT INTO STNumPoints_geog_test (ID, geog_type, geog) VALUES (9, 'Empty LineString', geography::STGeomFromText('LINESTRING EMPTY', 4326)); +~~ROW COUNT: 1~~ + +INSERT INTO STNumPoints_geog_test (ID, geog_type, geog) VALUES (10, 'Point Z', geography::STGeomFromText('POINT Z(-122.349 47.651 100)', 4326)); +~~ROW COUNT: 1~~ + +INSERT INTO STNumPoints_geog_test (ID, geog_type, geog) VALUES (11, 'Empty Point', geography::STGeomFromText('POINT EMPTY', 4326)); +~~ROW COUNT: 1~~ + +INSERT INTO STNumPoints_geog_test (ID, geog_type, geog) VALUES (12, 'Empty LineString', geography::STGeomFromText('LINESTRING EMPTY', 4326)); +~~ROW COUNT: 1~~ + + +CREATE VIEW STNumPoints_geom_view AS SELECT ID, geom_type, geom.STNumPoints() AS num_points FROM STNumPoints_geom_test; + +CREATE VIEW STNumPoints_geog_view AS SELECT ID, geog_type, geog.STNumPoints() AS num_points FROM STNumPoints_geog_test; CREATE DATABASE TestGeospatialParse_DB; USE TestGeospatialParse_DB; diff --git a/test/JDBC/expected/Test-spatial-functions-3-vu-verify.out b/test/JDBC/expected/Test-spatial-functions-3-vu-verify.out index 35839387aed..0756d63e847 100644 --- a/test/JDBC/expected/Test-spatial-functions-3-vu-verify.out +++ b/test/JDBC/expected/Test-spatial-functions-3-vu-verify.out @@ -1,4 +1,877 @@ +--STNumPoints() +USE TestSTNumPoints_DB; +GO + +-- View tests +SELECT * FROM STNumPoints_geom_view_db ORDER BY ID; +go +~~START~~ +int#!#varchar#!#int +1#!#Point#!#1 +2#!#Point with SRID#!#1 +3#!#Point constructor#!#1 +4#!#LineString 2pts#!#2 +5#!#LineString 3pts#!#3 +6#!#LineString 5pts#!#5 +7#!#Polygon triangle#!#4 +8#!#Polygon square#!#5 +9#!#Polygon with hole#!#10 +10#!#Empty Point#!#0 +11#!#Empty LineString#!#0 +12#!#Empty Polygon#!#0 +13#!#Point Z#!#1 +14#!#Empty Point#!#0 +15#!#Empty LineString#!#0 +16#!#Empty Polygon#!#0 +~~END~~ + +SELECT * FROM STNumPoints_geog_view_db ORDER BY ID; +go +~~START~~ +int#!#varchar#!#int +1#!#Point#!#1 +2#!#Point constructor#!#1 +3#!#LineString 2pts#!#2 +4#!#LineString 3pts#!#3 +5#!#LineString 5pts#!#5 +6#!#Polygon triangle#!#4 +7#!#Polygon square#!#5 +8#!#Empty Point#!#0 +9#!#Empty LineString#!#0 +10#!#Point Z#!#1 +11#!#Empty Point#!#0 +12#!#Empty LineString#!#0 +~~END~~ + + +-- JOIN test (geom + geog, both DB tables) +SELECT g.ID, g.geom_type, gg.geog_type, + g.geom.STNumPoints() AS geom_pts, gg.geog.STNumPoints() AS geog_pts +FROM STNumPoints_geom_test_db g +JOIN STNumPoints_geog_test_db gg ON g.ID = gg.ID +ORDER BY g.ID; +go +~~START~~ +int#!#varchar#!#varchar#!#int#!#int +1#!#Point#!#Point#!#1#!#1 +2#!#Point with SRID#!#Point constructor#!#1#!#1 +3#!#Point constructor#!#LineString 2pts#!#1#!#2 +4#!#LineString 2pts#!#LineString 3pts#!#2#!#3 +5#!#LineString 3pts#!#LineString 5pts#!#3#!#5 +6#!#LineString 5pts#!#Polygon triangle#!#5#!#4 +7#!#Polygon triangle#!#Polygon square#!#4#!#5 +8#!#Polygon square#!#Empty Point#!#5#!#0 +9#!#Polygon with hole#!#Empty LineString#!#10#!#0 +10#!#Empty Point#!#Point Z#!#0#!#1 +11#!#Empty LineString#!#Empty Point#!#0#!#0 +12#!#Empty Polygon#!#Empty LineString#!#0#!#0 +~~END~~ + + +-- CTE test +WITH PointCTE AS ( + SELECT ID, geom_type, geom.STNumPoints() AS num_points FROM STNumPoints_geom_test_db +) +SELECT * FROM PointCTE WHERE num_points > 0 ORDER BY num_points DESC, geom_type; +go +~~START~~ +int#!#varchar#!#int +9#!#Polygon with hole#!#10 +6#!#LineString 5pts#!#5 +8#!#Polygon square#!#5 +7#!#Polygon triangle#!#4 +5#!#LineString 3pts#!#3 +4#!#LineString 2pts#!#2 +1#!#Point#!#1 +3#!#Point constructor#!#1 +2#!#Point with SRID#!#1 +13#!#Point Z#!#1 +~~END~~ + + +-- CTE with Window Functions +WITH RankedGeom AS ( + SELECT ID, geom_type, geom.STNumPoints() AS num_points, + ROW_NUMBER() OVER (ORDER BY geom.STNumPoints() DESC, ID) AS row_num, + RANK() OVER (ORDER BY geom.STNumPoints() DESC, ID) AS rnk, + SUM(geom.STNumPoints()) OVER () AS total_pts + FROM STNumPoints_geom_test_db +) +SELECT * FROM RankedGeom ORDER BY row_num; +go +~~START~~ +int#!#varchar#!#int#!#bigint#!#bigint#!#int +9#!#Polygon with hole#!#10#!#1#!#1#!#33 +6#!#LineString 5pts#!#5#!#2#!#2#!#33 +8#!#Polygon square#!#5#!#3#!#3#!#33 +7#!#Polygon triangle#!#4#!#4#!#4#!#33 +5#!#LineString 3pts#!#3#!#5#!#5#!#33 +4#!#LineString 2pts#!#2#!#6#!#6#!#33 +1#!#Point#!#1#!#7#!#7#!#33 +2#!#Point with SRID#!#1#!#8#!#8#!#33 +3#!#Point constructor#!#1#!#9#!#9#!#33 +13#!#Point Z#!#1#!#10#!#10#!#33 +10#!#Empty Point#!#0#!#11#!#11#!#33 +11#!#Empty LineString#!#0#!#12#!#12#!#33 +12#!#Empty Polygon#!#0#!#13#!#13#!#33 +14#!#Empty Point#!#0#!#14#!#14#!#33 +15#!#Empty LineString#!#0#!#15#!#15#!#33 +16#!#Empty Polygon#!#0#!#16#!#16#!#33 +~~END~~ + + +-- GROUP BY test +SELECT geom_type, COUNT(*) AS cnt, SUM(geom.STNumPoints()) AS total_pts +FROM STNumPoints_geom_test_db +GROUP BY geom_type +ORDER BY total_pts DESC, geom_type; +go +~~START~~ +varchar#!#int#!#int +Polygon with hole#!#1#!#10 +LineString 5pts#!#1#!#5 +Polygon square#!#1#!#5 +Polygon triangle#!#1#!#4 +LineString 3pts#!#1#!#3 +LineString 2pts#!#1#!#2 +Point#!#1#!#1 +Point constructor#!#1#!#1 +Point with SRID#!#1#!#1 +Point Z#!#1#!#1 +Empty LineString#!#2#!#0 +Empty Point#!#2#!#0 +Empty Polygon#!#2#!#0 +~~END~~ + + +-- ORDER BY test +SELECT ID, geom_type, geom.STNumPoints() AS num_points +FROM STNumPoints_geom_test_db +ORDER BY num_points DESC, ID ASC; +go +~~START~~ +int#!#varchar#!#int +9#!#Polygon with hole#!#10 +6#!#LineString 5pts#!#5 +8#!#Polygon square#!#5 +7#!#Polygon triangle#!#4 +5#!#LineString 3pts#!#3 +4#!#LineString 2pts#!#2 +1#!#Point#!#1 +2#!#Point with SRID#!#1 +3#!#Point constructor#!#1 +13#!#Point Z#!#1 +10#!#Empty Point#!#0 +11#!#Empty LineString#!#0 +12#!#Empty Polygon#!#0 +14#!#Empty Point#!#0 +15#!#Empty LineString#!#0 +16#!#Empty Polygon#!#0 +~~END~~ + + +-- Nested functions test +SELECT ID, geom_type, + ABS(geom.STNumPoints() - 5) AS diff_from_5, + COALESCE(NULLIF(geom.STNumPoints(), 0), -1) AS pts_or_neg1 +FROM STNumPoints_geom_test_db +ORDER BY ID; +go +~~START~~ +int#!#varchar#!#int#!#int +1#!#Point#!#4#!#1 +2#!#Point with SRID#!#4#!#1 +3#!#Point constructor#!#4#!#1 +4#!#LineString 2pts#!#3#!#2 +5#!#LineString 3pts#!#2#!#3 +6#!#LineString 5pts#!#0#!#5 +7#!#Polygon triangle#!#1#!#4 +8#!#Polygon square#!#0#!#5 +9#!#Polygon with hole#!#5#!#10 +10#!#Empty Point#!#5#!#-1 +11#!#Empty LineString#!#5#!#-1 +12#!#Empty Polygon#!#5#!#-1 +13#!#Point Z#!#4#!#1 +14#!#Empty Point#!#5#!#-1 +15#!#Empty LineString#!#5#!#-1 +16#!#Empty Polygon#!#5#!#-1 +~~END~~ + + +USE MASTER; +go + + +-- Test STNumPoints() on geometry table with various geometry types +SELECT + ID, + geom_type, + geom.STNumPoints() AS actual_result, + CASE ID + WHEN 1 THEN 1 + WHEN 2 THEN 1 + WHEN 3 THEN 1 + WHEN 4 THEN 2 + WHEN 5 THEN 3 + WHEN 6 THEN 5 + WHEN 7 THEN 4 + WHEN 8 THEN 5 + WHEN 9 THEN 10 + WHEN 10 THEN 0 + WHEN 11 THEN 0 + WHEN 12 THEN 0 + WHEN 13 THEN 1 + WHEN 14 THEN 0 + WHEN 15 THEN 0 + WHEN 16 THEN 0 + END AS expected_result +FROM STNumPoints_geom_test +ORDER BY ID; +-- Test STNumPoints() with STPointFromText +DECLARE @point geometry; +SET @point = geometry::STPointFromText('POINT(-122.34900 47.65100)', 4326); +SELECT @point.STNumPoints(); +go +~~START~~ +int#!#varchar#!#int#!#int +1#!#Point#!#1#!#1 +2#!#Point with SRID#!#1#!#1 +3#!#Point constructor#!#1#!#1 +4#!#LineString 2pts#!#2#!#2 +5#!#LineString 3pts#!#3#!#3 +6#!#LineString 5pts#!#5#!#5 +7#!#Polygon triangle#!#4#!#4 +8#!#Polygon square#!#5#!#5 +9#!#Polygon with hole#!#10#!#10 +10#!#Empty Point#!#0#!#0 +11#!#Empty LineString#!#0#!#0 +12#!#Empty Polygon#!#0#!#0 +13#!#Point Z#!#1#!#1 +14#!#Empty Point#!#0#!#0 +15#!#Empty LineString#!#0#!#0 +16#!#Empty Polygon#!#0#!#0 +~~END~~ + +~~START~~ +int +1 +~~END~~ + + +DECLARE @point geometry; +SET @point = geometry::Point(22.34900, -47.65100, 4326); +SELECT @point.STNumPoints ( ); +go +~~START~~ +int +1 +~~END~~ + + + +-- Test STNumPoints() on geography table with various geography types +SELECT + ID, + geog_type, + geog.STNumPoints() AS actual_result, + CASE ID + WHEN 1 THEN 1 + WHEN 2 THEN 1 + WHEN 3 THEN 2 + WHEN 4 THEN 3 + WHEN 5 THEN 5 + WHEN 6 THEN 4 + WHEN 7 THEN 5 + WHEN 8 THEN 0 + WHEN 9 THEN 0 + WHEN 10 THEN 1 + WHEN 11 THEN 0 + WHEN 12 THEN 0 + END AS expected_result +FROM STNumPoints_geog_test +ORDER BY ID; +go +~~START~~ +int#!#varchar#!#int#!#int +1#!#Point#!#1#!#1 +2#!#Point constructor#!#1#!#1 +3#!#LineString 2pts#!#2#!#2 +4#!#LineString 3pts#!#3#!#3 +5#!#LineString 5pts#!#5#!#5 +6#!#Polygon triangle#!#4#!#4 +7#!#Polygon square#!#5#!#5 +8#!#Empty Point#!#0#!#0 +9#!#Empty LineString#!#0#!#0 +10#!#Point Z#!#1#!#1 +11#!#Empty Point#!#0#!#0 +12#!#Empty LineString#!#0#!#0 +~~END~~ + + +DECLARE @point geography; +SET @point = geography::STPointFromText('POINT(-122.34900 47.65100)', 4326); +SELECT @point.STNumPoints(); +go +~~START~~ +int +1 +~~END~~ + + +DECLARE @point geography; +SET @point = geography::Point(47.65100, -122.34900, 4326); +SELECT @point . STNumPoints ( ); +go +~~START~~ +int +1 +~~END~~ + + +-- Test STNumPoints() on NULL geometry +DECLARE @nullGeom geometry; +SELECT @nullGeom.STNumPoints() AS null_geometry_result; +go +~~START~~ +int + +~~END~~ + + +-- Test STNumPoints() on empty point +DECLARE @g geometry; +SET @g = geometry::STGeomFromText('POINT EMPTY', 0); +SELECT @g.STNumPoints() AS empty_point_geometry; +go +~~START~~ +int +0 +~~END~~ + + +DECLARE @g geography; +SET @g = geography::STGeomFromText('POINT EMPTY', 4326); +SELECT @g.STNumPoints() AS empty_point_geography; +go +~~START~~ +int +0 +~~END~~ + + +-- Test STNumPoints() with CAST from VARCHAR +SELECT CAST(CAST('POINT EMPTY' AS VARCHAR(100)) AS geography).STNumPoints() AS cast_varchar_result; +go +~~START~~ +int +0 +~~END~~ + + +-- Test STNumPoints() with CAST from CHAR +SELECT CAST(CAST('POINT EMPTY' AS CHAR(100)) AS geography).STNumPoints() AS cast_char_result; +go +~~START~~ +int +0 +~~END~~ + + +-- Test STNumPoints() via geometry view +SELECT * FROM STNumPoints_geom_view ORDER BY ID; +go +~~START~~ +int#!#varchar#!#int +1#!#Point#!#1 +2#!#Point with SRID#!#1 +3#!#Point constructor#!#1 +4#!#LineString 2pts#!#2 +5#!#LineString 3pts#!#3 +6#!#LineString 5pts#!#5 +7#!#Polygon triangle#!#4 +8#!#Polygon square#!#5 +9#!#Polygon with hole#!#10 +10#!#Empty Point#!#0 +11#!#Empty LineString#!#0 +12#!#Empty Polygon#!#0 +13#!#Point Z#!#1 +14#!#Empty Point#!#0 +15#!#Empty LineString#!#0 +16#!#Empty Polygon#!#0 +~~END~~ + + +-- Test STNumPoints() via geography view +SELECT * FROM STNumPoints_geog_view ORDER BY ID; +go +~~START~~ +int#!#varchar#!#int +1#!#Point#!#1 +2#!#Point constructor#!#1 +3#!#LineString 2pts#!#2 +4#!#LineString 3pts#!#3 +5#!#LineString 5pts#!#5 +6#!#Polygon triangle#!#4 +7#!#Polygon square#!#5 +8#!#Empty Point#!#0 +9#!#Empty LineString#!#0 +10#!#Point Z#!#1 +11#!#Empty Point#!#0 +12#!#Empty LineString#!#0 +~~END~~ + + +-- Test STNumPoints() with different SRIDs for geometry +DECLARE @point1 geometry = geometry::STPointFromText('POINT(-122.349 47.651)', 4326); +DECLARE @point2 geometry = geometry::STPointFromText('POINT(-122.349 47.651)', 0); +DECLARE @point3 geometry = geometry::STPointFromText('POINT(-122.349 47.651)', 999999); +SELECT + @point1.STNumPoints() AS srid_4326, + @point2.STNumPoints() AS srid_0, + @point3.STNumPoints() AS srid_999999; +go +~~START~~ +int#!#int#!#int +1#!#1#!#1 +~~END~~ + + +-- Test STNumPoints() with different SRIDs for geography +DECLARE @point1 geography = geography::STPointFromText('POINT(-122.349 47.651)', 4326); +DECLARE @point2 geography = geography::STPointFromText('POINT(-122.349 47.651)', 4204); +SELECT + @point1.STNumPoints() AS srid_4326, + @point2.STNumPoints() AS srid_4204; +go +~~START~~ +int#!#int +1#!#1 +~~END~~ + + +-- Test STNumPoints() on LineString +DECLARE @line geometry; +SET @line = geometry::STGeomFromText('LINESTRING(0 0, 1 1, 2 2)', 0); +SELECT @line.STNumPoints(); +go +~~START~~ +int +3 +~~END~~ + + +-- Test STNumPoints() on simple Polygon +DECLARE @poly geometry; +SET @poly = geometry::STGeomFromText('POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))', 0); +SELECT @poly.STNumPoints(); +go +~~START~~ +int +5 +~~END~~ + + +-- Test STNumPoints() on Polygon with hole +DECLARE @poly geometry; +SET @poly = geometry::STGeomFromText('POLYGON((0 0, 10 0, 10 10, 0 10, 0 0), (2 2, 8 2, 8 8, 2 8, 2 2))', 0); +SELECT @poly.STNumPoints(); +go +~~START~~ +int +10 +~~END~~ + + +-- Test STNumPoints() on Point with Z coordinate (geometry) +DECLARE @pointZ geometry; +SET @pointZ = geometry::STGeomFromText('POINT(0 0 5)', 0); +SELECT @pointZ.STNumPoints(); +go +~~START~~ +int +1 +~~END~~ + + +-- Test STNumPoints() on Point with Z coordinate (geography) +DECLARE @pointZ geography; +SET @pointZ = geography::STGeomFromText('POINT(-122.34 47.65 100)', 4326); +SELECT @pointZ.STNumPoints(); +go +~~START~~ +int +1 +~~END~~ + + +-- Test STNumPoints() on Point with M coordinate +DECLARE @pointM geometry; +SET @pointM = geometry::STGeomFromText('POINT(0 0 NULL 5)', 0); +SELECT @pointM.STNumPoints(); +go +~~START~~ +int +1 +~~END~~ + + +-- Test STNumPoints() on LineString with Z coordinates +DECLARE @lineZ geometry; +SET @lineZ = geometry::STGeomFromText('LINESTRING(0 0 0, 1 1 1, 2 2 2)', 0); +SELECT @lineZ.STNumPoints(); +go +~~START~~ +int +3 +~~END~~ + + +-- UNION test +SELECT 'geometry' AS source, geom.STNumPoints() AS num_points FROM STNumPoints_geom_test WHERE ID <= 3 +UNION ALL +SELECT 'geography' AS source, geog.STNumPoints() AS num_points FROM STNumPoints_geog_test WHERE ID <= 3 +ORDER BY source, num_points; +go +~~START~~ +varchar#!#int +geography#!#1 +geography#!#1 +geography#!#2 +geometry#!#1 +geometry#!#1 +geometry#!#1 +~~END~~ + + + +SELECT g1.ID, g1.geom_type, g1.geom.STNumPoints() AS geom_points, + g2.ID, g2.geog_type, g2.geog.STNumPoints() AS geog_points +FROM STNumPoints_geom_test g1 +JOIN STNumPoints_geog_test g2 ON g1.geom.STNumPoints() = g2.geog.STNumPoints() +WHERE g1.ID <= 5 AND g2.ID <= 5 +ORDER BY g1.ID, g2.ID; +go +~~START~~ +int#!#varchar#!#int#!#int#!#varchar#!#int +1#!#Point#!#1#!#1#!#Point#!#1 +1#!#Point#!#1#!#2#!#Point constructor#!#1 +2#!#Point with SRID#!#1#!#1#!#Point#!#1 +2#!#Point with SRID#!#1#!#2#!#Point constructor#!#1 +3#!#Point constructor#!#1#!#1#!#Point#!#1 +3#!#Point constructor#!#1#!#2#!#Point constructor#!#1 +4#!#LineString 2pts#!#2#!#3#!#LineString 2pts#!#2 +5#!#LineString 3pts#!#3#!#4#!#LineString 3pts#!#3 +~~END~~ + + +-- Geometry WHERE/ORDER BY/GROUP BY tests +SELECT ID, geom_type FROM STNumPoints_geom_test WHERE geom.STNumPoints() BETWEEN 2 AND 5 ORDER BY ID; +go +~~START~~ +int#!#varchar +4#!#LineString 2pts +5#!#LineString 3pts +6#!#LineString 5pts +7#!#Polygon triangle +8#!#Polygon square +~~END~~ + +SELECT geom.STNumPoints() AS num_points, COUNT(*) AS count FROM STNumPoints_geom_test GROUP BY geom.STNumPoints() HAVING COUNT(*) > 1 ORDER BY num_points; +go +~~START~~ +int#!#int +0#!#6 +1#!#4 +5#!#2 +~~END~~ + + +-- Geography WHERE/ORDER BY/GROUP BY tests +SELECT ID, geog_type FROM STNumPoints_geog_test WHERE geog.STNumPoints() BETWEEN 2 AND 5 ORDER BY ID; +go +~~START~~ +int#!#varchar +3#!#LineString 2pts +4#!#LineString 3pts +5#!#LineString 5pts +6#!#Polygon triangle +7#!#Polygon square +~~END~~ + +SELECT geog.STNumPoints() AS num_points, COUNT(*) AS count FROM STNumPoints_geog_test GROUP BY geog.STNumPoints() HAVING COUNT(*) > 1 ORDER BY num_points; +go +~~START~~ +int#!#int +0#!#4 +1#!#3 +5#!#2 +~~END~~ + + +-- Geometry CTE test +WITH GeomCTE AS ( + SELECT ID, geom_type, geom.STNumPoints() AS num_points FROM STNumPoints_geom_test +) +SELECT * FROM GeomCTE WHERE num_points > 0 ORDER BY num_points, ID; +go +~~START~~ +int#!#varchar#!#int +1#!#Point#!#1 +2#!#Point with SRID#!#1 +3#!#Point constructor#!#1 +13#!#Point Z#!#1 +4#!#LineString 2pts#!#2 +5#!#LineString 3pts#!#3 +7#!#Polygon triangle#!#4 +6#!#LineString 5pts#!#5 +8#!#Polygon square#!#5 +9#!#Polygon with hole#!#10 +~~END~~ + + +-- Geometry Window test +SELECT ID, geom_type, geom.STNumPoints() AS num_points, + ROW_NUMBER() OVER (ORDER BY geom.STNumPoints() DESC) AS row_num +FROM STNumPoints_geom_test ORDER BY row_num; +go +~~START~~ +int#!#varchar#!#int#!#bigint +9#!#Polygon with hole#!#10#!#1 +8#!#Polygon square#!#5#!#2 +6#!#LineString 5pts#!#5#!#3 +7#!#Polygon triangle#!#4#!#4 +5#!#LineString 3pts#!#3#!#5 +4#!#LineString 2pts#!#2#!#6 +1#!#Point#!#1#!#7 +2#!#Point with SRID#!#1#!#8 +3#!#Point constructor#!#1#!#9 +13#!#Point Z#!#1#!#10 +11#!#Empty LineString#!#0#!#11 +12#!#Empty Polygon#!#0#!#12 +16#!#Empty Polygon#!#0#!#13 +14#!#Empty Point#!#0#!#14 +15#!#Empty LineString#!#0#!#15 +10#!#Empty Point#!#0#!#16 +~~END~~ + + +-- Geography CTE test +WITH GeogCTE AS ( + SELECT ID, geog_type, geog.STNumPoints() AS num_points FROM STNumPoints_geog_test +) +SELECT * FROM GeogCTE WHERE num_points > 0 ORDER BY num_points, ID; +go +~~START~~ +int#!#varchar#!#int +1#!#Point#!#1 +2#!#Point constructor#!#1 +10#!#Point Z#!#1 +3#!#LineString 2pts#!#2 +4#!#LineString 3pts#!#3 +6#!#Polygon triangle#!#4 +5#!#LineString 5pts#!#5 +7#!#Polygon square#!#5 +~~END~~ + + +-- Geography Window test +SELECT ID, geog_type, geog.STNumPoints() AS num_points, + ROW_NUMBER() OVER (ORDER BY geog.STNumPoints() DESC, ID) AS row_num +FROM STNumPoints_geog_test ORDER BY row_num; +go +~~START~~ +int#!#varchar#!#int#!#bigint +5#!#LineString 5pts#!#5#!#1 +7#!#Polygon square#!#5#!#2 +6#!#Polygon triangle#!#4#!#3 +4#!#LineString 3pts#!#3#!#4 +3#!#LineString 2pts#!#2#!#5 +1#!#Point#!#1#!#6 +2#!#Point constructor#!#1#!#7 +10#!#Point Z#!#1#!#8 +8#!#Empty Point#!#0#!#9 +9#!#Empty LineString#!#0#!#10 +11#!#Empty Point#!#0#!#11 +12#!#Empty LineString#!#0#!#12 +~~END~~ + + +-- View tests +SELECT * FROM STNumPoints_geom_view ORDER BY ID; +go +~~START~~ +int#!#varchar#!#int +1#!#Point#!#1 +2#!#Point with SRID#!#1 +3#!#Point constructor#!#1 +4#!#LineString 2pts#!#2 +5#!#LineString 3pts#!#3 +6#!#LineString 5pts#!#5 +7#!#Polygon triangle#!#4 +8#!#Polygon square#!#5 +9#!#Polygon with hole#!#10 +10#!#Empty Point#!#0 +11#!#Empty LineString#!#0 +12#!#Empty Polygon#!#0 +13#!#Point Z#!#1 +14#!#Empty Point#!#0 +15#!#Empty LineString#!#0 +16#!#Empty Polygon#!#0 +~~END~~ + +SELECT * FROM STNumPoints_geog_view ORDER BY ID; +go +~~START~~ +int#!#varchar#!#int +1#!#Point#!#1 +2#!#Point constructor#!#1 +3#!#LineString 2pts#!#2 +4#!#LineString 3pts#!#3 +5#!#LineString 5pts#!#5 +6#!#Polygon triangle#!#4 +7#!#Polygon square#!#5 +8#!#Empty Point#!#0 +9#!#Empty LineString#!#0 +10#!#Point Z#!#1 +11#!#Empty Point#!#0 +12#!#Empty LineString#!#0 +~~END~~ + + +-- JOIN test (geom + geog, both MASTER tables) +SELECT g.ID, g.geom_type, gg.geog_type, + g.geom.STNumPoints() AS geom_pts, gg.geog.STNumPoints() AS geog_pts +FROM STNumPoints_geom_test g +JOIN STNumPoints_geog_test gg ON g.ID = gg.ID +ORDER BY g.ID; +go +~~START~~ +int#!#varchar#!#varchar#!#int#!#int +1#!#Point#!#Point#!#1#!#1 +2#!#Point with SRID#!#Point constructor#!#1#!#1 +3#!#Point constructor#!#LineString 2pts#!#1#!#2 +4#!#LineString 2pts#!#LineString 3pts#!#2#!#3 +5#!#LineString 3pts#!#LineString 5pts#!#3#!#5 +6#!#LineString 5pts#!#Polygon triangle#!#5#!#4 +7#!#Polygon triangle#!#Polygon square#!#4#!#5 +8#!#Polygon square#!#Empty Point#!#5#!#0 +9#!#Polygon with hole#!#Empty LineString#!#10#!#0 +10#!#Empty Point#!#Point Z#!#0#!#1 +11#!#Empty LineString#!#Empty Point#!#0#!#0 +12#!#Empty Polygon#!#Empty LineString#!#0#!#0 +~~END~~ + + +-- CTE with Window Functions +WITH RankedGeom AS ( + SELECT ID, geom_type, geom.STNumPoints() AS num_points, + ROW_NUMBER() OVER (ORDER BY geom.STNumPoints() DESC) AS row_num, + RANK() OVER (ORDER BY geom.STNumPoints() DESC) AS rnk, + SUM(geom.STNumPoints()) OVER () AS total_pts + FROM STNumPoints_geom_test +) +SELECT * FROM RankedGeom ORDER BY row_num; +go +~~START~~ +int#!#varchar#!#int#!#bigint#!#bigint#!#int +9#!#Polygon with hole#!#10#!#1#!#1#!#33 +8#!#Polygon square#!#5#!#2#!#2#!#33 +6#!#LineString 5pts#!#5#!#3#!#2#!#33 +7#!#Polygon triangle#!#4#!#4#!#4#!#33 +5#!#LineString 3pts#!#3#!#5#!#5#!#33 +4#!#LineString 2pts#!#2#!#6#!#6#!#33 +1#!#Point#!#1#!#7#!#7#!#33 +2#!#Point with SRID#!#1#!#8#!#7#!#33 +3#!#Point constructor#!#1#!#9#!#7#!#33 +13#!#Point Z#!#1#!#10#!#7#!#33 +11#!#Empty LineString#!#0#!#11#!#11#!#33 +12#!#Empty Polygon#!#0#!#12#!#11#!#33 +16#!#Empty Polygon#!#0#!#13#!#11#!#33 +14#!#Empty Point#!#0#!#14#!#11#!#33 +15#!#Empty LineString#!#0#!#15#!#11#!#33 +10#!#Empty Point#!#0#!#16#!#11#!#33 +~~END~~ + + +-- GROUP BY test +SELECT geom_type, COUNT(*) AS cnt, SUM(geom.STNumPoints()) AS total_pts +FROM STNumPoints_geom_test +GROUP BY geom_type +ORDER BY total_pts DESC, geom_type; +go +~~START~~ +varchar#!#int#!#int +Polygon with hole#!#1#!#10 +LineString 5pts#!#1#!#5 +Polygon square#!#1#!#5 +Polygon triangle#!#1#!#4 +LineString 3pts#!#1#!#3 +LineString 2pts#!#1#!#2 +Point#!#1#!#1 +Point constructor#!#1#!#1 +Point with SRID#!#1#!#1 +Point Z#!#1#!#1 +Empty LineString#!#2#!#0 +Empty Point#!#2#!#0 +Empty Polygon#!#2#!#0 +~~END~~ + + +-- ORDER BY test +SELECT ID, geom_type, geom.STNumPoints() AS num_points +FROM STNumPoints_geom_test +ORDER BY num_points DESC, ID ASC; +go +~~START~~ +int#!#varchar#!#int +9#!#Polygon with hole#!#10 +6#!#LineString 5pts#!#5 +8#!#Polygon square#!#5 +7#!#Polygon triangle#!#4 +5#!#LineString 3pts#!#3 +4#!#LineString 2pts#!#2 +1#!#Point#!#1 +2#!#Point with SRID#!#1 +3#!#Point constructor#!#1 +13#!#Point Z#!#1 +10#!#Empty Point#!#0 +11#!#Empty LineString#!#0 +12#!#Empty Polygon#!#0 +14#!#Empty Point#!#0 +15#!#Empty LineString#!#0 +16#!#Empty Polygon#!#0 +~~END~~ + + +-- Nested functions test +SELECT ID, geom_type, + ABS(geom.STNumPoints() - 5) AS diff_from_5, + COALESCE(NULLIF(geom.STNumPoints(), 0), -1) AS pts_or_neg1 +FROM STNumPoints_geom_test +ORDER BY ID; +go +~~START~~ +int#!#varchar#!#int#!#int +1#!#Point#!#4#!#1 +2#!#Point with SRID#!#4#!#1 +3#!#Point constructor#!#4#!#1 +4#!#LineString 2pts#!#3#!#2 +5#!#LineString 3pts#!#2#!#3 +6#!#LineString 5pts#!#0#!#5 +7#!#Polygon triangle#!#1#!#4 +8#!#Polygon square#!#0#!#5 +9#!#Polygon with hole#!#5#!#10 +10#!#Empty Point#!#5#!#-1 +11#!#Empty LineString#!#5#!#-1 +12#!#Empty Polygon#!#5#!#-1 +13#!#Point Z#!#4#!#1 +14#!#Empty Point#!#5#!#-1 +15#!#Empty LineString#!#5#!#-1 +16#!#Empty Polygon#!#5#!#-1 +~~END~~ + + --Parse functions test -- geometry::Parse with POINT DECLARE @geomText NVARCHAR(MAX); @@ -95,11 +968,15 @@ int#!#nvarchar ~~END~~ -SELECT ID, geography::Parse(GeogColumn.STAsText()).STAsText() AS ParsedGeog FROM TestGeospatialParse_GeogTemp ORDER BY ID; +SELECT ID, geography::Parse(GeogColumn.STAsText()).STAsText() AS ParsedGeog FROM TestGeospatialParse_GeogTemp3 ORDER BY ID; go -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: relation "testgeospatialparse_geogtemp" does not exist)~~ +~~START~~ +int#!#nvarchar +1#!#POINT(3 4) +2#!#LINESTRING(0 0,1 1) +3#!#POLYGON((0 0,0 2,2 2,2 0,0 0)) +4#!#POINT(47.651 -22.349) +~~END~~ -- Parse with STEquals in WHERE clause @@ -115,11 +992,12 @@ int DECLARE @searchText NVARCHAR(MAX); SET @searchText = 'POINT(3.0 4.0)'; -SELECT ID FROM TestGeospatialParse_GeogTemp WHERE geography::Parse(@searchText).STEquals(GeogColumn) = 1 ORDER BY ID; +SELECT ID FROM TestGeospatialParse_GeogTemp3 WHERE geography::Parse(@searchText).STEquals(GeogColumn) = 1 ORDER BY ID; go -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: relation "testgeospatialparse_geogtemp" does not exist)~~ +~~START~~ +int +1 +~~END~~ -- Parse with JOIN and STIntersects @@ -158,49 +1036,61 @@ int#!#varchar DECLARE @refText NVARCHAR(MAX); SET @refText = 'POINT(3.0 4.0)'; WITH ParseCTE AS ( - SELECT ID, geometry::Parse(@refText).STDistance(GeomColumn) AS Distance + SELECT ID, CAST(geometry::Parse(@refText).STDistance(GeomColumn) AS NUMERIC(20,6)) AS Distance FROM TestGeospatialParse_GeomTemp3 ) -SELECT * FROM ParseCTE WHERE Distance < 10.0 ORDER BY Distance; +SELECT * FROM ParseCTE WHERE Distance < 10.0 ORDER BY Distance, ID; go ~~START~~ -int#!#float -1#!#0.0 -3#!#2.23606797749979 -2#!#3.605551275463989 +int#!#numeric +1#!#0.000000 +3#!#2.236068 +2#!#3.605551 ~~END~~ + -- Parse with cross-database query (geometry) DECLARE @refText NVARCHAR(MAX); SET @refText = 'POINT(3.0 4.0)'; -SELECT ID, geometry::Parse(@refText).STDistance(GeomColumn) AS Distance -FROM TestGeospatialParse_DB.dbo.TestGeospatialParse_GeometryTable3ORDER BY ID; +SELECT ID, CAST(geometry::Parse(@refText).STDistance(GeomColumn) AS NUMERIC(20,6)) AS Distance +FROM TestGeospatialParse_DB.dbo.TestGeospatialParse_GeometryTable3 ORDER BY ID; go -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: syntax error near 'BY' at line 5 and character position 72)~~ +~~START~~ +int#!#numeric +1#!#0.000000 +2#!#2.236068 +3#!#3.605551 +4#!#2.828427 +5#!#0.707107 +7#!#2.236068 +9#!#2.236068 +10#!#2.828427 +12#!#2.828427 +13#!#3.605551 +15#!#3.605551 +~~END~~ -- Parse with cross-database query (geography) DECLARE @refText NVARCHAR(MAX); SET @refText = 'POINT(3.0 4.0)'; -SELECT ID, geography::Parse(@refText).STDistance(GeogColumn) AS Distance +SELECT ID, CAST(geography::Parse(@refText).STDistance(GeogColumn) AS NUMERIC(20,6)) AS Distance FROM TestGeospatialParse_DB.dbo.TestGeospatialParse_GeographyTable3 ORDER BY ID; go ~~START~~ -int#!#float -1#!#0.0 -2#!#247520.76060020996 -3#!#399384.36945885984 -4#!#313588.39721259556 -5#!#77836.58790621723 -6#!#247520.76060020996 -8#!#247520.76060020996 -9#!#313588.39721259556 -11#!#313588.39721259556 -12#!#399384.36945885984 -14#!#399384.36945885984 +int#!#numeric +1#!#0.000000 +2#!#247520.760600 +3#!#399384.369459 +4#!#313588.397213 +5#!#77836.587906 +6#!#247520.760600 +8#!#247520.760600 +9#!#313588.397213 +11#!#313588.397213 +12#!#399384.369459 +14#!#399384.369459 ~~END~~ @@ -540,16 +1430,24 @@ LINESTRING(0 0,1 1) -- UNION with Parse -SELECT geometry::Parse('POINT(1 2)').STAsText() AS geom -UNION -SELECT geometry::Parse('POINT(3 4)').STAsText() -UNION -SELECT geometry::Parse('NULL').STAsText(); -ORDER BY geom DESC; +-- UNION with Parse +SELECT * FROM ( + SELECT geometry::Parse('POINT(1 2)').STAsText() AS geom + UNION + SELECT geometry::Parse('POINT(3 4)').STAsText() AS geom + UNION + SELECT geometry::Parse('NULL').STAsText() AS geom +) t +ORDER BY CASE WHEN geom IS NULL THEN 1 ELSE 0 END, geom DESC; go -~~ERROR (Code: 33557097)~~ +~~START~~ +nvarchar +POINT(3 4) +POINT(1 2) + +~~END~~ + -~~ERROR (Message: syntax error near 'ORDER' at line 7 and character position 0)~~ -- GROUP BY with spatial type @@ -569,16 +1467,16 @@ Polygon#!#1 -- Window function with Parse SELECT ID, - geometry::Parse('POINT(0 0)').STDistance(GeomColumn) AS Distance, - ROW_NUMBER() OVER (ORDER BY geometry::Parse('POINT(0 0)').STDistance(GeomColumn)) AS RowNum + CAST(geometry::Parse('POINT(0 0)').STDistance(GeomColumn) AS NUMERIC(20,6)) AS Distance, + ROW_NUMBER() OVER (ORDER BY geometry::Parse('POINT(0 0)').STDistance(GeomColumn), ID) AS RowNum FROM TestGeospatialParse_GeomTemp3; go ~~START~~ -int#!#float#!#bigint -2#!#0.0#!#1 -3#!#0.0#!#2 -1#!#5.0#!#3 -4#!#52.63169769255026#!#4 +int#!#numeric#!#bigint +2#!#0.000000#!#1 +3#!#0.000000#!#2 +1#!#5.000000#!#3 +4#!#52.631698#!#4 ~~END~~ @@ -1990,12 +2888,14 @@ DECLARE @geom geometry = geometry::STGeomFromText('LINESTRING(0 0, 10 10)', 4326 DECLARE @geog geography = geography::STGeomFromText('POINT(-122.34 47.65)', 4326); SELECT 'Geometry' AS Source, @geom.STGeometryType() AS Type UNION ALL -SELECT 'Geography', @geog.STGeometryType(); +SELECT 'Geography', @geog.STGeometryType() ORDER BY Source; go -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: syntax error near 'ORDER' at line 7 and character position 0)~~ +~~START~~ +varchar#!#nvarchar +Geography#!#Point +Geometry#!#LineString +~~END~~ -- SRID 999999 diff --git a/test/JDBC/expected/parallel_query/Numeric_Decimal_tests.out b/test/JDBC/expected/parallel_query/Numeric_Decimal_tests.out index fe6b3e9be43..6dc8f172ad2 100644 --- a/test/JDBC/expected/parallel_query/Numeric_Decimal_tests.out +++ b/test/JDBC/expected/parallel_query/Numeric_Decimal_tests.out @@ -4884,34 +4884,38 @@ GO -- GEOMETRY -> NUMERIC SELECT CAST(GEOMETRY::STGeomFromText('LINESTRING(0 0, 1 1, 2 2)', 0).STNumPoints() AS NUMERIC(10,0)); GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: syntax error at or near ".")~~ +~~START~~ +numeric +3 +~~END~~ -- GEOMETRY -> DECIMAL SELECT CAST(GEOMETRY::STGeomFromText('LINESTRING(0 0, 1 1, 2 2)', 0).STNumPoints() AS DECIMAL(10,0)); GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: syntax error at or near ".")~~ +~~START~~ +numeric +3 +~~END~~ -- GEOGRAPHY -> NUMERIC/DECIMAL (using STNumPoints() method) -- GEOGRAPHY -> NUMERIC SELECT CAST(GEOGRAPHY::STGeomFromText('LINESTRING(-122.34 47.65, -122.35 47.66)', 4326).STNumPoints() AS NUMERIC(10,0)); GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: syntax error at or near ".")~~ +~~START~~ +numeric +2 +~~END~~ -- GEOGRAPHY -> DECIMAL SELECT CAST(GEOGRAPHY::STGeomFromText('LINESTRING(-122.34 47.65, -122.35 47.66)', 4326).STNumPoints() AS DECIMAL(10,0)); GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: syntax error at or near ".")~~ +~~START~~ +numeric +2 +~~END~~ -- ROWVERSION/TIMESTAMP -> NUMERIC/DECIMAL @@ -5807,33 +5811,37 @@ GO -- GEOMETRY -> NUMERIC using CONVERT SELECT CONVERT(NUMERIC(10,0), GEOMETRY::STGeomFromText('LINESTRING(0 0, 1 1, 2 2)', 0).STNumPoints()); GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: syntax error at or near ".")~~ +~~START~~ +numeric +3 +~~END~~ -- GEOMETRY -> DECIMAL using CONVERT SELECT CONVERT(DECIMAL(10,0), GEOMETRY::STGeomFromText('LINESTRING(0 0, 1 1, 2 2)', 0).STNumPoints()); GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: syntax error at or near ".")~~ +~~START~~ +numeric +3 +~~END~~ -- GEOGRAPHY -> NUMERIC using CONVERT SELECT CONVERT(NUMERIC(10,0), GEOGRAPHY::STGeomFromText('LINESTRING(-122.34 47.65, -122.35 47.66)', 4326).STNumPoints()); GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: syntax error at or near ".")~~ +~~START~~ +numeric +2 +~~END~~ -- GEOGRAPHY -> DECIMAL using CONVERT SELECT CONVERT(DECIMAL(10,0), GEOGRAPHY::STGeomFromText('LINESTRING(-122.34 47.65, -122.35 47.66)', 4326).STNumPoints()); GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: syntax error at or near ".")~~ +~~START~~ +numeric +2 +~~END~~ -- ROWVERSION/TIMESTAMP -> NUMERIC/DECIMAL using CONVERT diff --git a/test/JDBC/input/datatypes/Test-spatial-functions-3-vu-cleanup.txt b/test/JDBC/input/datatypes/Test-spatial-functions-3-vu-cleanup.txt index 56f1c67de89..a382e0526e0 100644 --- a/test/JDBC/input/datatypes/Test-spatial-functions-3-vu-cleanup.txt +++ b/test/JDBC/input/datatypes/Test-spatial-functions-3-vu-cleanup.txt @@ -1,3 +1,21 @@ +USE TestSTNumPoints_DB; + +DROP VIEW STNumPoints_geog_view_db; +DROP VIEW STNumPoints_geom_view_db; + +DROP TABLE STNumPoints_geog_test_db; +DROP TABLE STNumPoints_geom_test_db; + +USE MASTER; + +DROP VIEW STNumPoints_geog_view; +DROP VIEW STNumPoints_geom_view; + +DROP TABLE STNumPoints_geog_test; +DROP TABLE STNumPoints_geom_test; + +DROP DATABASE TestSTNumPoints_DB; + USE TestGeospatialParse_DB DROP TABLE TestGeospatialParse_GeometryTable3 diff --git a/test/JDBC/input/datatypes/Test-spatial-functions-3-vu-prepare.txt b/test/JDBC/input/datatypes/Test-spatial-functions-3-vu-prepare.txt index c567213b767..ef633e0e52a 100644 --- a/test/JDBC/input/datatypes/Test-spatial-functions-3-vu-prepare.txt +++ b/test/JDBC/input/datatypes/Test-spatial-functions-3-vu-prepare.txt @@ -1,3 +1,83 @@ +CREATE DATABASE TestSTNumPoints_DB; + +USE TestSTNumPoints_DB; + +CREATE TABLE STNumPoints_geom_test_db ( ID INT PRIMARY KEY, geom_type VARCHAR(50), geom geometry); + +INSERT INTO STNumPoints_geom_test_db (ID, geom_type, geom) VALUES (1, 'Point', geometry::STPointFromText('POINT(0 0)', 0)); +INSERT INTO STNumPoints_geom_test_db (ID, geom_type, geom) VALUES (2, 'Point with SRID', geometry::STPointFromText('POINT(-122.349 47.651)', 4326)); +INSERT INTO STNumPoints_geom_test_db (ID, geom_type, geom) VALUES (3, 'Point constructor', geometry::Point(3.0, 4.0, 4326)); +INSERT INTO STNumPoints_geom_test_db (ID, geom_type, geom) VALUES (4, 'LineString 2pts', geometry::STGeomFromText('LINESTRING(0 0, 1 1)', 0)); +INSERT INTO STNumPoints_geom_test_db (ID, geom_type, geom) VALUES (5, 'LineString 3pts', geometry::STGeomFromText('LINESTRING(0 0, 1 1, 2 2)', 0)); +INSERT INTO STNumPoints_geom_test_db (ID, geom_type, geom) VALUES (6, 'LineString 5pts', geometry::STGeomFromText('LINESTRING(0 0, 1 1, 2 2, 3 3, 4 4)', 0)); +INSERT INTO STNumPoints_geom_test_db (ID, geom_type, geom) VALUES (7, 'Polygon triangle', geometry::STGeomFromText('POLYGON((0 0, 1 0, 0 1, 0 0))', 0)); +INSERT INTO STNumPoints_geom_test_db (ID, geom_type, geom) VALUES (8, 'Polygon square', geometry::STGeomFromText('POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))', 0)); +INSERT INTO STNumPoints_geom_test_db (ID, geom_type, geom) VALUES (9, 'Polygon with hole', geometry::STGeomFromText('POLYGON((0 0, 10 0, 10 10, 0 10, 0 0), (2 2, 8 2, 8 8, 2 8, 2 2))', 0)); +INSERT INTO STNumPoints_geom_test_db (ID, geom_type, geom) VALUES (10, 'Empty Point', geometry::STGeomFromText('POINT EMPTY', 0)); +INSERT INTO STNumPoints_geom_test_db (ID, geom_type, geom) VALUES (11, 'Empty LineString', geometry::STGeomFromText('LINESTRING EMPTY', 0)); +INSERT INTO STNumPoints_geom_test_db (ID, geom_type, geom) VALUES (12, 'Empty Polygon', geometry::STGeomFromText('POLYGON EMPTY', 0)); +INSERT INTO STNumPoints_geom_test_db (ID, geom_type, geom) VALUES (13, 'Point Z', geometry::STGeomFromText('POINT Z(1 2 3)', 0)); +INSERT INTO STNumPoints_geom_test_db (ID, geom_type, geom) VALUES (14, 'Empty Point', geometry::STGeomFromText('POINT EMPTY', 0)); +INSERT INTO STNumPoints_geom_test_db (ID, geom_type, geom) VALUES (15, 'Empty LineString', geometry::STGeomFromText('LINESTRING EMPTY', 0)); +INSERT INTO STNumPoints_geom_test_db (ID, geom_type, geom) VALUES (16, 'Empty Polygon', geometry::STGeomFromText('POLYGON EMPTY', 0)); + +CREATE TABLE STNumPoints_geog_test_db ( ID INT PRIMARY KEY, geog_type VARCHAR(50), geog geography ); + +INSERT INTO STNumPoints_geog_test_db (ID, geog_type, geog) VALUES (1, 'Point', geography::STPointFromText('POINT(-122.349 47.651)', 4326)); +INSERT INTO STNumPoints_geog_test_db (ID, geog_type, geog) VALUES (2, 'Point constructor', geography::Point(47.651, -122.349, 4326)); +INSERT INTO STNumPoints_geog_test_db (ID, geog_type, geog) VALUES (3, 'LineString 2pts', geography::STGeomFromText('LINESTRING(-122.36 47.65, -122.34 47.66)', 4326)); +INSERT INTO STNumPoints_geog_test_db (ID, geog_type, geog) VALUES (4, 'LineString 3pts', geography::STGeomFromText('LINESTRING(-122.36 47.65, -122.34 47.66, -122.32 47.67)', 4326)); +INSERT INTO STNumPoints_geog_test_db (ID, geog_type, geog) VALUES (5, 'LineString 5pts', geography::STGeomFromText('LINESTRING(-122.36 47.65, -122.35 47.66, -122.34 47.67, -122.33 47.68, -122.32 47.69)', 4326)); +INSERT INTO STNumPoints_geog_test_db (ID, geog_type, geog) VALUES (6, 'Polygon triangle', geography::STGeomFromText('POLYGON((-122.36 47.65, -122.34 47.65, -122.35 47.67, -122.36 47.65))', 4326)); +INSERT INTO STNumPoints_geog_test_db (ID, geog_type, geog) VALUES (7, 'Polygon square', geography::STGeomFromText('POLYGON((-122.36 47.65, -122.34 47.65, -122.34 47.67, -122.36 47.67, -122.36 47.65))', 4326)); +INSERT INTO STNumPoints_geog_test_db (ID, geog_type, geog) VALUES (8, 'Empty Point', geography::STGeomFromText('POINT EMPTY', 4326)); +INSERT INTO STNumPoints_geog_test_db (ID, geog_type, geog) VALUES (9, 'Empty LineString', geography::STGeomFromText('LINESTRING EMPTY', 4326)); +INSERT INTO STNumPoints_geog_test_db (ID, geog_type, geog) VALUES (10, 'Point Z', geography::STGeomFromText('POINT Z(-122.349 47.651 100)', 4326)); +INSERT INTO STNumPoints_geog_test_db (ID, geog_type, geog) VALUES (11, 'Empty Point', geography::STGeomFromText('POINT EMPTY', 4326)); +INSERT INTO STNumPoints_geog_test_db (ID, geog_type, geog) VALUES (12, 'Empty LineString', geography::STGeomFromText('LINESTRING EMPTY', 4326)); + +CREATE VIEW STNumPoints_geom_view_db AS SELECT ID, geom_type, geom.STNumPoints() AS num_points FROM STNumPoints_geom_test_db; + +CREATE VIEW STNumPoints_geog_view_db AS SELECT ID, geog_type, geog.STNumPoints() AS num_points FROM STNumPoints_geog_test_db; + +USE MASTER + +CREATE TABLE STNumPoints_geom_test ( ID INT PRIMARY KEY, geom_type VARCHAR(50), geom geometry ); + +INSERT INTO STNumPoints_geom_test (ID, geom_type, geom) VALUES (1, 'Point', geometry::STPointFromText('POINT(0 0)', 0)); +INSERT INTO STNumPoints_geom_test (ID, geom_type, geom) VALUES (2, 'Point with SRID', geometry::STPointFromText('POINT(-122.349 47.651)', 4326)); +INSERT INTO STNumPoints_geom_test (ID, geom_type, geom) VALUES (3, 'Point constructor', geometry::Point(3.0, 4.0, 4326)); +INSERT INTO STNumPoints_geom_test (ID, geom_type, geom) VALUES (4, 'LineString 2pts', geometry::STGeomFromText('LINESTRING(0 0, 1 1)', 0)); +INSERT INTO STNumPoints_geom_test (ID, geom_type, geom) VALUES (5, 'LineString 3pts', geometry::STGeomFromText('LINESTRING(0 0, 1 1, 2 2)', 0)); +INSERT INTO STNumPoints_geom_test (ID, geom_type, geom) VALUES (6, 'LineString 5pts', geometry::STGeomFromText('LINESTRING(0 0, 1 1, 2 2, 3 3, 4 4)', 0)); +INSERT INTO STNumPoints_geom_test (ID, geom_type, geom) VALUES (7, 'Polygon triangle', geometry::STGeomFromText('POLYGON((0 0, 1 0, 0 1, 0 0))', 0)); +INSERT INTO STNumPoints_geom_test (ID, geom_type, geom) VALUES (8, 'Polygon square', geometry::STGeomFromText('POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))', 0)); +INSERT INTO STNumPoints_geom_test (ID, geom_type, geom) VALUES (9, 'Polygon with hole', geometry::STGeomFromText('POLYGON((0 0, 10 0, 10 10, 0 10, 0 0), (2 2, 8 2, 8 8, 2 8, 2 2))', 0)); +INSERT INTO STNumPoints_geom_test (ID, geom_type, geom) VALUES (10, 'Empty Point', geometry::STGeomFromText('POINT EMPTY', 0)); +INSERT INTO STNumPoints_geom_test (ID, geom_type, geom) VALUES (11, 'Empty LineString', geometry::STGeomFromText('LINESTRING EMPTY', 0)); +INSERT INTO STNumPoints_geom_test (ID, geom_type, geom) VALUES (12, 'Empty Polygon', geometry::STGeomFromText('POLYGON EMPTY', 0)); +INSERT INTO STNumPoints_geom_test (ID, geom_type, geom) VALUES (13, 'Point Z', geometry::STGeomFromText('POINT Z(1 2 3)', 0)); +INSERT INTO STNumPoints_geom_test (ID, geom_type, geom) VALUES (14, 'Empty Point', geometry::STGeomFromText('POINT EMPTY', 0)); +INSERT INTO STNumPoints_geom_test (ID, geom_type, geom) VALUES (15, 'Empty LineString', geometry::STGeomFromText('LINESTRING EMPTY', 0)); +INSERT INTO STNumPoints_geom_test (ID, geom_type, geom) VALUES (16, 'Empty Polygon', geometry::STGeomFromText('POLYGON EMPTY', 0)); + +CREATE TABLE STNumPoints_geog_test ( ID INT PRIMARY KEY, geog_type VARCHAR(50), geog geography ); +INSERT INTO STNumPoints_geog_test (ID, geog_type, geog) VALUES (1, 'Point', geography::STPointFromText('POINT(-122.349 47.651)', 4326)); +INSERT INTO STNumPoints_geog_test (ID, geog_type, geog) VALUES (2, 'Point constructor', geography::Point(47.651, -122.349, 4326)); +INSERT INTO STNumPoints_geog_test (ID, geog_type, geog) VALUES (3, 'LineString 2pts', geography::STGeomFromText('LINESTRING(-122.36 47.65, -122.34 47.66)', 4326)); +INSERT INTO STNumPoints_geog_test (ID, geog_type, geog) VALUES (4, 'LineString 3pts', geography::STGeomFromText('LINESTRING(-122.36 47.65, -122.34 47.66, -122.32 47.67)', 4326)); +INSERT INTO STNumPoints_geog_test (ID, geog_type, geog) VALUES (5, 'LineString 5pts', geography::STGeomFromText('LINESTRING(-122.36 47.65, -122.35 47.66, -122.34 47.67, -122.33 47.68, -122.32 47.69)', 4326)); +INSERT INTO STNumPoints_geog_test (ID, geog_type, geog) VALUES (6, 'Polygon triangle', geography::STGeomFromText('POLYGON((-122.36 47.65, -122.34 47.65, -122.35 47.67, -122.36 47.65))', 4326)); +INSERT INTO STNumPoints_geog_test (ID, geog_type, geog) VALUES (7, 'Polygon square', geography::STGeomFromText('POLYGON((-122.36 47.65, -122.34 47.65, -122.34 47.67, -122.36 47.67, -122.36 47.65))', 4326)); +INSERT INTO STNumPoints_geog_test (ID, geog_type, geog) VALUES (8, 'Empty Point', geography::STGeomFromText('POINT EMPTY', 4326)); +INSERT INTO STNumPoints_geog_test (ID, geog_type, geog) VALUES (9, 'Empty LineString', geography::STGeomFromText('LINESTRING EMPTY', 4326)); +INSERT INTO STNumPoints_geog_test (ID, geog_type, geog) VALUES (10, 'Point Z', geography::STGeomFromText('POINT Z(-122.349 47.651 100)', 4326)); +INSERT INTO STNumPoints_geog_test (ID, geog_type, geog) VALUES (11, 'Empty Point', geography::STGeomFromText('POINT EMPTY', 4326)); +INSERT INTO STNumPoints_geog_test (ID, geog_type, geog) VALUES (12, 'Empty LineString', geography::STGeomFromText('LINESTRING EMPTY', 4326)); + +CREATE VIEW STNumPoints_geom_view AS SELECT ID, geom_type, geom.STNumPoints() AS num_points FROM STNumPoints_geom_test; + +CREATE VIEW STNumPoints_geog_view AS SELECT ID, geog_type, geog.STNumPoints() AS num_points FROM STNumPoints_geog_test; CREATE DATABASE TestGeospatialParse_DB; USE TestGeospatialParse_DB; diff --git a/test/JDBC/input/datatypes/Test-spatial-functions-3-vu-verify.sql b/test/JDBC/input/datatypes/Test-spatial-functions-3-vu-verify.sql index 26335e88cbf..408570a250c 100644 --- a/test/JDBC/input/datatypes/Test-spatial-functions-3-vu-verify.sql +++ b/test/JDBC/input/datatypes/Test-spatial-functions-3-vu-verify.sql @@ -1,3 +1,326 @@ +--STNumPoints() + +USE TestSTNumPoints_DB; +GO + +-- View tests +SELECT * FROM STNumPoints_geom_view_db ORDER BY ID; +go +SELECT * FROM STNumPoints_geog_view_db ORDER BY ID; +go + +-- JOIN test (geom + geog, both DB tables) +SELECT g.ID, g.geom_type, gg.geog_type, + g.geom.STNumPoints() AS geom_pts, gg.geog.STNumPoints() AS geog_pts +FROM STNumPoints_geom_test_db g +JOIN STNumPoints_geog_test_db gg ON g.ID = gg.ID +ORDER BY g.ID; +go + +-- CTE test +WITH PointCTE AS ( + SELECT ID, geom_type, geom.STNumPoints() AS num_points FROM STNumPoints_geom_test_db +) +SELECT * FROM PointCTE WHERE num_points > 0 ORDER BY num_points DESC, geom_type; +go + +-- CTE with Window Functions +WITH RankedGeom AS ( + SELECT ID, geom_type, geom.STNumPoints() AS num_points, + ROW_NUMBER() OVER (ORDER BY geom.STNumPoints() DESC, ID) AS row_num, + RANK() OVER (ORDER BY geom.STNumPoints() DESC, ID) AS rnk, + SUM(geom.STNumPoints()) OVER () AS total_pts + FROM STNumPoints_geom_test_db +) +SELECT * FROM RankedGeom ORDER BY row_num; +go + +-- GROUP BY test +SELECT geom_type, COUNT(*) AS cnt, SUM(geom.STNumPoints()) AS total_pts +FROM STNumPoints_geom_test_db +GROUP BY geom_type +ORDER BY total_pts DESC, geom_type; +go + +-- ORDER BY test +SELECT ID, geom_type, geom.STNumPoints() AS num_points +FROM STNumPoints_geom_test_db +ORDER BY num_points DESC, ID ASC; +go + +-- Nested functions test +SELECT ID, geom_type, + ABS(geom.STNumPoints() - 5) AS diff_from_5, + COALESCE(NULLIF(geom.STNumPoints(), 0), -1) AS pts_or_neg1 +FROM STNumPoints_geom_test_db +ORDER BY ID; +go + +USE MASTER; +go + +-- Test STNumPoints() on geometry table with various geometry types +SELECT + ID, + geom_type, + geom.STNumPoints() AS actual_result, + CASE ID + WHEN 1 THEN 1 + WHEN 2 THEN 1 + WHEN 3 THEN 1 + WHEN 4 THEN 2 + WHEN 5 THEN 3 + WHEN 6 THEN 5 + WHEN 7 THEN 4 + WHEN 8 THEN 5 + WHEN 9 THEN 10 + WHEN 10 THEN 0 + WHEN 11 THEN 0 + WHEN 12 THEN 0 + WHEN 13 THEN 1 + WHEN 14 THEN 0 + WHEN 15 THEN 0 + WHEN 16 THEN 0 + END AS expected_result +FROM STNumPoints_geom_test +ORDER BY ID; + +-- Test STNumPoints() with STPointFromText +DECLARE @point geometry; +SET @point = geometry::STPointFromText('POINT(-122.34900 47.65100)', 4326); +SELECT @point.STNumPoints(); +go + +DECLARE @point geometry; +SET @point = geometry::Point(22.34900, -47.65100, 4326); +SELECT @point.STNumPoints ( ); +go + +-- Test STNumPoints() on geography table with various geography types +SELECT + ID, + geog_type, + geog.STNumPoints() AS actual_result, + CASE ID + WHEN 1 THEN 1 + WHEN 2 THEN 1 + WHEN 3 THEN 2 + WHEN 4 THEN 3 + WHEN 5 THEN 5 + WHEN 6 THEN 4 + WHEN 7 THEN 5 + WHEN 8 THEN 0 + WHEN 9 THEN 0 + WHEN 10 THEN 1 + + WHEN 11 THEN 0 + WHEN 12 THEN 0 + END AS expected_result +FROM STNumPoints_geog_test +ORDER BY ID; +go + +DECLARE @point geography; +SET @point = geography::STPointFromText('POINT(-122.34900 47.65100)', 4326); +SELECT @point.STNumPoints(); +go + +DECLARE @point geography; +SET @point = geography::Point(47.65100, -122.34900, 4326); +SELECT @point . STNumPoints ( ); +go + +-- Test STNumPoints() on NULL geometry +DECLARE @nullGeom geometry; +SELECT @nullGeom.STNumPoints() AS null_geometry_result; +go + +-- Test STNumPoints() on empty point +DECLARE @g geometry; +SET @g = geometry::STGeomFromText('POINT EMPTY', 0); +SELECT @g.STNumPoints() AS empty_point_geometry; +go + +DECLARE @g geography; +SET @g = geography::STGeomFromText('POINT EMPTY', 4326); +SELECT @g.STNumPoints() AS empty_point_geography; +go + +-- Test STNumPoints() with CAST from VARCHAR +SELECT CAST(CAST('POINT EMPTY' AS VARCHAR(100)) AS geography).STNumPoints() AS cast_varchar_result; +go + +-- Test STNumPoints() with CAST from CHAR +SELECT CAST(CAST('POINT EMPTY' AS CHAR(100)) AS geography).STNumPoints() AS cast_char_result; +go + +-- Test STNumPoints() via geometry view +SELECT * FROM STNumPoints_geom_view ORDER BY ID; +go + +-- Test STNumPoints() via geography view +SELECT * FROM STNumPoints_geog_view ORDER BY ID; +go + +-- Test STNumPoints() with different SRIDs for geometry +DECLARE @point1 geometry = geometry::STPointFromText('POINT(-122.349 47.651)', 4326); +DECLARE @point2 geometry = geometry::STPointFromText('POINT(-122.349 47.651)', 0); +DECLARE @point3 geometry = geometry::STPointFromText('POINT(-122.349 47.651)', 999999); +SELECT + @point1.STNumPoints() AS srid_4326, + @point2.STNumPoints() AS srid_0, + @point3.STNumPoints() AS srid_999999; +go + +-- Test STNumPoints() with different SRIDs for geography +DECLARE @point1 geography = geography::STPointFromText('POINT(-122.349 47.651)', 4326); +DECLARE @point2 geography = geography::STPointFromText('POINT(-122.349 47.651)', 4204); +SELECT + @point1.STNumPoints() AS srid_4326, + @point2.STNumPoints() AS srid_4204; +go + +-- Test STNumPoints() on LineString +DECLARE @line geometry; +SET @line = geometry::STGeomFromText('LINESTRING(0 0, 1 1, 2 2)', 0); +SELECT @line.STNumPoints(); +go + +-- Test STNumPoints() on simple Polygon +DECLARE @poly geometry; +SET @poly = geometry::STGeomFromText('POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))', 0); +SELECT @poly.STNumPoints(); +go + +-- Test STNumPoints() on Polygon with hole +DECLARE @poly geometry; +SET @poly = geometry::STGeomFromText('POLYGON((0 0, 10 0, 10 10, 0 10, 0 0), (2 2, 8 2, 8 8, 2 8, 2 2))', 0); +SELECT @poly.STNumPoints(); +go + +-- Test STNumPoints() on Point with Z coordinate (geometry) +DECLARE @pointZ geometry; +SET @pointZ = geometry::STGeomFromText('POINT(0 0 5)', 0); +SELECT @pointZ.STNumPoints(); +go + +-- Test STNumPoints() on Point with Z coordinate (geography) +DECLARE @pointZ geography; +SET @pointZ = geography::STGeomFromText('POINT(-122.34 47.65 100)', 4326); +SELECT @pointZ.STNumPoints(); +go + +-- Test STNumPoints() on Point with M coordinate +DECLARE @pointM geometry; +SET @pointM = geometry::STGeomFromText('POINT(0 0 NULL 5)', 0); +SELECT @pointM.STNumPoints(); +go + +-- Test STNumPoints() on LineString with Z coordinates +DECLARE @lineZ geometry; +SET @lineZ = geometry::STGeomFromText('LINESTRING(0 0 0, 1 1 1, 2 2 2)', 0); +SELECT @lineZ.STNumPoints(); +go + +-- UNION test +SELECT 'geometry' AS source, geom.STNumPoints() AS num_points FROM STNumPoints_geom_test WHERE ID <= 3 +UNION ALL +SELECT 'geography' AS source, geog.STNumPoints() AS num_points FROM STNumPoints_geog_test WHERE ID <= 3 +ORDER BY source, num_points; +go + + +SELECT g1.ID, g1.geom_type, g1.geom.STNumPoints() AS geom_points, + g2.ID, g2.geog_type, g2.geog.STNumPoints() AS geog_points +FROM STNumPoints_geom_test g1 +JOIN STNumPoints_geog_test g2 ON g1.geom.STNumPoints() = g2.geog.STNumPoints() +WHERE g1.ID <= 5 AND g2.ID <= 5 +ORDER BY g1.ID, g2.ID; +go + +-- Geometry WHERE/ORDER BY/GROUP BY tests +SELECT ID, geom_type FROM STNumPoints_geom_test WHERE geom.STNumPoints() BETWEEN 2 AND 5 ORDER BY ID; +go +SELECT geom.STNumPoints() AS num_points, COUNT(*) AS count FROM STNumPoints_geom_test GROUP BY geom.STNumPoints() HAVING COUNT(*) > 1 ORDER BY num_points; +go + +-- Geography WHERE/ORDER BY/GROUP BY tests +SELECT ID, geog_type FROM STNumPoints_geog_test WHERE geog.STNumPoints() BETWEEN 2 AND 5 ORDER BY ID; +go +SELECT geog.STNumPoints() AS num_points, COUNT(*) AS count FROM STNumPoints_geog_test GROUP BY geog.STNumPoints() HAVING COUNT(*) > 1 ORDER BY num_points; +go + +-- Geometry CTE test +WITH GeomCTE AS ( + SELECT ID, geom_type, geom.STNumPoints() AS num_points FROM STNumPoints_geom_test +) +SELECT * FROM GeomCTE WHERE num_points > 0 ORDER BY num_points, ID; +go + +-- Geometry Window test +SELECT ID, geom_type, geom.STNumPoints() AS num_points, + ROW_NUMBER() OVER (ORDER BY geom.STNumPoints() DESC) AS row_num +FROM STNumPoints_geom_test ORDER BY row_num; +go + +-- Geography CTE test +WITH GeogCTE AS ( + SELECT ID, geog_type, geog.STNumPoints() AS num_points FROM STNumPoints_geog_test +) +SELECT * FROM GeogCTE WHERE num_points > 0 ORDER BY num_points, ID; +go + +-- Geography Window test +SELECT ID, geog_type, geog.STNumPoints() AS num_points, + ROW_NUMBER() OVER (ORDER BY geog.STNumPoints() DESC, ID) AS row_num +FROM STNumPoints_geog_test ORDER BY row_num; +go + +-- View tests +SELECT * FROM STNumPoints_geom_view ORDER BY ID; +go +SELECT * FROM STNumPoints_geog_view ORDER BY ID; +go + +-- JOIN test (geom + geog, both MASTER tables) +SELECT g.ID, g.geom_type, gg.geog_type, + g.geom.STNumPoints() AS geom_pts, gg.geog.STNumPoints() AS geog_pts +FROM STNumPoints_geom_test g +JOIN STNumPoints_geog_test gg ON g.ID = gg.ID +ORDER BY g.ID; +go + +-- CTE with Window Functions +WITH RankedGeom AS ( + SELECT ID, geom_type, geom.STNumPoints() AS num_points, + ROW_NUMBER() OVER (ORDER BY geom.STNumPoints() DESC) AS row_num, + RANK() OVER (ORDER BY geom.STNumPoints() DESC) AS rnk, + SUM(geom.STNumPoints()) OVER () AS total_pts + FROM STNumPoints_geom_test +) +SELECT * FROM RankedGeom ORDER BY row_num; +go + +-- GROUP BY test +SELECT geom_type, COUNT(*) AS cnt, SUM(geom.STNumPoints()) AS total_pts +FROM STNumPoints_geom_test +GROUP BY geom_type +ORDER BY total_pts DESC, geom_type; +go + +-- ORDER BY test +SELECT ID, geom_type, geom.STNumPoints() AS num_points +FROM STNumPoints_geom_test +ORDER BY num_points DESC, ID ASC; +go + +-- Nested functions test +SELECT ID, geom_type, + ABS(geom.STNumPoints() - 5) AS diff_from_5, + COALESCE(NULLIF(geom.STNumPoints(), 0), -1) AS pts_or_neg1 +FROM STNumPoints_geom_test +ORDER BY ID; +go --Parse functions test -- geometry::Parse with POINT @@ -47,7 +370,7 @@ go SELECT ID, geometry::Parse(GeomColumn.STAsText()).STAsText() AS ParsedGeom FROM TestGeospatialParse_GeomTemp3 ORDER BY ID; go -SELECT ID, geography::Parse(GeogColumn.STAsText()).STAsText() AS ParsedGeog FROM TestGeospatialParse_GeogTemp ORDER BY ID; +SELECT ID, geography::Parse(GeogColumn.STAsText()).STAsText() AS ParsedGeog FROM TestGeospatialParse_GeogTemp3 ORDER BY ID; go -- Parse with STEquals in WHERE clause @@ -58,7 +381,7 @@ go DECLARE @searchText NVARCHAR(MAX); SET @searchText = 'POINT(3.0 4.0)'; -SELECT ID FROM TestGeospatialParse_GeogTemp WHERE geography::Parse(@searchText).STEquals(GeogColumn) = 1 ORDER BY ID; +SELECT ID FROM TestGeospatialParse_GeogTemp3 WHERE geography::Parse(@searchText).STEquals(GeogColumn) = 1 ORDER BY ID; go -- Parse with JOIN and STIntersects @@ -81,23 +404,24 @@ go DECLARE @refText NVARCHAR(MAX); SET @refText = 'POINT(3.0 4.0)'; WITH ParseCTE AS ( - SELECT ID, geometry::Parse(@refText).STDistance(GeomColumn) AS Distance + SELECT ID, CAST(geometry::Parse(@refText).STDistance(GeomColumn) AS NUMERIC(20,6)) AS Distance FROM TestGeospatialParse_GeomTemp3 ) -SELECT * FROM ParseCTE WHERE Distance < 10.0 ORDER BY Distance; +SELECT * FROM ParseCTE WHERE Distance < 10.0 ORDER BY Distance, ID; go + -- Parse with cross-database query (geometry) DECLARE @refText NVARCHAR(MAX); SET @refText = 'POINT(3.0 4.0)'; -SELECT ID, geometry::Parse(@refText).STDistance(GeomColumn) AS Distance -FROM TestGeospatialParse_DB.dbo.TestGeospatialParse_GeometryTable3ORDER BY ID; +SELECT ID, CAST(geometry::Parse(@refText).STDistance(GeomColumn) AS NUMERIC(20,6)) AS Distance +FROM TestGeospatialParse_DB.dbo.TestGeospatialParse_GeometryTable3 ORDER BY ID; go -- Parse with cross-database query (geography) DECLARE @refText NVARCHAR(MAX); SET @refText = 'POINT(3.0 4.0)'; -SELECT ID, geography::Parse(@refText).STDistance(GeogColumn) AS Distance +SELECT ID, CAST(geography::Parse(@refText).STDistance(GeogColumn) AS NUMERIC(20,6)) AS Distance FROM TestGeospatialParse_DB.dbo.TestGeospatialParse_GeographyTable3 ORDER BY ID; go @@ -254,14 +578,19 @@ SELECT geography::Parse('lineString(0 0, 1 1)').STAsText(); go -- UNION with Parse -SELECT geometry::Parse('POINT(1 2)').STAsText() AS geom -UNION -SELECT geometry::Parse('POINT(3 4)').STAsText() -UNION -SELECT geometry::Parse('NULL').STAsText(); -ORDER BY geom DESC; +-- UNION with Parse +SELECT * FROM ( + SELECT geometry::Parse('POINT(1 2)').STAsText() AS geom + UNION + SELECT geometry::Parse('POINT(3 4)').STAsText() AS geom + UNION + SELECT geometry::Parse('NULL').STAsText() AS geom +) t +ORDER BY CASE WHEN geom IS NULL THEN 1 ELSE 0 END, geom DESC; go + + -- GROUP BY with spatial type SELECT GeomColumn.STGeometryType() AS GeomType, COUNT(*) AS Count @@ -272,8 +601,8 @@ go -- Window function with Parse SELECT ID, - geometry::Parse('POINT(0 0)').STDistance(GeomColumn) AS Distance, - ROW_NUMBER() OVER (ORDER BY geometry::Parse('POINT(0 0)').STDistance(GeomColumn)) AS RowNum + CAST(geometry::Parse('POINT(0 0)').STDistance(GeomColumn) AS NUMERIC(20,6)) AS Distance, + ROW_NUMBER() OVER (ORDER BY geometry::Parse('POINT(0 0)').STDistance(GeomColumn), ID) AS RowNum FROM TestGeospatialParse_GeomTemp3; go @@ -907,7 +1236,7 @@ DECLARE @geom geometry = geometry::STGeomFromText('LINESTRING(0 0, 10 10)', 4326 DECLARE @geog geography = geography::STGeomFromText('POINT(-122.34 47.65)', 4326); SELECT 'Geometry' AS Source, @geom.STGeometryType() AS Type UNION ALL -SELECT 'Geography', @geog.STGeometryType(); +SELECT 'Geography', @geog.STGeometryType() ORDER BY Source; go diff --git a/test/python/expected/upgrade_validation/expected_dependency.out b/test/python/expected/upgrade_validation/expected_dependency.out index beb860d7d0a..7b80eab37ea 100644 --- a/test/python/expected/upgrade_validation/expected_dependency.out +++ b/test/python/expected/upgrade_validation/expected_dependency.out @@ -684,6 +684,8 @@ Function sys.stintersects_helper(sys.geography,sys.geography) Function sys.stintersects_helper(sys.geometry,sys.geometry) Function sys.stisclosed_helper(sys.geography) Function sys.stisclosed_helper(sys.geometry) +Function sys.stnumpoints_helper(sys.geography) +Function sys.stnumpoints_helper(sys.geometry) Function sys.string_escape(sys.nvarchar,text) Function sys.string_split(character varying,character varying) Function sys.suser_id()