Skip to content

feat(sedona-gdal): add foundational wrapper utilities#696

Merged
Kontinuation merged 6 commits intoapache:mainfrom
Kontinuation:feat/sedona-gdal-safe-foundation
Mar 13, 2026
Merged

feat(sedona-gdal): add foundational wrapper utilities#696
Kontinuation merged 6 commits intoapache:mainfrom
Kontinuation:feat/sedona-gdal-safe-foundation

Conversation

@Kontinuation
Copy link
Member

@Kontinuation Kontinuation commented Mar 9, 2026

Summary

  • add foundational safe-wrapper utilities on top of the GDAL FFI crate
  • introduce GDAL option list helpers, raster type abstractions, and expanded shared error handling

Testing

  • cargo test -p sedona-gdal
  • cargo clippy -p sedona-gdal -- -D warnings

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds foundational safe-wrapper utilities on top of the GDAL FFI crate (sedona-gdal). It introduces a pure-Rust CslStringList for GDAL's char** option lists, raster type abstractions (GdalDataType, GdalType, Buffer, DatasetOptions, ResampleAlg), a thread-local config setter, and expands the shared error type. It also re-exports the call_gdal_api! macro for use by follow-up wrapper PRs.

Changes:

  • New cpl.rs: Implements CslStringList with comprehensive tests for building/querying null-terminated GDAL option string lists.
  • New raster/types.rs + raster.rs: Adds raster type enums and structs (GdalDataType, Buffer, DatasetOptions, ResampleAlg) that map cleanly between Rust types and GDAL C types.
  • config.rs + errors.rs + gdal_api.rs additions: Thread-local GDAL config wrapper, two new error variants (BadArgument, FfiNulError), a Result<T> alias, and a pub(crate) macro re-export.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
c/sedona-gdal/src/cpl.rs New: Pure-Rust CslStringList implementation with iterator, formatting, and conversion impls, plus unit tests
c/sedona-gdal/src/raster/types.rs New: Raster type enums/structs and GdalType trait for Rust↔GDAL type mapping
c/sedona-gdal/src/raster.rs New: Module declaration and re-exports for raster types
c/sedona-gdal/src/config.rs New: set_thread_local_config_option wrapper function
c/sedona-gdal/src/errors.rs Adds BadArgument, FfiNulError variants and a Result<T> type alias to GdalError
c/sedona-gdal/src/gdal_api.rs Exports call_gdal_api! macro as pub(crate)
c/sedona-gdal/src/lib.rs Registers new high-level wrapper modules

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Kontinuation Kontinuation force-pushed the feat/sedona-gdal-safe-foundation branch from 1f6b2df to 1803c4c Compare March 10, 2026 08:46
Copy link
Member

@paleolimbot paleolimbot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few optional suggestions to consider...thank you!

Comment on lines +29 to +30
/// Set a GDAL library configuration option with **thread-local** scope.
pub fn set_thread_local_config_option(api: &'static GdalApi, key: &str, value: &str) -> Result<()> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps not here, but it might be worth exposing this as with_thread_local_config_option(FnMut...) that takes care of resetting the previous value. At the very least returning the previous value so it can be reset may be a good feature of this particular function:

https://github.com/geopandas/pyogrio/blob/5f298ba31a22654c8fdfa061342df99c2f66b12b/pyogrio/_io.pyx#L202-L233

Comment on lines +18 to +22
pub mod types;

pub use types::{
Buffer, DatasetOptions, GdalDataType, GdalType, RasterCreationOptions, ResampleAlg,
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems odd to have these aliases...should the aliases be removed or types be private?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided to remove these aliases.

Comment on lines +133 to +135
/// Shape as (cols, rows) — matches georust/gdal convention.
pub shape: (usize, usize),
pub data: Vec<T>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any future in which we need either (1) a shape larger than 2 dimensions or (2) non-owned data?

Copy link
Member Author

@Kontinuation Kontinuation Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to handle rasters with more than 2 dimensions using GDAL in the near future. This struct was taken from georust/gdal for representing blocks read from the raster. We'll simply pass in slices when working with buffer slices, and there's currently no methods for returning borrowed raster data. We can add a BorrowedBuffer if we need to work with non-owned buffer in a different way in the future.

@Kontinuation Kontinuation force-pushed the feat/sedona-gdal-safe-foundation branch from ebb9d74 to 5a608c6 Compare March 11, 2026 07:50
@Kontinuation Kontinuation merged commit d748e4c into apache:main Mar 13, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants