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(python): Parse uppercase config keys #19852

Merged
Changes from 4 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
51 changes: 43 additions & 8 deletions crates/polars-io/src/cloud/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,14 @@ fn parsed_untyped_config<T, I: IntoIterator<Item = (impl AsRef<str>, impl Into<S
where
T: FromStr + Eq + std::hash::Hash,
{
config
Ok(config
.into_iter()
.map(|(key, val)| {
T::from_str(key.as_ref())
.map_err(
|_| polars_err!(ComputeError: "unknown configuration key: {}", key.as_ref()),
)
.filter_map(|(key, val)| {
Copy link
Member

@ritchie46 ritchie46 Nov 24, 2024

Choose a reason for hiding this comment

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

Now invalid keys are silently ignored? That doesn't seem right.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am doing it explicitly. In delta-rs for example we use quite some custom storage_options for our internal log/objectstore handling.

So when you do a read_delta and you pass those additional options from your DeltaTable object into pola-rs, it will error out, see this comment #19103 (comment)

Copy link
Member

Choose a reason for hiding this comment

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

Right, can you add a comment that some keys are read upstream and may silently be ignored there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Donee

T::from_str(key.as_ref().to_ascii_lowercase().as_str())
.ok()
.map(|typed_key| (typed_key, val.into()))
})
.collect::<PolarsResult<Configs<T>>>()
.collect::<Configs<T>>())
}

#[derive(PartialEq)]
Expand Down Expand Up @@ -607,7 +605,9 @@ impl CloudOptions {
#[cfg(feature = "cloud")]
#[cfg(test)]
mod tests {
use super::parse_url;
use hashbrown::HashMap;

use super::{parse_url, parsed_untyped_config};

#[test]
fn test_parse_url() {
Expand Down Expand Up @@ -682,4 +682,39 @@ mod tests {
);
}
}
#[cfg(feature = "aws")]
#[test]
fn test_parse_untyped_config() {
use object_store::aws::AmazonS3ConfigKey;

let aws_config = [
("aws_secret_access_key", "a_key"),
("aws_s3_allow_unsafe_rename", "true"),
]
.into_iter()
.collect::<HashMap<_, _>>();
let aws_keys = parsed_untyped_config::<AmazonS3ConfigKey, _>(aws_config)
.expect("Parsing keys shouldn't have thrown an error");

assert_eq!(
aws_keys.first().unwrap().0,
AmazonS3ConfigKey::SecretAccessKey
);
assert_eq!(aws_keys.len(), 1);

let aws_config = [
("AWS_SECRET_ACCESS_KEY", "a_key"),
("aws_s3_allow_unsafe_rename", "true"),
]
.into_iter()
.collect::<HashMap<_, _>>();
let aws_keys = parsed_untyped_config::<AmazonS3ConfigKey, _>(aws_config)
.expect("Parsing keys shouldn't have thrown an error");

assert_eq!(
aws_keys.first().unwrap().0,
AmazonS3ConfigKey::SecretAccessKey
);
assert_eq!(aws_keys.len(), 1);
}
}