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


##########
rust/sedona-testing/src/rasters.rs:
##########
@@ -0,0 +1,118 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+use arrow_array::StructArray;
+use arrow_schema::ArrowError;
+use sedona_raster::builder::RasterBuilder;
+use sedona_raster::traits::{BandMetadata, RasterMetadata};
+use sedona_schema::raster::{BandDataType, StorageType};
+
+/// Generate a StructArray of rasters with sequentially increasing dimensions 
and pixel values
+/// These tiny rasters are to provide fast, easy and predictable test data for 
unit tests.
+pub fn generate_test_rasters(
+    count: usize,
+    null_raster_index: Option<usize>,
+) -> Result<StructArray, ArrowError> {
+    let mut builder = RasterBuilder::new(count);
+    for i in 0..count {
+        // If a null raster index is specified and that matches the current 
index,
+        // append a null raster
+        if matches!(null_raster_index, Some(index) if index == i) {
+            builder.append_null()?;
+            continue;
+        }
+
+        let raster_metadata = RasterMetadata {
+            width: i as u64 + 1,
+            height: i as u64 + 2,
+            upperleft_x: i as f64 + 1.0,
+            upperleft_y: i as f64 + 2.0,
+            scale_x: i as f64 * 0.1,
+            scale_y: i as f64 * 0.2,
+            skew_x: i as f64 * 0.3,
+            skew_y: i as f64 * 0.4,
+        };
+        builder.start_raster(&raster_metadata, None)?;
+        builder.start_band(BandMetadata {
+            datatype: BandDataType::UInt16,
+            nodata_value: Some(vec![0u8; 2]),
+            storage_type: StorageType::InDb,
+            outdb_url: None,
+            outdb_band_id: None,
+        })?;
+
+        let pixel_count = i * (i + 1);

Review Comment:
   `width` is i + 1, `height` is i + 2. `pixel_count` should be (i + 1) * (i + 
2)



##########
rust/sedona-raster-functions/src/executor.rs:
##########
@@ -0,0 +1,188 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use arrow_array::{Array, ArrayRef, StructArray};
+use datafusion_common::error::Result;
+use datafusion_common::{DataFusionError, ScalarValue};
+use datafusion_expr::ColumnarValue;
+use sedona_raster::array::{RasterRefImpl, RasterStructArray};
+use sedona_schema::datatypes::SedonaType;
+use sedona_schema::datatypes::RASTER;
+
+/// Helper for writing raster kernel implementations
+///
+/// The [RasterExecutor] provides a simplified interface for executing 
functions
+/// on raster arrays, handling the common pattern of downcasting to 
StructArray,
+/// creating raster iterators, and handling null values.
+pub struct RasterExecutor<'a, 'b> {
+    pub arg_types: &'a [SedonaType],
+    pub args: &'b [ColumnarValue],
+    num_iterations: usize,
+}
+
+impl<'a, 'b> RasterExecutor<'a, 'b> {
+    /// Create a new [RasterExecutor]
+    pub fn new(arg_types: &'a [SedonaType], args: &'b [ColumnarValue]) -> Self 
{
+        Self {
+            arg_types,
+            args,
+            num_iterations: Self::calc_num_iterations(args),
+        }
+    }
+
+    /// Return the number of iterations that will be performed
+    pub fn num_iterations(&self) -> usize {
+        self.num_iterations
+    }
+
+    /// Execute a function by iterating over rasters in the first argument
+    ///
+    /// This handles the common pattern of:
+    /// 1. Downcasting array to StructArray
+    /// 2. Creating raster iterator
+    /// 3. Iterating with null checks
+    /// 4. Calling the provided function with each raster
+    pub fn execute_raster_void<F>(&self, mut func: F) -> Result<()>
+    where
+        F: FnMut(usize, Option<RasterRefImpl<'_>>) -> Result<()>,
+    {
+        if self.arg_types[0] != RASTER {
+            return Err(DataFusionError::Internal(
+                "First argument must be a raster type".to_string(),
+            ));

Review Comment:
   We had a better way to return sedona internal errors: 
`sedona_internal_err!`. It constructs a `DataFusionError::External` with proper 
message referring to https://github.com/apache/sedona-db/issues to avoid the 
message suggesting it's internal to DataFusion.
   
   I believe that we need to do a clean-up for the entire code base as well, 
but in a separate PR.



##########
rust/sedona-raster-functions/src/executor.rs:
##########
@@ -0,0 +1,188 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use arrow_array::{Array, ArrayRef, StructArray};
+use datafusion_common::error::Result;
+use datafusion_common::{DataFusionError, ScalarValue};
+use datafusion_expr::ColumnarValue;
+use sedona_raster::array::{RasterRefImpl, RasterStructArray};
+use sedona_schema::datatypes::SedonaType;
+use sedona_schema::datatypes::RASTER;
+
+/// Helper for writing raster kernel implementations
+///
+/// The [RasterExecutor] provides a simplified interface for executing 
functions
+/// on raster arrays, handling the common pattern of downcasting to 
StructArray,
+/// creating raster iterators, and handling null values.
+pub struct RasterExecutor<'a, 'b> {
+    pub arg_types: &'a [SedonaType],
+    pub args: &'b [ColumnarValue],
+    num_iterations: usize,
+}
+
+impl<'a, 'b> RasterExecutor<'a, 'b> {

Review Comment:
   What will the executor API look like if we want to support raster functions 
such as RS_Clip? It takes both raster and geometry arguments.
   
   If we decided to stick to the current `RasterExecutor` design, will the new 
`execute_raster_wkb_void` be added to `RasterExecutor`?
   
   If we switch to `IntoRasterIterator`, we'll call next() in the closure 
passed into `execute_wkb_void` in order to keep the raster iterator and wkb 
iteration process in sync.



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