comphead commented on code in PR #23054:
URL: https://github.com/apache/datafusion/pull/23054#discussion_r3447317118


##########
datafusion/common/src/config.rs:
##########
@@ -582,6 +583,87 @@ impl Display for SpillCompression {
     }
 }
 
+/// A `usize` configuration value that rejects zero when set from strings.
+///
+/// Use this for options where zero is never a meaningful runtime value. The
+/// default should be constructed with [`ConfigNonZeroUsize::new`] so invalid
+/// defaults fail at compile/test time, while user-provided values return a
+/// configuration error through [`ConfigField`].
+#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
+pub struct ConfigNonZeroUsize(NonZeroUsize);
+
+impl ConfigNonZeroUsize {
+    /// Creates a [`ConfigNonZeroUsize`], panicking if `value` is zero.
+    pub const fn new(value: usize) -> Self {
+        match NonZeroUsize::new(value) {
+            Some(value) => Self(value),
+            None => panic!("value must be greater than 0"),
+        }
+    }
+
+    /// Creates a [`ConfigNonZeroUsize`], returning a configuration error if
+    /// `value` is zero.
+    pub fn try_new(value: usize) -> Result<Self> {
+        NonZeroUsize::new(value).map(Self).ok_or_else(|| {
+            DataFusionError::Configuration("value must be greater than 
0".to_string())
+        })
+    }
+
+    /// Returns the wrapped `usize`.
+    pub const fn get(self) -> usize {
+        self.0.get()
+    }
+}
+
+impl From<ConfigNonZeroUsize> for usize {
+    fn from(value: ConfigNonZeroUsize) -> Self {
+        value.get()
+    }
+}
+
+impl FromStr for ConfigNonZeroUsize {
+    type Err = DataFusionError;
+
+    fn from_str(s: &str) -> Result<Self, Self::Err> {
+        Self::try_new(default_config_transform(s)?)
+    }
+}
+
+impl ConfigField for ConfigNonZeroUsize {
+    fn visit<V: Visit>(&self, v: &mut V, key: &str, description: &'static str) 
{
+        v.some(key, self, description)
+    }
+
+    fn set(&mut self, key: &str, value: &str) -> Result<()> {
+        if !key.is_empty() {
+            return _config_err!(
+                "Config field is a scalar ConfigNonZeroUsize and does not have 
nested field \"{}\"",

Review Comment:
   would be nice to add config field name here



##########
datafusion/common/src/config.rs:
##########
@@ -582,6 +583,87 @@ impl Display for SpillCompression {
     }
 }
 
+/// A `usize` configuration value that rejects zero when set from strings.
+///
+/// Use this for options where zero is never a meaningful runtime value. The
+/// default should be constructed with [`ConfigNonZeroUsize::new`] so invalid
+/// defaults fail at compile/test time, while user-provided values return a
+/// configuration error through [`ConfigField`].
+#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
+pub struct ConfigNonZeroUsize(NonZeroUsize);
+
+impl ConfigNonZeroUsize {
+    /// Creates a [`ConfigNonZeroUsize`], panicking if `value` is zero.
+    pub const fn new(value: usize) -> Self {
+        match NonZeroUsize::new(value) {
+            Some(value) => Self(value),
+            None => panic!("value must be greater than 0"),
+        }
+    }
+
+    /// Creates a [`ConfigNonZeroUsize`], returning a configuration error if
+    /// `value` is zero.
+    pub fn try_new(value: usize) -> Result<Self> {
+        NonZeroUsize::new(value).map(Self).ok_or_else(|| {
+            DataFusionError::Configuration("value must be greater than 
0".to_string())
+        })
+    }
+
+    /// Returns the wrapped `usize`.
+    pub const fn get(self) -> usize {
+        self.0.get()
+    }
+}
+
+impl From<ConfigNonZeroUsize> for usize {
+    fn from(value: ConfigNonZeroUsize) -> Self {
+        value.get()
+    }
+}
+
+impl FromStr for ConfigNonZeroUsize {
+    type Err = DataFusionError;
+
+    fn from_str(s: &str) -> Result<Self, Self::Err> {
+        Self::try_new(default_config_transform(s)?)
+    }
+}
+
+impl ConfigField for ConfigNonZeroUsize {
+    fn visit<V: Visit>(&self, v: &mut V, key: &str, description: &'static str) 
{
+        v.some(key, self, description)
+    }
+
+    fn set(&mut self, key: &str, value: &str) -> Result<()> {
+        if !key.is_empty() {
+            return _config_err!(
+                "Config field is a scalar ConfigNonZeroUsize and does not have 
nested field \"{}\"",

Review Comment:
   would be nice to add config name here



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to