Skip to content

Commit 9657a5e

Browse files
authored
Add ST_SetCrs (#37)
* Split into ST_SetSRID and ST_SetCRS * Fix doc, update integration tests and allow null args * updates parquet integration tests to use st_setcrs
1 parent bfb46a6 commit 9657a5e

5 files changed

Lines changed: 197 additions & 67 deletions

File tree

python/sedonadb/tests/functions/test_transforms.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,17 @@ def test_st_setsrid(eng, geom, srid, expected_srid):
5050
assert df.crs == pyproj.CRS(expected_srid)
5151

5252

53-
# PostGIS does not handle String CRS input to ST_SetSrid
53+
# PostGIS does not have an API ST_SetCrs
5454
@pytest.mark.parametrize("eng", [SedonaDB])
5555
@pytest.mark.parametrize(
56-
("geom", "srid", "expected_srid"),
56+
("geom", "crs", "expected_srid"),
5757
[
5858
("POINT (1 1)", "EPSG:26920", 26920),
5959
("POINT (1 1)", pyproj.CRS("EPSG:26920").to_json(), 26920),
6060
],
6161
)
62-
def test_st_setsrid_sedonadb(eng, geom, srid, expected_srid):
62+
def test_st_setcrs_sedonadb(eng, geom, crs, expected_srid):
6363
eng = eng.create_or_skip()
64-
result = eng.execute_and_collect(
65-
f"SELECT ST_SetSrid({geom_or_null(geom)}, '{srid}')"
66-
)
64+
result = eng.execute_and_collect(f"SELECT ST_SetCrs({geom_or_null(geom)}, '{crs}')")
6765
df = eng.result_to_pandas(result)
6866
assert df.crs.to_epsg() == expected_srid

python/sedonadb/tests/io/test_parquet.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def test_read_geoparquet_pruned(geoarrow_data, name):
102102
result = eng.execute_and_collect(
103103
f"""
104104
SELECT "OBJECTID", geometry FROM tab
105-
WHERE ST_Intersects(geometry, ST_SetSRID({geom_or_null(wkt_filter)}, '{gdf.crs.to_json()}'))
105+
WHERE ST_Intersects(geometry, ST_SetCRS({geom_or_null(wkt_filter)}, '{gdf.crs.to_json()}'))
106106
ORDER BY "OBJECTID";
107107
"""
108108
)
@@ -127,7 +127,7 @@ def test_read_geoparquet_pruned(geoarrow_data, name):
127127
result = eng.execute_and_collect(
128128
f"""
129129
SELECT * FROM tab_dataset
130-
WHERE ST_Intersects(geometry, ST_SetSRID({geom_or_null(wkt_filter)}, '{gdf.crs.to_json()}'))
130+
WHERE ST_Intersects(geometry, ST_SetCRS({geom_or_null(wkt_filter)}, '{gdf.crs.to_json()}'))
131131
ORDER BY "OBJECTID";
132132
"""
133133
)

rust/sedona-expr/src/scalar_udf.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,11 @@ impl ArgMatcher {
207207
Arc::new(IsGeography {})
208208
}
209209

210+
/// Matches a null argument
211+
pub fn is_null() -> Arc<dyn TypeMatcher + Send + Sync> {
212+
Arc::new(IsNull {})
213+
}
214+
210215
/// Matches any numeric argument
211216
pub fn is_numeric() -> Arc<dyn TypeMatcher + Send + Sync> {
212217
Arc::new(IsNumeric {})
@@ -371,6 +376,14 @@ impl TypeMatcher for IsBoolean {
371376
}
372377
}
373378

379+
#[derive(Debug)]
380+
struct IsNull {}
381+
impl TypeMatcher for IsNull {
382+
fn match_type(&self, arg: &SedonaType) -> bool {
383+
matches!(arg, SedonaType::Arrow(DataType::Null))
384+
}
385+
}
386+
374387
/// Type definition for a Scalar kernel implementation function
375388
pub type SedonaScalarKernelImpl =
376389
Arc<dyn Fn(&[SedonaType], &[ColumnarValue]) -> Result<ColumnarValue> + Send + Sync>;
@@ -602,6 +615,9 @@ mod tests {
602615

603616
assert!(ArgMatcher::is_boolean().match_type(&SedonaType::Arrow(DataType::Boolean)));
604617
assert!(!ArgMatcher::is_boolean().match_type(&SedonaType::Arrow(DataType::Int32)));
618+
619+
assert!(ArgMatcher::is_null().match_type(&SedonaType::Arrow(DataType::Null)));
620+
assert!(!ArgMatcher::is_null().match_type(&SedonaType::Arrow(DataType::Int32)));
605621
}
606622

607623
#[test]

rust/sedona-functions/src/register.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ pub fn default_function_set() -> FunctionSet {
8585
crate::st_pointzm::st_pointm_udf,
8686
crate::st_pointzm::st_pointzm_udf,
8787
crate::st_transform::st_transform_udf,
88+
crate::st_setsrid::st_set_crs_udf,
8889
crate::st_setsrid::st_set_srid_udf,
8990
crate::st_srid::st_srid_udf,
9091
crate::st_xyzm::st_m_udf,
@@ -124,6 +125,7 @@ pub mod stubs {
124125
pub use crate::st_area::st_area_udf;
125126
pub use crate::st_length::st_length_udf;
126127
pub use crate::st_perimeter::st_perimeter_udf;
128+
pub use crate::st_setsrid::st_set_crs_with_engine_udf;
127129
pub use crate::st_setsrid::st_set_srid_with_engine_udf;
128130
pub use crate::st_transform::st_transform_udf;
129131
}

0 commit comments

Comments
 (0)