This is an automated email from the ASF dual-hosted git repository.
jiayu 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 2ee2e7c bug: Casts ints to floats in st_buffer and st_dwithin args
(#32)
2ee2e7c is described below
commit 2ee2e7cf5e780991d8a32aba0b4c537eaa27e2ba
Author: Peter Nguyen <[email protected]>
AuthorDate: Fri Sep 5 12:34:21 2025 -0700
bug: Casts ints to floats in st_buffer and st_dwithin args (#32)
* Cast to float64 in st_buffer and st_dwithin
* Test it in python integration tests
* Sprinkle other negative and float args in other functions (already pass)
---
c/sedona-geos/src/st_buffer.rs | 5 +++--
c/sedona-geos/src/st_dwithin.rs | 5 +++--
python/sedonadb/tests/functions/test_functions.py | 20 ++++++++++----------
python/sedonadb/tests/functions/test_predicates.py | 6 +++---
4 files changed, 19 insertions(+), 17 deletions(-)
diff --git a/c/sedona-geos/src/st_buffer.rs b/c/sedona-geos/src/st_buffer.rs
index 6ffd5c3..7049400 100644
--- a/c/sedona-geos/src/st_buffer.rs
+++ b/c/sedona-geos/src/st_buffer.rs
@@ -17,6 +17,7 @@
use std::sync::Arc;
use arrow_array::builder::BinaryBuilder;
+use arrow_schema::DataType;
use datafusion_common::error::Result;
use datafusion_common::DataFusionError;
use datafusion_expr::ColumnarValue;
@@ -59,7 +60,8 @@ impl SedonaScalarKernel for STBuffer {
// Extract the constant scalar value before looping over the input
geometries
let distance: Option<f64>;
- if let ColumnarValue::Scalar(scalar_arg) = &args[1] {
+ let arg1 = args[1].cast_to(&DataType::Float64, None)?;
+ if let ColumnarValue::Scalar(scalar_arg) = &arg1 {
if scalar_arg.is_null() {
distance = None;
} else {
@@ -113,7 +115,6 @@ fn invoke_scalar(
#[cfg(test)]
mod tests {
use arrow_array::ArrayRef;
- use arrow_schema::DataType;
use datafusion_common::ScalarValue;
use rstest::rstest;
use sedona_expr::scalar_udf::SedonaScalarUDF;
diff --git a/c/sedona-geos/src/st_dwithin.rs b/c/sedona-geos/src/st_dwithin.rs
index 47826d6..1d8f97d 100644
--- a/c/sedona-geos/src/st_dwithin.rs
+++ b/c/sedona-geos/src/st_dwithin.rs
@@ -55,7 +55,8 @@ impl SedonaScalarKernel for STDWithin {
) -> Result<ColumnarValue> {
// Extract the constant scalar value before looping over the input
geometries
let distance: Option<f64>;
- if let ColumnarValue::Scalar(scalar_arg) = &args[2] {
+ let arg2 = args[2].cast_to(&DataType::Float64, None)?;
+ if let ColumnarValue::Scalar(scalar_arg) = &arg2 {
if scalar_arg.is_null() {
distance = None;
} else {
@@ -145,7 +146,7 @@ mod tests {
],
&WKB_GEOMETRY,
);
- let distance = 1.0;
+ let distance = 1;
let expected: ArrayRef = arrow_array!(Boolean, [Some(true),
Some(false), None, Some(true)]);
assert_array_equal(
diff --git a/python/sedonadb/tests/functions/test_functions.py
b/python/sedonadb/tests/functions/test_functions.py
index 870b960..7e3e1e3 100644
--- a/python/sedonadb/tests/functions/test_functions.py
+++ b/python/sedonadb/tests/functions/test_functions.py
@@ -126,8 +126,8 @@ def test_st_astext(eng, geom):
(None, None, None),
(None, 1.0, None),
("POINT (1 1)", None, None),
- ("POINT (1 1)", 0.0, 0),
- ("POINT EMPTY", 1.0, 0),
+ ("POINT (1 1)", 0, 0),
+ ("POINT EMPTY", 1, 0),
("LINESTRING EMPTY", 1.0, 0),
("POLYGON EMPTY", 1.0, 0),
("POINT (0 0)", 1.0, 3.121445152258052),
@@ -663,7 +663,7 @@ def test_st_pointzm(eng, x, y, z, m, expected):
("POINT ZM EMPTY", None),
("POINT (1 2)", None),
("POINT Z (1 2 3)", None),
- ("POINT M (1 2 3)", 3),
+ ("POINT M (1 2 3.2)", 3.2),
("POINT ZM (1 2 3 -4)", -4),
],
)
@@ -681,7 +681,7 @@ def test_st_m(eng, geom, expected):
("POINT Z EMPTY", None),
("POINT M EMPTY", None),
("POINT ZM EMPTY", None),
- ("POINT (1 2)", 1),
+ ("POINT (1.1 2)", 1.1),
("POINT Z (1 2 3)", 1),
("POINT M (1 2 3)", 1),
("POINT ZM (1 2 3 -4)", 1),
@@ -704,7 +704,7 @@ def test_st_x(eng, geom, expected):
("POINT (1 2)", 2),
("POINT Z (1 2 3)", 2),
("POINT M (1 2 3)", 2),
- ("POINT ZM (1 2 3 -4)", 2),
+ ("POINT ZM (1 2.2 3 -4)", 2.2),
],
)
def test_st_y(eng, geom, expected):
@@ -742,7 +742,7 @@ def test_st_z(eng, geom, expected):
("POINT Z (1 2 3)", 1),
("POINT M (1 2 3)", 1),
("POINT ZM (1 2 3 4)", 1),
- ("MULTILINESTRING ((0 0, 1 1), (2 2, 3 3))", 0),
+ ("MULTILINESTRING ((-1.1 0, 1 1), (2 2, 3 3))", -1.1),
("POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))", 0),
(
"GEOMETRYCOLLECTION (POINT (0 0), POLYGON ((0 0, 1 0, 1 1, 0 1, 0
0)), LINESTRING (0 0, 1 1))",
@@ -773,7 +773,7 @@ def test_st_xmin(eng, geom, expected):
("POINT Z (1 2 3)", 2),
("POINT M (1 2 3)", 2),
("POINT ZM (1 2 3 4)", 2),
- ("MULTILINESTRING ((0 0, 1 1), (2 2, 3 3))", 0),
+ ("MULTILINESTRING ((0 0, 1 1), (2 -2.2, 3 3))", -2.2),
("POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))", 0),
(
"GEOMETRYCOLLECTION (POINT (0 0), POLYGON ((0 0, 1 0, 1 1, 0 1, 0
0)), LINESTRING (0 0, 1 1))",
@@ -804,7 +804,7 @@ def test_st_ymin(eng, geom, expected):
("POINT Z (1 2 3)", 1),
("POINT M (1 2 3)", 1),
("POINT ZM (1 2 3 4)", 1),
- ("MULTILINESTRING ((0 0, 1 1), (2 2, 3 3))", 3),
+ ("MULTILINESTRING ((0 0, 1 1), (2 2, 3.3 3))", 3.3),
("POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))", 1),
(
"GEOMETRYCOLLECTION (POINT (0 0), POLYGON ((0 0, 1 0, 1 1, 0 1, 0
0)), LINESTRING (0 0, 1 1))",
@@ -948,8 +948,8 @@ def test_st_zmax(eng, geom, expected):
None,
),
(
- "GEOMETRYCOLLECTION ZM (POINT ZM (1 2 3 4), LINESTRING ZM (3 4 5
6, 7 8 9 10), POLYGON ZM ((0 0 0 0, 1 0 0 0, 0 1 0 0, 0 0 0 0)))",
- 0,
+ "GEOMETRYCOLLECTION ZM (POINT ZM (1 2 3 4), LINESTRING ZM (3 4 5
6, 7 8 9 10), POLYGON ZM ((0 0 0 -1.1, 1 0 0 0, 0 1 0 0, 0 0 0 0)))",
+ -1.1,
),
(
"GEOMETRYCOLLECTION (POINT (1 2), LINESTRING (3 4, 5 6),
GEOMETRYCOLLECTION (POINT (10 10)))",
diff --git a/python/sedonadb/tests/functions/test_predicates.py
b/python/sedonadb/tests/functions/test_predicates.py
index 91d9ddb..77b3f03 100644
--- a/python/sedonadb/tests/functions/test_predicates.py
+++ b/python/sedonadb/tests/functions/test_predicates.py
@@ -154,7 +154,7 @@ def test_st_disjoint(eng, geom1, geom2, expected):
@pytest.mark.parametrize(
("geom1", "geom2", "distance", "expected"),
[
- (None, "POINT (0 0)", 1.0, None),
+ (None, "POINT (0 0)", 1, None),
("POINT (1 1)", None, 1.0, None),
("POINT (0 0)", "POINT (0 0)", None, None),
(None, None, None, None),
@@ -165,13 +165,13 @@ def test_st_disjoint(eng, geom1, geom2, expected):
(
"POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))",
"POLYGON ((5 5, 6 5, 6 6, 5 6, 5 5))",
- 6.0,
+ 6.2,
True,
),
(
"GEOMETRYCOLLECTION (POINT (0 0), LINESTRING (0 0, 1 1))",
"GEOMETRYCOLLECTION (POINT (0 0), LINESTRING (0 0, 1 1))",
- 1.0,
+ 1,
True,
),
],