@@ -38,7 +38,7 @@ use crate::{DataFusionError, Result};
38
38
/// /// Amazing config
39
39
/// pub struct MyConfig {
40
40
/// /// Field 1 doc
41
- /// field1: String, default = "".to_string()
41
+ /// field1: String, transform = str::to_lowercase, default = "".to_string()
42
42
///
43
43
/// /// Field 2 doc
44
44
/// field2: usize, default = 232
@@ -67,9 +67,12 @@ use crate::{DataFusionError, Result};
67
67
/// fn set(&mut self, key: &str, value: &str) -> Result<()> {
68
68
/// let (key, rem) = key.split_once('.').unwrap_or((key, ""));
69
69
/// match key {
70
- /// "field1" => self.field1.set(rem, value),
71
- /// "field2" => self.field2.set(rem, value),
72
- /// "field3" => self.field3.set(rem, value),
70
+ /// "field1" => {
71
+ /// let value = str::to_lowercase(value);
72
+ /// self.field1.set(rem, value)
73
+ /// },
74
+ /// "field2" => self.field2.set(rem, value.as_ref()),
75
+ /// "field3" => self.field3.set(rem, value.as_ref()),
73
76
/// _ => _internal_err!(
74
77
/// "Config value \"{}\" not found on MyConfig",
75
78
/// key
@@ -102,15 +105,14 @@ use crate::{DataFusionError, Result};
102
105
/// ```
103
106
///
104
107
/// NB: Misplaced commas may result in nonsensical errors
105
- ///
106
108
#[ macro_export]
107
109
macro_rules! config_namespace {
108
110
(
109
111
$( #[ doc = $struct_d: tt] ) *
110
112
$vis: vis struct $struct_name: ident {
111
113
$(
112
114
$( #[ doc = $d: tt] ) *
113
- $field_vis: vis $field_name: ident : $field_type: ty, $( transform = $tf : expr, ) ? default = $default: expr
115
+ $field_vis: vis $field_name: ident : $field_type: ty, $( transform = $transform : expr, ) ? default = $default: expr
114
116
) * $( , ) *
115
117
}
116
118
) => {
@@ -131,7 +133,7 @@ macro_rules! config_namespace {
131
133
match key {
132
134
$(
133
135
stringify!( $field_name) => {
134
- $( let value = $tf ( value) ; ) ?
136
+ $( let value = $transform ( value) ; ) ?
135
137
self . $field_name. set( rem, value. as_ref( ) )
136
138
} ,
137
139
) *
@@ -160,6 +162,20 @@ macro_rules! config_namespace {
160
162
}
161
163
}
162
164
165
+ config_namespace ! {
166
+ /// Amazing config
167
+ pub struct MyConfig {
168
+ /// Field 1 doc
169
+ field1: String , transform = str :: to_lowercase, default = "" . to_string( )
170
+
171
+ /// Field 2 doc
172
+ field2: usize , default = 232
173
+
174
+ /// Field 3 doc
175
+ field3: Option <usize >, default = None
176
+ }
177
+ }
178
+
163
179
config_namespace ! {
164
180
/// Options related to catalog and directory scanning
165
181
///
@@ -220,7 +236,8 @@ config_namespace! {
220
236
221
237
/// Configure the SQL dialect used by DataFusion's parser; supported values include: Generic,
222
238
/// MySQL, PostgreSQL, Hive, SQLite, Snowflake, Redshift, MsSQL, ClickHouse, BigQuery, and Ansi.
223
- pub dialect: String , default = "generic" . to_string( ) // no need to lowercase because this is handled by [`sqlparser::dialect_from_str`]
239
+ pub dialect: String , default = "generic" . to_string( ) // no need to lowercase because
240
+ // [`sqlparser::dialect_from_str`] is case-insensitive
224
241
225
242
/// If true, permit lengths for `VARCHAR` such as `VARCHAR(20)`, but
226
243
/// ignore the length. If false, error if a `VARCHAR` with a length is
@@ -998,7 +1015,6 @@ macro_rules! config_field {
998
1015
Box :: new( DataFusionError :: External ( Box :: new( e) ) ) ,
999
1016
)
1000
1017
} ) ?;
1001
-
1002
1018
Ok ( ( ) )
1003
1019
}
1004
1020
}
0 commit comments