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


##########
rust/sedona-raster-functions/src/rs_rastercoordinate.rs:
##########
@@ -368,4 +372,112 @@ mod tests {
             .unwrap();
         assert_array_equal(&result, &expected);
     }
+
+    #[rstest]
+    fn udf_invoke_xy_with_scalar_raster_array_coords(#[values(Coord::Y, 
Coord::X)] coord: Coord) {
+        let udf = match coord {
+            Coord::X => rs_worldtorastercoordx_udf(),
+            Coord::Y => rs_worldtorastercoordy_udf(),
+        };
+        let tester = ScalarUdfTester::new(
+            udf.into(),
+            vec![
+                RASTER,
+                SedonaType::Arrow(DataType::Float64),
+                SedonaType::Arrow(DataType::Float64),
+            ],
+        );
+
+        // Use raster 1 (invertible) as scalar.
+        let rasters = generate_test_rasters(2, Some(0)).unwrap();
+        let raster_struct = 
rasters.as_any().downcast_ref::<StructArray>().unwrap();
+        let scalar_raster = ScalarValue::try_from_array(raster_struct, 
1).unwrap();
+
+        let raster_ref = RasterStructArray::new(raster_struct).get(1).unwrap();
+
+        let world_x = Arc::new(arrow_array::Float64Array::from(vec![2.0, 2.5, 
3.25]));
+        let world_y = Arc::new(arrow_array::Float64Array::from(vec![3.0, 2.5, 
1.75]));
+
+        let expected_coords: Vec<Option<i64>> = world_x
+            .iter()
+            .zip(world_y.iter())
+            .map(|(x, y)| match (x, y) {
+                (Some(x), Some(y)) => {
+                    let (rx, ry) = to_raster_coordinate(&raster_ref, x, 
y).unwrap();
+                    Some(match coord {
+                        Coord::X => rx,
+                        Coord::Y => ry,
+                    })
+                }
+                _ => None,
+            })
+            .collect();

Review Comment:
   Makes sense. My initial attempt is to test the RasterExecutor but not the RS 
function itself. Hardcoding expected values is the correct approach since this 
test lives in rs_rastercoordinate.rs so it should test the correctness of the 
RS function as its primary goal.



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