james-willis commented on code in PR #812: URL: https://github.com/apache/sedona-db/pull/812#discussion_r3190294518
########## rust/sedona-raster-gdal/src/source_uri.rs: ########## @@ -0,0 +1,237 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +//! GDAL-format-driver-internal parser for out-db raster source URIs. +//! +//! When a band's `outdb_format` dispatches to the GDAL driver, the loader +//! uses this helper to extract a 1-based source band index from `outdb_uri` +//! via the SedonaDB convention `<uri>#band=N`. The convention is private to +//! the GDAL driver — the schema and format-agnostic surfaces (e.g. +//! `RS_BandPath`) treat `outdb_uri` as opaque. Other format drivers handle +//! their own URIs however they like. + +use std::borrow::Cow; + +use datafusion_common::{error::Result, exec_err}; + +/// Parse a SedonaDB out-db source URI into the GDAL-side URI and 1-based +/// source band index. +/// +/// Behaviour: +/// +/// - `<uri>#band=N` where `N` parses as a `u32` in `1..=u32::MAX`: strips +/// the fragment and returns `(<uri>, N)`. +/// - `<uri>#band=...` with a value that is not a positive `u32` (zero, +/// negative, non-numeric, empty, or overflowing `u32`): returns an +/// `Execution` error. The user explicitly asked for a band; we refuse to +/// silently substitute a default. +/// - GDAL-native subdataset URIs (e.g. `HDF5:"x.h5":/var`, +/// `NETCDF:"x.nc":var`, `GTIFF_DIR:1:multi.tif`) and any URI whose +/// fragment is not `band=...`: pass through verbatim with default band +/// index 1. +/// - Plain URIs without any fragment: pass through verbatim with default +/// band index 1. +/// +/// On success the returned URI is always borrowed from the input; this +/// function never allocates on the happy path. +pub(crate) fn parse_outdb_source(uri: &str) -> Result<(Cow<'_, str>, u32)> { Review Comment: done. Probably doesnt even wind up saving an allocation once we pass into GDAL. -- 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]
