Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions c/sedona-geos/src/st_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions c/sedona-geos/src/st_dwithin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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(
Expand Down
20 changes: 10 additions & 10 deletions python/sedonadb/tests/functions/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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),
],
)
Expand All @@ -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),
Expand All @@ -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):
Expand Down Expand Up @@ -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))",
Expand Down Expand Up @@ -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))",
Expand Down Expand Up @@ -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))",
Expand Down Expand Up @@ -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)))",
Expand Down
6 changes: 3 additions & 3 deletions python/sedonadb/tests/functions/test_predicates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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,
),
],
Expand Down