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


##########
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:
   It would probably be better (and more compact) to hard-code these values. 
This is a bit circular since it's essentially the same as the UDF 
implementation.
   
   (Also for other tests)



##########
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();

Review Comment:
   ```suggestion
           let scalar_raster = ScalarValue::try_from_array(&rasters, 
1).unwrap();
   ```
   
   I know this was my suggestion but I think it can be even more compact 😬 
   
   (Also for the other tests)



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