james-willis commented on code in PR #1027:
URL: https://github.com/apache/sedona-db/pull/1027#discussion_r3590121237
##########
rust/sedona-raster-functions/src/rs_value.rs:
##########
@@ -786,6 +658,74 @@ mod tests {
assert_eq!(sample("POINT (100 100)"), None); // outside the footprint
}
+ /// A two-band raster used to exercise the default-band ambiguity error.
+ fn two_band_raster() -> StructArray {
+ RasterSpec::d2(2, 2)
+ .band_values(&[1u8, 2, 3, 4])
+ .band_values(&[10u8, 20, 30, 40])
+ .transform([0.0, 1.0, 0.0, 10.0, 0.0, -1.0])
+ .build()
+ }
+
+ #[test]
+ fn default_band_requires_single_band_raster_array_path() {
+ // No band argument + multiband raster is ambiguous -> error (general,
+ // array-raster path) rather than silently sampling band 1.
+ let udf: ScalarUDF = rs_value_udf().into();
+ let geom_type = SedonaType::Wkb(Edges::Planar, lnglat());
+ let tester = ScalarUdfTester::new(udf, vec![RASTER,
geom_type.clone()]);
+ let geoms = create_geom_array(&[Some("POINT (0.5 9.5)")], &geom_type);
+ let err = tester
+ .invoke_arrays(vec![Arc::new(two_band_raster()), geoms])
+ .unwrap_err()
+ .to_string();
+ assert!(
+ err.contains("specify which band"),
+ "unexpected error: {err}"
+ );
+ }
+
+ #[test]
+ fn default_band_requires_single_band_raster_scalar_path() {
+ // Same ambiguity on the scalar-raster fast path.
+ let udf: ScalarUDF = rs_value_udf().into();
+ let geom_type = SedonaType::Wkb(Edges::Planar, lnglat());
+ let tester = ScalarUdfTester::new(udf, vec![RASTER,
geom_type.clone()]);
+ let geoms = create_geom_array(&[Some("POINT (0.5 9.5)")], &geom_type);
+ let err = tester
+ .invoke(vec![
+
ColumnarValue::Scalar(ScalarValue::Struct(Arc::new(two_band_raster()))),
+ ColumnarValue::Array(geoms),
+ ])
+ .unwrap_err()
+ .to_string();
+ assert!(
+ err.contains("specify which band"),
+ "unexpected error: {err}"
+ );
+ }
+
+ #[test]
+ fn scalar_all_null_points_defer_default_band_check() {
+ // The scalar fast path defers the default-band ambiguity check until a
+ // point needs sampling: an all-NULL point column over a multiband
raster
+ // returns NULL rather than erroring — matching the general path, which
+ // only resolves the band on rows that actually have a point.
+ let udf: ScalarUDF = rs_value_udf().into();
+ let geom_type = SedonaType::Wkb(Edges::Planar, lnglat());
+ let tester = ScalarUdfTester::new(udf, vec![RASTER,
geom_type.clone()]);
+ let geoms = create_geom_array(&[None, None], &geom_type);
+ let result = tester
+ .invoke(vec![
+
ColumnarValue::Scalar(ScalarValue::Struct(Arc::new(two_band_raster()))),
+ ColumnarValue::Array(geoms),
+ ])
+ .unwrap();
Review Comment:
this one is also intentionally testing a distinct case, this time scalar
raster + array points
--
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]