Skip to content

Commit 259443d

Browse files
authored
Minor: consolidate ConfigExtension example into API docs (#13954)
* Update examples README.md * Minor: consolidate ConfigExtension example into API docs * more docs * Remove update * clippy * Fix issue with ExtensionsOptions docs
1 parent ab9ff56 commit 259443d

File tree

2 files changed

+46
-54
lines changed

2 files changed

+46
-54
lines changed

datafusion-examples/examples/config_extension.rs

Lines changed: 0 additions & 52 deletions
This file was deleted.

datafusion/common/src/config.rs

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -895,8 +895,48 @@ impl ConfigOptions {
895895
}
896896
}
897897

898-
/// [`ConfigExtension`] provides a mechanism to store third-party configuration within DataFusion
898+
/// [`ConfigExtension`] provides a mechanism to store third-party configuration
899+
/// within DataFusion [`ConfigOptions`]
899900
///
901+
/// This mechanism can be used to pass configuration to user defined functions
902+
/// or optimizer passes
903+
///
904+
/// # Example
905+
/// ```
906+
/// use datafusion_common::{
907+
/// config::ConfigExtension, extensions_options,
908+
/// config::ConfigOptions,
909+
/// };
910+
/// // Define a new configuration struct using the `extensions_options` macro
911+
/// extensions_options! {
912+
/// /// My own config options.
913+
/// pub struct MyConfig {
914+
/// /// Should "foo" be replaced by "bar"?
915+
/// pub foo_to_bar: bool, default = true
916+
///
917+
/// /// How many "baz" should be created?
918+
/// pub baz_count: usize, default = 1337
919+
/// }
920+
/// }
921+
///
922+
/// impl ConfigExtension for MyConfig {
923+
/// const PREFIX: &'static str = "my_config";
924+
/// }
925+
///
926+
/// // set up config struct and register extension
927+
/// let mut config = ConfigOptions::default();
928+
/// config.extensions.insert(MyConfig::default());
929+
///
930+
/// // overwrite config default
931+
/// config.set("my_config.baz_count", "42").unwrap();
932+
///
933+
/// // check config state
934+
/// let my_config = config.extensions.get::<MyConfig>().unwrap();
935+
/// assert!(my_config.foo_to_bar,);
936+
/// assert_eq!(my_config.baz_count, 42,);
937+
/// ```
938+
///
939+
/// # Note:
900940
/// Unfortunately associated constants are not currently object-safe, and so this
901941
/// extends the object-safe [`ExtensionOptions`]
902942
pub trait ConfigExtension: ExtensionOptions {
@@ -906,7 +946,9 @@ pub trait ConfigExtension: ExtensionOptions {
906946
const PREFIX: &'static str;
907947
}
908948

909-
/// An object-safe API for storing arbitrary configuration
949+
/// An object-safe API for storing arbitrary configuration.
950+
///
951+
/// See [`ConfigExtension`] for user defined configuration
910952
pub trait ExtensionOptions: Send + Sync + fmt::Debug + 'static {
911953
/// Return `self` as [`Any`]
912954
///
@@ -1114,6 +1156,8 @@ pub trait Visit {
11141156
/// - `<default_value>`: Default value matching the field type like `42`.
11151157
///
11161158
/// # Example
1159+
/// See also a full example on the [`ConfigExtension`] documentation
1160+
///
11171161
/// ```
11181162
/// use datafusion_common::extensions_options;
11191163
///

0 commit comments

Comments
 (0)