@@ -895,8 +895,48 @@ impl ConfigOptions {
895
895
}
896
896
}
897
897
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`]
899
900
///
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:
900
940
/// Unfortunately associated constants are not currently object-safe, and so this
901
941
/// extends the object-safe [`ExtensionOptions`]
902
942
pub trait ConfigExtension : ExtensionOptions {
@@ -906,7 +946,9 @@ pub trait ConfigExtension: ExtensionOptions {
906
946
const PREFIX : & ' static str ;
907
947
}
908
948
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
910
952
pub trait ExtensionOptions : Send + Sync + fmt:: Debug + ' static {
911
953
/// Return `self` as [`Any`]
912
954
///
@@ -1114,6 +1156,8 @@ pub trait Visit {
1114
1156
/// - `<default_value>`: Default value matching the field type like `42`.
1115
1157
///
1116
1158
/// # Example
1159
+ /// See also a full example on the [`ConfigExtension`] documentation
1160
+ ///
1117
1161
/// ```
1118
1162
/// use datafusion_common::extensions_options;
1119
1163
///
0 commit comments