From d573ea0a840bfdcc94a41007ea34e7853102e4be Mon Sep 17 00:00:00 2001 From: Kristin Cowalcijk Date: Tue, 10 Feb 2026 21:28:52 +0800 Subject: [PATCH] feat(rust/sedona-testing): Add test helpers for loading raster test data Add test_raster() function in data.rs for resolving paths to raster test files in the sedona-testing submodule, and raster_from_single_band() in rasters.rs for programmatically building minimal single-band rasters in unit tests. Update sedona-testing submodule to include raster test data files (test1.tiff, test3.tif, test4.tiff, test5.tiff). --- rust/sedona-testing/src/data.rs | 41 ++++++++++++++++++++++++++++++ rust/sedona-testing/src/rasters.rs | 37 +++++++++++++++++++++++++++ submodules/sedona-testing | 2 +- 3 files changed, 79 insertions(+), 1 deletion(-) diff --git a/rust/sedona-testing/src/data.rs b/rust/sedona-testing/src/data.rs index a6bd991fd..f5a4c0135 100644 --- a/rust/sedona-testing/src/data.rs +++ b/rust/sedona-testing/src/data.rs @@ -125,6 +125,33 @@ pub fn sedona_testing_dir() -> Result { ) } +/// Get the path to a raster test file from the sedona-testing data directory. +/// +/// # Arguments +/// * `name` - The name of the raster file (e.g., "test1.tiff", "test4.tiff") +/// +/// # Returns +/// The full path to the raster test file if it exists. +/// +/// # Example +/// ```ignore +/// let path = test_raster("test4.tiff")?; +/// ``` +pub fn test_raster(name: &str) -> Result { + let base = sedona_testing_dir()?; + let path = format!("{}/data/raster/{}", base, name); + if fs::exists(&path)? { + Ok(path) + } else { + sedona_internal_err!( + "sedona-testing raster file '{}' not found at '{}', \ + run submodules/download-assets.py or check the file name", + name, + path + ) + } +} + #[cfg(test)] mod test { use super::*; @@ -172,4 +199,18 @@ mod test { env::remove_var("SEDONA_TESTING_DIR"); assert!(maybe_dir.is_ok()); } + + #[test] + fn test_raster_resolves() { + // Test that test_raster can find existing raster files + let path = test_raster("test4.tiff"); + assert!(path.is_ok(), "Failed to find test4.tiff: {:?}", path.err()); + let path_str = path.unwrap(); + assert!(path_str.ends_with("test4.tiff")); + assert!(fs::exists(&path_str).unwrap()); + + // Test that non-existent files return an error + let err = test_raster("nonexistent.tiff"); + assert!(err.is_err()); + } } diff --git a/rust/sedona-testing/src/rasters.rs b/rust/sedona-testing/src/rasters.rs index aea072cab..2aab413cc 100644 --- a/rust/sedona-testing/src/rasters.rs +++ b/rust/sedona-testing/src/rasters.rs @@ -184,6 +184,43 @@ pub fn build_noninvertible_raster() -> StructArray { builder.finish().expect("finish") } +/// Builds a single-band raster from raw bytes for tests. +pub fn raster_from_single_band( + width: usize, + height: usize, + data_type: BandDataType, + band_bytes: &[u8], + crs: Option<&str>, +) -> StructArray { + let mut builder = RasterBuilder::new(1); + let metadata = RasterMetadata { + width: width as u64, + height: height as u64, + upperleft_x: 0.0, + upperleft_y: 0.0, + scale_x: 1.0, + scale_y: -1.0, + skew_x: 0.0, + skew_y: 0.0, + }; + + builder.start_raster(&metadata, crs).expect("start raster"); + builder + .start_band(BandMetadata { + datatype: data_type, + nodata_value: None, + storage_type: StorageType::InDb, + outdb_url: None, + outdb_band_id: None, + }) + .expect("start band"); + builder.band_data_writer().append_value(band_bytes); + builder.finish_band().expect("finish band"); + builder.finish_raster().expect("finish raster"); + + builder.finish().expect("finish") +} + /// Determine if this tile contains a corner of the overall grid and return its position /// Returns Some(position) if this tile contains a corner, None otherwise fn get_corner_position( diff --git a/submodules/sedona-testing b/submodules/sedona-testing index c7bc17d71..48f6cd7ef 160000 --- a/submodules/sedona-testing +++ b/submodules/sedona-testing @@ -1 +1 @@ -Subproject commit c7bc17d7109fc628959eb2850d4cfce3d483b1ee +Subproject commit 48f6cd7efbc9e4f14bd3caf3a706e2cf12b9d6ce