Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix scanning from HTTP cloud paths #17571

Merged
merged 4 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions crates/polars-io/src/cloud/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,14 +200,12 @@ fn read_config(
let content = std::str::from_utf8(buf.as_ref()).ok()?;

for (pattern, key) in keys.iter() {
let local = std::mem::take(builder);

if builder.get_config_value(key).is_none() {
let reg = Regex::new(pattern).unwrap();
let cap = reg.captures(content)?;
let m = cap.get(1)?;
let parsed = m.as_str();
*builder = local.with_config(*key, parsed)
*builder = std::mem::take(builder).with_config(*key, parsed);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fix issue with the config key being incorrectly overwritten. If the code above using ? short circuits then the original config is reset due to mem::take.

}
}
}
Expand Down
31 changes: 22 additions & 9 deletions crates/polars-io/src/file_cache/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,10 @@ pub(super) fn update_last_accessed(file: &std::fs::File) {
}
}

pub fn init_entries_from_uri_list<A: AsRef<[Arc<str>]>>(
uri_list: A,
pub fn init_entries_from_uri_list(
uri_list: &[Arc<str>],
cloud_options: Option<&CloudOptions>,
) -> PolarsResult<Vec<Arc<FileCacheEntry>>> {
let uri_list = uri_list.as_ref();

if uri_list.is_empty() {
return Ok(Default::default());
}
Expand All @@ -69,13 +67,27 @@ pub fn init_entries_from_uri_list<A: AsRef<[Arc<str>]>>(
.unwrap_or_else(get_env_file_cache_ttl);

if is_cloud_url(first_uri) {
let (_, object_store) = pl_async::get_runtime()
.block_on_potential_spawn(build_object_store(first_uri, cloud_options))?;
let object_store = PolarsObjectStore::new(object_store);
let object_stores = pl_async::get_runtime().block_on_potential_spawn(async {
futures::future::try_join_all(
(0..if first_uri.starts_with("http") {
// Object stores for http are tied to the path.
uri_list.len()
Copy link
Collaborator Author

@nameexhaustion nameexhaustion Jul 11, 2024

Choose a reason for hiding this comment

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

Fix issue where scanning a list of HTTP paths would just scan the first file N times.

} else {
1
})
.map(|i| async move {
let (_, object_store) =
build_object_store(&uri_list[i], cloud_options).await?;
PolarsResult::Ok(PolarsObjectStore::new(object_store))
}),
)
.await
})?;

uri_list
.iter()
.map(|uri| {
.enumerate()
.map(|(i, uri)| {
FILE_CACHE.init_entry(
uri.clone(),
|| {
Expand All @@ -88,7 +100,8 @@ pub fn init_entries_from_uri_list<A: AsRef<[Arc<str>]>>(
object_path_from_string(prefix)?
};

let object_store = object_store.clone();
let object_store =
object_stores[std::cmp::min(i, object_stores.len())].clone();
let uri = uri.clone();

Ok(Arc::new(CloudFileFetcher {
Expand Down
4 changes: 4 additions & 0 deletions crates/polars-io/src/utils/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ pub fn expand_paths(
cloud_options: Option<&CloudOptions>|
-> PolarsResult<(usize, Vec<PathBuf>)> {
crate::pl_async::get_runtime().block_on_potential_spawn(async {
if path.starts_with("http") {
return Ok((0, vec![PathBuf::from(path)]));
}

let (cloud_location, store) =
crate::cloud::build_object_store(path, cloud_options).await?;

Expand Down
3 changes: 2 additions & 1 deletion crates/polars-plan/src/plans/conversion/scans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ pub(super) fn csv_file_info(
paths
.iter()
.map(|path| Arc::from(path.to_str().unwrap()))
.collect::<Box<[_]>>(),
.collect::<Vec<_>>()
.as_slice(),
cloud_options,
)?)
} else {
Expand Down