Skip to content

Commit 2f9143b

Browse files
psvrialamb
authored andcommitted
Refactor sessionconfig set fns to avoid an unnecessary enum to string conversion (apache#10141)
* Refactor sessionconfig set functions to avoid an uncessary enum to string conversion * Call set_str directly on usize --------- Co-authored-by: Andrew Lamb <[email protected]>
1 parent b8cc025 commit 2f9143b

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

datafusion/execution/src/config.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -157,30 +157,29 @@ impl SessionConfig {
157157
}
158158

159159
/// Set a configuration option
160-
pub fn set(mut self, key: &str, value: ScalarValue) -> Self {
161-
self.options.set(key, &value.to_string()).unwrap();
162-
self
160+
pub fn set(self, key: &str, value: ScalarValue) -> Self {
161+
self.set_str(key, &value.to_string())
163162
}
164163

165164
/// Set a boolean configuration option
166165
pub fn set_bool(self, key: &str, value: bool) -> Self {
167-
self.set(key, ScalarValue::Boolean(Some(value)))
166+
self.set_str(key, &value.to_string())
168167
}
169168

170169
/// Set a generic `u64` configuration option
171170
pub fn set_u64(self, key: &str, value: u64) -> Self {
172-
self.set(key, ScalarValue::UInt64(Some(value)))
171+
self.set_str(key, &value.to_string())
173172
}
174173

175174
/// Set a generic `usize` configuration option
176175
pub fn set_usize(self, key: &str, value: usize) -> Self {
177-
let value: u64 = value.try_into().expect("convert usize to u64");
178-
self.set(key, ScalarValue::UInt64(Some(value)))
176+
self.set_str(key, &value.to_string())
179177
}
180178

181179
/// Set a generic `str` configuration option
182-
pub fn set_str(self, key: &str, value: &str) -> Self {
183-
self.set(key, ScalarValue::from(value))
180+
pub fn set_str(mut self, key: &str, value: &str) -> Self {
181+
self.options.set(key, value).unwrap();
182+
self
184183
}
185184

186185
/// Customize batch size

0 commit comments

Comments
 (0)