diff --git a/crates/polars-io/src/cloud/object_store_setup.rs b/crates/polars-io/src/cloud/object_store_setup.rs index 4d43d8184d62a..7b18640db6179 100644 --- a/crates/polars-io/src/cloud/object_store_setup.rs +++ b/crates/polars-io/src/cloud/object_store_setup.rs @@ -40,17 +40,9 @@ fn url_and_creds_to_key(url: &Url, options: Option<&CloudOptions>) -> String { ) } -/// Simply construct an object_store `Path` struct from a string. -pub fn object_path_from_string(path: String) -> object_store::path::Path { - // We transmute because they don't expose a way to just create it from a string - // without encoding or decoding it. If one day we can't use this transmute hack - // anymore then we'll just have to `Path::from_url_path(percent_encode(path))` - { - const _: [(); std::mem::align_of::()] = - [(); std::mem::align_of::()]; - }; - - unsafe { std::mem::transmute::(path) } +/// Construct an object_store `Path` from a string without any encoding/decoding. +pub fn object_path_from_string(path: String) -> PolarsResult { + object_store::path::Path::parse(&path).map_err(to_compute_err) } /// Build an [`ObjectStore`] based on the URL and passed in url. Return the cloud location and an implementation of the object store. @@ -147,7 +139,7 @@ mod test { use super::object_path_from_string; let path = "%25"; - let out = object_path_from_string(path.to_string()); + let out = object_path_from_string(path.to_string()).unwrap(); assert_eq!(out.as_ref(), path); } diff --git a/crates/polars-io/src/file_cache/utils.rs b/crates/polars-io/src/file_cache/utils.rs index 6262cfe772aab..b239c2792e54b 100644 --- a/crates/polars-io/src/file_cache/utils.rs +++ b/crates/polars-io/src/file_cache/utils.rs @@ -85,7 +85,7 @@ pub fn init_entries_from_uri_list]>>( let cloud_path = { assert!(expansion.is_none(), "path should not contain wildcards"); - object_path_from_string(prefix) + object_path_from_string(prefix)? }; let object_store = object_store.clone(); diff --git a/crates/polars-io/src/ipc/ipc_reader_async.rs b/crates/polars-io/src/ipc/ipc_reader_async.rs index 2a78f4bfe3b62..4501898b50ade 100644 --- a/crates/polars-io/src/ipc/ipc_reader_async.rs +++ b/crates/polars-io/src/ipc/ipc_reader_async.rs @@ -78,7 +78,7 @@ impl IpcReaderAsync { // Any wildcards should already have been resolved here. Without this assertion they would // be ignored. debug_assert!(expansion.is_none(), "path should not contain wildcards"); - object_path_from_string(prefix) + object_path_from_string(prefix)? }; Ok(Self { diff --git a/crates/polars-io/src/parquet/read/async_impl.rs b/crates/polars-io/src/parquet/read/async_impl.rs index e53cd8922d71a..5ec9632871d58 100644 --- a/crates/polars-io/src/parquet/read/async_impl.rs +++ b/crates/polars-io/src/parquet/read/async_impl.rs @@ -49,7 +49,7 @@ impl ParquetObjectStore { // Any wildcards should already have been resolved here. Without this assertion they would // be ignored. debug_assert!(expansion.is_none(), "path should not contain wildcards"); - let path = object_path_from_string(prefix); + let path = object_path_from_string(prefix)?; Ok(ParquetObjectStore { store: PolarsObjectStore::new(store), diff --git a/crates/polars-lazy/src/scan/file_list_reader.rs b/crates/polars-lazy/src/scan/file_list_reader.rs index eaec836187320..1b0a88f5c3317 100644 --- a/crates/polars-lazy/src/scan/file_list_reader.rs +++ b/crates/polars-lazy/src/scan/file_list_reader.rs @@ -72,7 +72,7 @@ fn expand_paths( let (cloud_location, store) = polars_io::cloud::build_object_store(path, cloud_options).await?; - let prefix = object_path_from_string(cloud_location.prefix.clone()); + let prefix = object_path_from_string(cloud_location.prefix.clone())?; let out = if !path.ends_with("/") && cloud_location.expansion.is_none()