You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sedona.apache.org by pa...@apache.org on 2026/04/17 17:23:27 UTC
(sedona-db) branch main updated: feat(python/sedonadb): Enable GPU feature in python package and add spatial join tests (#768)
This is an automated email from the ASF dual-hosted git repository.
paleolimbot pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/sedona-db.git
The following commit(s) were added to refs/heads/main by this push:
new a991238a6 feat(python/sedonadb): Enable GPU feature in python package and add spatial join tests (#768)
a991238a6 is described below
commit a991238a680db53e61859d49c858e6edd9be205b
Author: Liang Geng <pw...@gmail.com>
AuthorDate: Sat Apr 18 01:23:22 2026 +0800
feat(python/sedonadb): Enable GPU feature in python package and add spatial join tests (#768)
---
python/sedonadb/Cargo.toml | 1 +
python/sedonadb/src/lib.rs | 15 +--
python/sedonadb/tests/test_sjoin_gpu.py | 156 ++++++++++++++++++++++++++++++++
3 files changed, 165 insertions(+), 7 deletions(-)
diff --git a/python/sedonadb/Cargo.toml b/python/sedonadb/Cargo.toml
index 177e96cee..fed6a9747 100644
--- a/python/sedonadb/Cargo.toml
+++ b/python/sedonadb/Cargo.toml
@@ -29,6 +29,7 @@ crate-type = ["cdylib"]
default = ["mimalloc"]
mimalloc = ["dep:mimalloc", "dep:libmimalloc-sys"]
s2geography = ["sedona/s2geography"]
+gpu = ["sedona/gpu"]
[dependencies]
adbc_core = { workspace = true }
diff --git a/python/sedonadb/src/lib.rs b/python/sedonadb/src/lib.rs
index 6a316964e..ad5f36ec0 100644
--- a/python/sedonadb/src/lib.rs
+++ b/python/sedonadb/src/lib.rs
@@ -53,16 +53,17 @@ fn sedona_python_version() -> PyResult<String> {
Ok(VERSION.to_string())
}
-#[cfg(feature = "s2geography")]
#[pyfunction]
fn sedona_python_features() -> PyResult<Vec<String>> {
- Ok(vec!["s2geography".to_string()])
-}
+ let mut features = vec![];
-#[cfg(not(feature = "s2geography"))]
-#[pyfunction]
-fn sedona_python_features() -> PyResult<Vec<String>> {
- Ok(vec![])
+ #[cfg(feature = "s2geography")]
+ features.push("s2geography".to_string());
+
+ #[cfg(feature = "gpu")]
+ features.push("gpu".to_string());
+
+ Ok(features)
}
#[pyfunction]
diff --git a/python/sedonadb/tests/test_sjoin_gpu.py b/python/sedonadb/tests/test_sjoin_gpu.py
new file mode 100644
index 000000000..6f426a500
--- /dev/null
+++ b/python/sedonadb/tests/test_sjoin_gpu.py
@@ -0,0 +1,156 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+import json
+
+import pytest
+import sedonadb
+from sedonadb.testing import PostGIS, SedonaDB, random_geometry
+
+
+@pytest.mark.parametrize(
+ "join_type", ["INNER JOIN", "LEFT OUTER JOIN", "RIGHT OUTER JOIN"]
+)
+@pytest.mark.parametrize(
+ "on",
+ [
+ "ST_Intersects(sjoin_point.geometry, sjoin_polygon.geometry)",
+ "ST_Within(sjoin_point.geometry, sjoin_polygon.geometry)",
+ "ST_Contains(sjoin_polygon.geometry, sjoin_point.geometry)",
+ ],
+)
+def test_spatial_join_gpu(join_type, on):
+ if "gpu" not in sedonadb.__features__:
+ pytest.skip("GPU feature is not available")
+ with (
+ SedonaDB.create_or_skip() as eng_sedonadb,
+ PostGIS.create_or_skip() as eng_postgis,
+ ):
+ eng_sedonadb.con.sql("SET gpu.enable = true").execute()
+ df_point = random_geometry("Point", 100, seed=42)
+ df_polygon = random_geometry(
+ "Polygon", 100, hole_rate=0.5, num_vertices=(2, 10), seed=43
+ )
+
+ eng_sedonadb.create_table_arrow("sjoin_point", df_point)
+ eng_sedonadb.create_table_arrow("sjoin_polygon", df_polygon)
+ eng_postgis.create_table_arrow("sjoin_point", df_point)
+ eng_postgis.create_table_arrow("sjoin_polygon", df_polygon)
+
+ sql = f"""
+ SELECT sjoin_point.id id0, sjoin_polygon.id id1
+ FROM sjoin_point {join_type} sjoin_polygon
+ ON {on}
+ ORDER BY id0, id1
+ """
+
+ sedonadb_results = eng_sedonadb.execute_and_collect(sql).to_pandas()
+ assert len(sedonadb_results) > 0
+ eng_postgis.assert_query_result(sql, sedonadb_results)
+
+
+@pytest.mark.parametrize(
+ "join_type",
+ [
+ "LEFT SEMI JOIN",
+ "LEFT ANTI JOIN",
+ "RIGHT SEMI JOIN",
+ "RIGHT ANTI JOIN",
+ ],
+)
+@pytest.mark.parametrize(
+ "on",
+ [
+ "ST_Intersects(sjoin_point.geometry, sjoin_polygon.geometry)",
+ "ST_Within(sjoin_point.geometry, sjoin_polygon.geometry)",
+ "ST_Contains(sjoin_polygon.geometry, sjoin_point.geometry)",
+ ],
+)
+def test_spatial_join_semi_anti_gpu(join_type, on):
+ if "gpu" not in sedonadb.__features__:
+ pytest.skip("GPU feature is not available")
+ with (
+ SedonaDB.create_or_skip() as eng_sedonadb,
+ PostGIS.create_or_skip() as eng_postgis,
+ ):
+ eng_sedonadb.con.sql("SET gpu.enable = true").execute()
+ options = json.dumps(
+ {
+ "geom_type": "Point",
+ "polygon_hole_rate": 0.5,
+ "num_parts_range": [2, 10],
+ "vertices_per_linestring_range": [2, 10],
+ "seed": 42,
+ }
+ )
+ df_point = eng_sedonadb.execute_and_collect(
+ f"SELECT * FROM sd_random_geometry('{options}') LIMIT 100"
+ )
+ options = json.dumps(
+ {
+ "geom_type": "Polygon",
+ "polygon_hole_rate": 0.5,
+ "num_parts_range": [2, 10],
+ "vertices_per_linestring_range": [2, 10],
+ "seed": 43,
+ }
+ )
+ df_polygon = eng_sedonadb.execute_and_collect(
+ f"SELECT * FROM sd_random_geometry('{options}') LIMIT 100"
+ )
+ eng_sedonadb.create_table_arrow("sjoin_point", df_point)
+ eng_sedonadb.create_table_arrow("sjoin_polygon", df_polygon)
+ eng_postgis.create_table_arrow("sjoin_point", df_point)
+ eng_postgis.create_table_arrow("sjoin_polygon", df_polygon)
+
+ is_left = join_type.startswith("LEFT")
+ is_semi = "SEMI" in join_type
+
+ if is_left:
+ sedona_sql = f"""
+ SELECT sjoin_point.id id0
+ FROM sjoin_point {join_type} sjoin_polygon
+ ON {on}
+ ORDER BY id0
+ """
+ exists = f"EXISTS (SELECT 1 FROM sjoin_polygon WHERE {on})"
+ where = exists if is_semi else f"NOT {exists}"
+ postgis_sql = f"""
+ SELECT sjoin_point.id id0
+ FROM sjoin_point
+ WHERE {where}
+ ORDER BY id0
+ """
+ else:
+ sedona_sql = f"""
+ SELECT sjoin_polygon.id id1
+ FROM sjoin_point {join_type} sjoin_polygon
+ ON {on}
+ ORDER BY id1
+ """
+ exists = f"EXISTS (SELECT 1 FROM sjoin_point WHERE {on})"
+ where = exists if is_semi else f"NOT {exists}"
+ postgis_sql = f"""
+ SELECT sjoin_polygon.id id1
+ FROM sjoin_polygon
+ WHERE {where}
+ ORDER BY id1
+ """
+
+ sedonadb_results = eng_sedonadb.execute_and_collect(sedona_sql).to_pandas()
+ assert len(sedonadb_results) > 0
+ eng_postgis.assert_query_result(postgis_sql, sedonadb_results)