paleolimbot commented on code in PR #204:
URL: https://github.com/apache/sedona-db/pull/204#discussion_r2420864454
##########
c/sedona-geos/src/binary_predicates.rs:
##########
@@ -377,4 +385,81 @@ mod tests {
let expected: ArrayRef = arrow_array!(Boolean, [Some(true),
Some(false), None]);
assert_array_equal(&tester.invoke_array_array(arg1, arg2).unwrap(),
&expected);
}
+
+ #[rstest]
+ fn crosses_udf(#[values(WKB_GEOMETRY, WKB_VIEW_GEOMETRY)] sedona_type:
SedonaType) {
+ use datafusion_common::ScalarValue;
+ let udf = SedonaScalarUDF::from_kernel("st_crosses",
st_crosses_impl());
+ let tester = ScalarUdfTester::new(udf.into(),
vec![sedona_type.clone(), sedona_type]);
+ tester.assert_return_type(DataType::Boolean);
+
+ let result = tester
+ .invoke_scalar_scalar("LINESTRING (0 0, 1 1)", "LINESTRING (0 1, 1
0)")
+ .unwrap();
+ tester.assert_scalar_result_equals(result, true);
+
+ let result = tester
+ .invoke_scalar_scalar(ScalarValue::Null, ScalarValue::Null)
+ .unwrap();
+ assert!(result.is_null());
+
+ let arg1 = create_array(
+ &[
+ Some("LINESTRING (0 0, 1 1)"),
+ Some("LINESTRING (0 0, 1 0)"),
+ None,
+ ],
+ &WKB_GEOMETRY,
+ );
+ let arg2 = create_array(
+ &[
+ Some("LINESTRING (0 1, 1 0)"),
+ Some("POLYGON ((2 2, 2 3, 3 3, 3 2, 2 2))"),
+ Some("LINESTRING (0 0, 1 1)"),
+ ],
+ &WKB_GEOMETRY,
+ );
+ let expected: ArrayRef = arrow_array!(Boolean, [Some(true),
Some(false), None]);
+ assert_array_equal(&tester.invoke_array_array(arg1, arg2).unwrap(),
&expected);
+ }
+
+ #[rstest]
+ fn overlaps_udf(#[values(WKB_GEOMETRY, WKB_VIEW_GEOMETRY)] sedona_type:
SedonaType) {
+ use datafusion_common::ScalarValue;
+ let udf = SedonaScalarUDF::from_kernel("st_overlaps",
st_overlaps_impl());
+ let tester = ScalarUdfTester::new(udf.into(),
vec![sedona_type.clone(), sedona_type]);
+ tester.assert_return_type(DataType::Boolean);
+
+ let result = tester
+ .invoke_scalar_scalar(
+ "POLYGON ((0 0, 0 2, 2 2, 2 0, 0 0))",
+ "POLYGON ((1 1, 1 3, 3 3, 3 1, 1 1))",
+ )
+ .unwrap();
+ tester.assert_scalar_result_equals(result, true);
+
+ let result = tester
+ .invoke_scalar_scalar(ScalarValue::Null, ScalarValue::Null)
+ .unwrap();
+ assert!(result.is_null());
+
+ let arg1 = create_array(
+ &[
+ Some("POLYGON ((0 0, 0 2, 2 2, 2 0, 0 0))"),
+ Some("LINESTRING (0 0, 2 0)"),
+ None,
+ ],
+ &WKB_GEOMETRY,
+ );
+ let arg2 = create_array(
+ &[
+ Some("POLYGON ((1 1, 1 3, 3 3, 3 1, 1 1))"),
+ Some("LINESTRING (1 0, 3 0)"),
+ Some("POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))"),
+ ],
+ &WKB_GEOMETRY,
+ );
+ let expected: ArrayRef = arrow_array!(Boolean, [Some(true),
Some(true), None]);
Review Comment:
I think this test would be more useful if one of the results were false
##########
c/sedona-geos/src/geos.rs:
##########
@@ -96,3 +96,21 @@ impl BinaryPredicate for Touches {
lhs.touches(rhs)
}
}
+
+/// Check if the geometries crosses
+#[derive(Debug, Default)]
+pub struct Crosses {}
+impl BinaryPredicate for Crosses {
+ fn evaluate(lhs: &Geometry, rhs: &Geometry) -> GResult<bool> {
+ lhs.crosses(rhs)
+ }
+}
+
+/// Check if the geometries overlaps
Review Comment:
nit:
```suggestion
/// Check if the geometries overlap
```
##########
c/sedona-geos/src/geos.rs:
##########
@@ -96,3 +96,21 @@ impl BinaryPredicate for Touches {
lhs.touches(rhs)
}
}
+
+/// Check if the geometries crosses
Review Comment:
nit:
```suggestion
/// Check if the geometries cross
```
--
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]