@@ -23,7 +23,10 @@ use datafusion_common::{
2323 ScalarValue ,
2424} ;
2525use datafusion_expr:: ColumnarValue ;
26+ use geo:: Relate ;
27+ use geo_traits:: to_geo:: ToGeoGeometry ;
2628use sedona_schema:: datatypes:: { SedonaType , WKB_GEOMETRY } ;
29+ use wkb:: reader:: Dimension ;
2730
2831use crate :: create:: create_scalar;
2932
@@ -104,7 +107,9 @@ pub fn assert_array_equal(actual: &ArrayRef, expected: &ArrayRef) {
104107/// Panics if the values' are not equal, generating reasonable failure messages for geometry
105108/// arrays where the default failure message would otherwise be uninformative.
106109pub fn assert_scalar_equal_wkb_geometry ( actual : & ScalarValue , expected_wkt : Option < & str > ) {
107- assert_scalar_equal ( actual, & create_scalar ( expected_wkt, & WKB_GEOMETRY ) ) ;
110+ let expected = create_scalar ( expected_wkt, & WKB_GEOMETRY ) ;
111+ assert_eq ! ( actual. data_type( ) , DataType :: Binary ) ;
112+ assert_wkb_scalar_equal ( actual, & expected) ;
108113}
109114
110115/// Assert two [`ScalarValue`]s are equal
@@ -205,9 +210,32 @@ fn assert_wkb_value_equal(
205210 )
206211 }
207212 ( Some ( actual_wkb) , Some ( expected_wkb) ) => {
213+ // Quick test: if the binary of the WKB is the same, they are equal
208214 if actual_wkb != expected_wkb {
209- let ( actual_wkt, expected_wkt) = ( format_wkb ( actual_wkb) , format_wkb ( expected_wkb) ) ;
210- panic ! ( "{actual_label} != {expected_label}\n {actual_label}:\n {actual_wkt}\n {expected_label}:\n {expected_wkt}" )
215+ // Binary of the WKB are not the same, but geometries could be topologically the same.
216+ let expected = wkb:: reader:: read_wkb ( expected_wkb) ;
217+ let actual = wkb:: reader:: read_wkb ( actual_wkb) ;
218+ let is_equals = match ( expected, actual) {
219+ ( Ok ( expected_geom) , Ok ( actual_geom) ) => {
220+ if expected_geom. dimension ( ) == Dimension :: Xy
221+ && actual_geom. dimension ( ) == Dimension :: Xy
222+ {
223+ let expected_geom = expected_geom. to_geometry ( ) ;
224+ let actual_geom = actual_geom. to_geometry ( ) ;
225+ expected_geom. relate ( & actual_geom) . is_equal_topo ( )
226+ } else {
227+ // geo crate does not support 3D/4D geometry operations, so we fall back to using the result
228+ // of byte-wise comparision
229+ false
230+ }
231+ }
232+ _ => false ,
233+ } ;
234+ if !is_equals {
235+ let ( actual_wkt, expected_wkt) =
236+ ( format_wkb ( actual_wkb) , format_wkb ( expected_wkb) ) ;
237+ panic ! ( "{actual_label} != {expected_label}\n {actual_label}:\n {actual_wkt}\n {expected_label}:\n {expected_wkt}" )
238+ }
211239 }
212240 }
213241 }
0 commit comments