Kontinuation commented on code in PR #615:
URL: https://github.com/apache/sedona-db/pull/615#discussion_r2891237227


##########
rust/sedona-raster-functions/src/executor.rs:
##########
@@ -35,6 +40,177 @@ pub struct RasterExecutor<'a, 'b> {
     num_iterations: usize,
 }
 
+#[derive(Clone)]
+enum ItemWkbAccessor {
+    Binary(BinaryArray),
+    BinaryView(BinaryViewArray),
+}
+
+impl ItemWkbAccessor {
+    #[inline]
+    fn get(&self, i: usize) -> Option<&[u8]> {
+        match self {
+            Self::Binary(arr) => {
+                if arr.is_null(i) {
+                    None
+                } else {
+                    Some(arr.value(i))
+                }
+            }
+            Self::BinaryView(arr) => {
+                if arr.is_null(i) {
+                    None
+                } else {
+                    Some(arr.value(i))
+                }
+            }
+        }
+    }
+}
+
+enum GeomWkbCrsAccessor {
+    WkbArray {
+        wkb: ItemWkbAccessor,
+        static_crs: Option<String>,
+    },
+    WkbScalar {
+        wkb: Option<Vec<u8>>,
+        static_crs: Option<String>,
+    },
+    ItemCrsArray {
+        struct_array: StructArray,
+        item: ItemWkbAccessor,
+        crs: StringViewArray,
+        item_static_crs: Option<String>,
+    },
+    ItemCrsScalar {
+        struct_array: StructArray,
+        item: ItemWkbAccessor,
+        crs: StringViewArray,
+        item_static_crs: Option<String>,
+    },
+    Null,
+}
+
+impl GeomWkbCrsAccessor {
+    #[inline]
+    fn get(&self, i: usize) -> Result<(Option<&[u8]>, Option<&str>)> {
+        match self {
+            Self::Null => Ok((None, None)),
+            Self::WkbArray { wkb, static_crs } => {
+                let maybe_wkb = wkb.get(i);
+                if maybe_wkb.is_none() {
+                    return Ok((None, None));
+                }
+                Ok((maybe_wkb, static_crs.as_deref()))
+            }
+            Self::WkbScalar { wkb, static_crs } => {
+                if wkb.is_none() {
+                    return Ok((None, None));
+                }
+                let _ = i;
+                Ok((wkb.as_deref(), static_crs.as_deref()))
+            }
+            Self::ItemCrsArray {
+                struct_array,
+                item,
+                crs,
+                item_static_crs,
+            } => {
+                if struct_array.is_null(i) {
+                    return Ok((None, None));
+                }
+
+                let maybe_wkb = item.get(i);
+                if maybe_wkb.is_none() {
+                    return Ok((None, None));
+                }
+
+                let item_crs_str = if crs.is_null(i) {
+                    None
+                } else {
+                    Some(crs.value(i))
+                };
+                let static_crs_str = item_static_crs.as_deref();
+                let crs_out = resolve_item_crs(item_crs_str, static_crs_str)?;
+                Ok((maybe_wkb, crs_out))
+            }
+            Self::ItemCrsScalar {
+                struct_array,
+                item,
+                crs,
+                item_static_crs,
+            } => {
+                if struct_array.is_null(0) {
+                    return Ok((None, None));
+                }
+
+                let maybe_wkb = item.get(0);
+                if maybe_wkb.is_none() {
+                    return Ok((None, None));
+                }
+
+                let item_crs_str = if crs.is_null(0) {
+                    None
+                } else {
+                    Some(crs.value(0))
+                };
+                let static_crs_str = item_static_crs.as_deref();
+                let crs_out = resolve_item_crs(item_crs_str, static_crs_str)?;
+                let _ = i;
+                Ok((maybe_wkb, crs_out))
+            }
+        }
+    }
+}
+
+fn resolve_item_crs<'a>(
+    item_crs: Option<&'a str>,
+    static_crs: Option<&'a str>,
+) -> Result<Option<&'a str>> {
+    match (item_crs, static_crs) {
+        (None, None) => Ok(None),
+        (Some(item), None) => Ok(Some(item)),
+        (None, Some(st)) => Ok(Some(st)),
+        (Some(item), Some(st)) => {
+            if item == st {
+                return Ok(Some(item));
+            }
+
+            let item_crs = deserialize_crs(item)?;
+            let static_crs = deserialize_crs(st)?;
+            if item_crs == static_crs {
+                Ok(Some(item))
+            } else {
+                exec_err!("CRS values not equal: {item_crs:?} vs 
{static_crs:?}")
+            }
+        }
+    }
+}
+
+fn crs_string_from_sedona_type(sedona_type: &SedonaType) -> 
Result<Option<String>> {
+    match sedona_type {
+        SedonaType::Wkb(_, crs) | SedonaType::WkbView(_, crs) => {
+            if let Some(crs) = crs {
+                Ok(Some(
+                    crs.to_authority_code()?.unwrap_or_else(|| crs.to_json()),
+                ))

Review Comment:
   I decide to change `execute_raster_wkb_crs_void` to pass `&dyn 
CoordinateReferenceSystem` instead of a CRS string to the closure.



-- 
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]

Reply via email to