james-willis commented on code in PR #749:
URL: https://github.com/apache/sedona-db/pull/749#discussion_r3191931404
##########
rust/sedona-raster-gdal/src/gdal_common.rs:
##########
@@ -176,21 +201,39 @@ pub unsafe fn raster_ref_to_gdal_mem<R: RasterRef +
?Sized>(
// is sequential (1..=band_indices.len()), even if the source band indices
are
// sparse (e.g. [1, 3]).
for &src_band_index in band_indices.iter() {
- let band = bands
- .band(src_band_index)
- .map_err(|e| arrow_datafusion_err!(e))?;
+ let band = resolve_band(raster, src_band_index)?;
- if band.metadata().storage_type()? != StorageType::InDb {
+ if !band.is_2d() {
+ return exec_err!(
+ "GDAL backend requires a 2-dim band; got dim_names={:?}",
+ band.dim_names()
+ );
+ }
+
+ if band.outdb_uri().is_some() {
return Err(DataFusionError::NotImplemented(
"OutDb bands are not supported in
raster_to_mem_dataset".to_string(),
));
}
- let band_metadata = band.metadata();
- let band_type = band_metadata.data_type()?;
+ let band_type = band.data_type();
let gdal_type = band_data_type_to_gdal(&band_type);
- let band_data = band.data();
- let data_ptr = band_data.as_ptr();
+ // contiguous_data() is Cow::Borrowed for is_2d identity views; the
+ // borrow points at the StructArray's backing buffer, which outlives
+ // the dataset (held by the caller). For Cow::Owned the pointer would
+ // dangle the moment the Cow drops, so we reject that case loudly.
+ let band_data = band
+ .contiguous_data()
+ .map_err(|e| arrow_datafusion_err!(e))?;
+ let bytes: &[u8] = match &band_data {
+ Cow::Borrowed(b) => b,
+ Cow::Owned(_) => {
+ return exec_err!(
+ "Internal: contiguous_data must be borrowed for is_2d
bands; got owned"
+ );
+ }
+ };
+ let data_ptr = bytes.as_ptr();
Review Comment:
Note to self. This whole section and the contiguous data thing will need
some thought from others and me.
--
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]