subhramit commented on code in PR #24541:
URL: https://github.com/apache/datafusion/pull/24541#discussion_r3835506728
##########
datafusion/common/src/config.rs:
##########
@@ -748,6 +748,88 @@ impl Display for ConfigMinTwoUsize {
}
}
+/// Used for [`OptimizerOptions::default_filter_selectivity`] to represent
+/// an integer percentage value, when valid values are 0 to 100 inclusive.
+#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
+pub struct ConfigFilterSelectivity(u8);
+
+/// Private helper for hard-coded defaults in `config_namespace!`, which cannot
+/// use `?`. All external construction should use
+/// [`ConfigFilterSelectivity::try_new`].
+const fn filter_selectivity_default(value: u8) -> ConfigFilterSelectivity {
+ if value <= 100 {
+ ConfigFilterSelectivity(value)
+ } else {
+ panic!("value must be between 0 and 100")
+ }
+}
+
+impl ConfigFilterSelectivity {
+ /// Creates a [`ConfigFilterSelectivity`], returning a configuration error
+ /// if `value` is greater than 100.
+ pub fn try_new(value: u8) -> Result<Self> {
+ if value <= 100 {
+ Ok(Self(value))
+ } else {
+ _config_err!("value must be between 0 and 100, got {value}")
+ }
+ }
+
+ /// Returns the wrapped `u8`.
+ pub const fn get(self) -> u8 {
+ self.0
+ }
+}
+
+impl From<ConfigFilterSelectivity> for u8 {
+ fn from(value: ConfigFilterSelectivity) -> Self {
+ value.get()
+ }
+}
+
+impl FromStr for ConfigFilterSelectivity {
+ type Err = DataFusionError;
+
+ fn from_str(s: &str) -> Result<Self, Self::Err> {
+ Self::try_new(default_config_transform(s)?)
Review Comment:
That makes sense. Let me do that.
--
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]