oglego commented on code in PR #802:
URL: https://github.com/apache/sedona-db/pull/802#discussion_r3175819692
##########
python/sedonadb/tests/functions/test_functions.py:
##########
@@ -2304,6 +2304,89 @@ def test_st_length(eng, geom, expected):
eng.assert_query_result(f"SELECT ST_Length({geom_or_null(geom)})",
expected)
[email protected]("eng", [SedonaDB, PostGIS])
[email protected](
+ ("geom", "expected"),
+ [
+ (None, None),
+ ("POINT EMPTY", "POINT EMPTY"),
+ ("LINESTRING EMPTY", "LINESTRING EMPTY"),
+ ("POLYGON EMPTY", "POLYGON EMPTY"),
+ ("MULTIPOINT EMPTY", "MULTIPOINT EMPTY"),
+ ("MULTILINESTRING EMPTY", "MULTILINESTRING EMPTY"),
+ ("MULTIPOLYGON EMPTY", "MULTIPOLYGON EMPTY"),
+ ("GEOMETRYCOLLECTION EMPTY", "GEOMETRYCOLLECTION EMPTY"),
+ ("POINT (0 0)", "POINT (0 0)"),
+ ("LINESTRING (0 0, 1 1)", "LINESTRING (0 0, 1 1)"),
+ (
+ "POLYGON ((1 1, 1 0, 0 0, 0 1, 1 1))",
+ "POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))",
+ ),
+ (
+ "POLYGON ((5 5, 5 0, 0 0, 0 5, 5 5), (4 4, 1 4, 1 1, 4 1, 4 4))",
+ "POLYGON ((0 0, 0 5, 5 5, 5 0, 0 0), (1 1, 4 1, 4 4, 1 4, 1 1))",
+ ),
+ ("MULTIPOINT ((2 2), (1 1), (0 0))", "MULTIPOINT ((2 2), (1 1), (0
0))"),
+ (
+ "MULTILINESTRING ((2 2, 1 1), (4 4, 3 3))",
+ "MULTILINESTRING ((3 3, 4 4), (1 1, 2 2))",
+ ),
+ (
+ "MULTIPOLYGON (((3 3, 3 2, 2 2, 2 3, 3 3)), ((1 1, 1 0, 0 0, 0 1,
1 1)))",
+ "MULTIPOLYGON (((2 2, 2 3, 3 3, 3 2, 2 2)), ((0 0, 0 1, 1 1, 1 0,
0 0)))",
+ ),
+ (
+ "GEOMETRYCOLLECTION (LINESTRING (2 2, 1 1), POLYGON ((1 1, 1 0, 0
0, 0 1, 1 1)), POINT (5 5))",
+ "GEOMETRYCOLLECTION (POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0)),
LINESTRING (1 1, 2 2), POINT (5 5))",
+ ),
+ # Already-normalized input should be unchanged
+ (
+ "POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))",
+ "POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))",
+ ),
+ # Z coordinates must survive normalization reordering
+ (
+ "POLYGON Z ((1 1 5, 1 0 5, 0 0 5, 0 1 5, 1 1 5))",
+ "POLYGON Z ((0 0 5, 0 1 5, 1 1 5, 1 0 5, 0 0 5))",
+ ),
+ # SedonaDB preserves M; PostGIS drops it during ST_Normalize in this
environment
+ (
+ "POLYGON M ((1 1 7, 1 0 7, 0 0 7, 0 1 7, 1 1 7))",
+ "POLYGON M ((0 0 7, 0 1 7, 1 1 7, 1 0 7, 0 0 7))",
+ ),
+ # SedonaDB preserves ZM; PostGIS drops M during ST_Normalize in this
environment
+ (
+ "POLYGON ZM ((1 1 5 7, 1 0 5 7, 0 0 5 7, 0 1 5 7, 1 1 5 7))",
+ "POLYGON ZM ((0 0 5 7, 0 1 5 7, 1 1 5 7, 1 0 5 7, 0 0 5 7))",
+ ),
+ ],
+)
+def test_st_normalize(eng, geom, expected):
+ eng = eng.create_or_skip()
+ if isinstance(eng, PostGIS):
+ # PostGIS drops M during ST_Normalize for these cases in our test
environment.
+ if geom == "POLYGON M ((1 1 7, 1 0 7, 0 0 7, 0 1 7, 1 1 7))":
+ expected = "POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))"
+ elif geom == "POLYGON ZM ((1 1 5 7, 1 0 5 7, 0 0 5 7, 0 1 5 7, 1 1 5
7))":
+ expected = "POLYGON Z ((0 0 5, 0 1 5, 1 1 5, 1 0 5, 0 0 5))"
+
+ if isinstance(eng, PostGIS) and expected is not None:
+ # Normalize expected WKT to PostGIS's compact ST_AsText formatting.
+ expected = expected.replace(", ", ",")
+ expected = expected.replace(" (", "(")
+ expected = expected.replace(r"ZM(", r"ZM (")
+ expected = expected.replace(r"M(", r"M (")
+ expected = expected.replace(r"Z(", r"Z (")
+
+ if isinstance(eng, SedonaDB) and expected is not None:
+ expected = expected.replace(", ", ",")
+ expected = expected.replace(" (", "(")
+
+ eng.assert_query_result(
+ f"SELECT ST_AsText(ST_Normalize({geom_or_null(geom)}))", expected
+ )
Review Comment:
Thank you for reviewing this, I really appreciate it! I tried the compact
version, but it led to formatting-only failures in the Python harness, for
example one of the diffs I ran into is:
E AssertionError: Expected:
E [('POLYGON Z ((0 0 5,0 1 5,1 1 5,1 0 5,0 0 5))',)]
E Got:
E [('POLYGON Z ((0 0 5, 0 1 5, 1 1 5, 1 0 5, 0 0 5))',)]
Without using `ST_AsText`, the failures seem to come from string formatting
in the test harness rather than from `ST_Normalize` behavior itself.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]