Skip to content

Commit ffa5385

Browse files
committed
More notes
1 parent 364f453 commit ffa5385

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

datafusion/common/src/config.rs

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ use crate::{DataFusionError, Result};
3838
/// /// Amazing config
3939
/// pub struct MyConfig {
4040
/// /// Field 1 doc
41-
/// field1: String, default = "".to_string()
41+
/// field1: String, transform = str::to_lowercase, default = "".to_string()
4242
///
4343
/// /// Field 2 doc
4444
/// field2: usize, default = 232
@@ -67,9 +67,12 @@ use crate::{DataFusionError, Result};
6767
/// fn set(&mut self, key: &str, value: &str) -> Result<()> {
6868
/// let (key, rem) = key.split_once('.').unwrap_or((key, ""));
6969
/// 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()),
7376
/// _ => _internal_err!(
7477
/// "Config value \"{}\" not found on MyConfig",
7578
/// key
@@ -102,15 +105,14 @@ use crate::{DataFusionError, Result};
102105
/// ```
103106
///
104107
/// NB: Misplaced commas may result in nonsensical errors
105-
///
106108
#[macro_export]
107109
macro_rules! config_namespace {
108110
(
109111
$(#[doc = $struct_d:tt])*
110112
$vis:vis struct $struct_name:ident {
111113
$(
112114
$(#[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
114116
)*$(,)*
115117
}
116118
) => {
@@ -131,7 +133,7 @@ macro_rules! config_namespace {
131133
match key {
132134
$(
133135
stringify!($field_name) => {
134-
$(let value = $tf(value);)?
136+
$(let value = $transform(value);)?
135137
self.$field_name.set(rem, value.as_ref())
136138
},
137139
)*
@@ -160,6 +162,20 @@ macro_rules! config_namespace {
160162
}
161163
}
162164

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+
163179
config_namespace! {
164180
/// Options related to catalog and directory scanning
165181
///
@@ -220,7 +236,8 @@ config_namespace! {
220236

221237
/// Configure the SQL dialect used by DataFusion's parser; supported values include: Generic,
222238
/// 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
224241

225242
/// If true, permit lengths for `VARCHAR` such as `VARCHAR(20)`, but
226243
/// ignore the length. If false, error if a `VARCHAR` with a length is
@@ -998,7 +1015,6 @@ macro_rules! config_field {
9981015
Box::new(DataFusionError::External(Box::new(e))),
9991016
)
10001017
})?;
1001-
10021018
Ok(())
10031019
}
10041020
}

datafusion/core/tests/config_from_env.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ use std::env;
2121
#[test]
2222
fn from_env() {
2323
// Note: these must be a single test to avoid interference from concurrent execution
24-
2524
let env_key = "DATAFUSION_OPTIMIZER_FILTER_NULL_JOIN_KEYS";
26-
// valid testing
25+
// valid testing in different cases
2726
for bool_option in ["true", "TRUE", "True"] {
2827
env::set_var(env_key, bool_option);
2928
let config = ConfigOptions::from_env().unwrap();

0 commit comments

Comments
 (0)