Skip to content

Commit 6856dc4

Browse files
authored
Add iter() method to Extensions (#18887)
## Which issue does this PR close? <!-- We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123. --> - None ## Rationale for this change <!-- Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed. Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes. --> As a consumer of the `Extension`s, I would like to be able to iterate all the config extensions present in the extension map. My specific use-case, is to be able to iterate them all so that I can transparently dump them in a `HeaderMap` so that I can send them as part of a network request. ## What changes are included in this PR? <!-- There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR. --> Adds an `iter()` method to the `Extensions` struct ## Are these changes tested? <!-- We typically require tests for all PRs in order to: 1. Prevent the code from being accidentally broken by subsequent changes 2. Serve as another way to document the expected behavior of the code If tests are not included in your PR, please explain why (for example, are they covered by existing tests)? --> yes ## Are there any user-facing changes? <!-- If there are user-facing changes then we may require documentation to be updated before approving the PR. --> <!-- If there are any breaking changes to public APIs, please add the `api change` label. --> Users are now able to iterate their custom `ConfigExtension`s
1 parent d24eb4a commit 6856dc4

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

datafusion/common/src/config.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1524,6 +1524,14 @@ impl Extensions {
15241524
let e = self.0.get_mut(T::PREFIX)?;
15251525
e.0.as_any_mut().downcast_mut()
15261526
}
1527+
1528+
/// Iterates all the config extension entries yielding their prefix and their
1529+
/// [ExtensionOptions] implementation.
1530+
pub fn iter(
1531+
&self,
1532+
) -> impl Iterator<Item = (&'static str, &Box<dyn ExtensionOptions>)> {
1533+
self.0.iter().map(|(k, v)| (*k, &v.0))
1534+
}
15271535
}
15281536

15291537
#[derive(Debug)]
@@ -3037,6 +3045,16 @@ mod tests {
30373045
);
30383046
}
30393047

3048+
#[test]
3049+
fn iter_test_extension_config() {
3050+
let mut extension = Extensions::new();
3051+
extension.insert(TestExtensionConfig::default());
3052+
let table_config = TableOptions::new().with_extensions(extension);
3053+
let extensions = table_config.extensions.iter().collect::<Vec<_>>();
3054+
assert_eq!(extensions.len(), 1);
3055+
assert_eq!(extensions[0].0, TestExtensionConfig::PREFIX);
3056+
}
3057+
30403058
#[test]
30413059
fn csv_u8_table_options() {
30423060
let mut table_config = TableOptions::new();

0 commit comments

Comments
 (0)