This is an automated email from the ASF dual-hosted git repository.
alamb pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion.git
The following commit(s) were added to refs/heads/main by this push:
new 46bcb03a14 Fix config_namespace macro symbol usage (#14520)
46bcb03a14 is described below
commit 46bcb03a14dc5a861ece3309fa903b0e290482a7
Author: Paul J. Davis <[email protected]>
AuthorDate: Fri Feb 7 10:13:34 2025 -0600
Fix config_namespace macro symbol usage (#14520)
* Fix config_namespace macro symbol usage
The `config_namespace` macro was relying on a few symbols being properly
imported before its used. This removes that need by referring to the
symbols directly with the `$crate` prefix.
* Move macro hygiene test
---
datafusion/common/src/config.rs | 9 +++++----
datafusion/core/tests/macro_hygiene/mod.rs | 16 ++++++++++++++++
2 files changed, 21 insertions(+), 4 deletions(-)
diff --git a/datafusion/common/src/config.rs b/datafusion/common/src/config.rs
index 320417c35a..c9900204b9 100644
--- a/datafusion/common/src/config.rs
+++ b/datafusion/common/src/config.rs
@@ -108,6 +108,7 @@ use crate::{DataFusionError, Result};
/// ```
///
/// NB: Misplaced commas may result in nonsensical errors
+#[macro_export]
macro_rules! config_namespace {
(
$(#[doc = $struct_d:tt])* // Struct-level documentation attributes
@@ -138,8 +139,8 @@ macro_rules! config_namespace {
)*
}
- impl ConfigField for $struct_name {
- fn set(&mut self, key: &str, value: &str) -> Result<()> {
+ impl $crate::config::ConfigField for $struct_name {
+ fn set(&mut self, key: &str, value: &str) ->
$crate::error::Result<()> {
let (key, rem) = key.split_once('.').unwrap_or((key, ""));
match key {
$(
@@ -154,13 +155,13 @@ macro_rules! config_namespace {
}
},
)*
- _ => return _config_err!(
+ _ => return $crate::error::_config_err!(
"Config value \"{}\" not found on {}", key,
stringify!($struct_name)
)
}
}
- fn visit<V: Visit>(&self, v: &mut V, key_prefix: &str,
_description: &'static str) {
+ fn visit<V: $crate::config::Visit>(&self, v: &mut V, key_prefix:
&str, _description: &'static str) {
$(
let key = format!(concat!("{}.", stringify!($field_name)),
key_prefix);
let desc = concat!($($d),*).trim();
diff --git a/datafusion/core/tests/macro_hygiene/mod.rs
b/datafusion/core/tests/macro_hygiene/mod.rs
index 5aff1d5e32..9196efec97 100644
--- a/datafusion/core/tests/macro_hygiene/mod.rs
+++ b/datafusion/core/tests/macro_hygiene/mod.rs
@@ -49,3 +49,19 @@ mod record_batch {
record_batch!(("column_name", Int32, vec![1, 2, 3])).unwrap();
}
}
+
+mod config_namespace {
+ // NO other imports!
+ use datafusion_common::config_namespace;
+
+ #[test]
+ fn test_macro() {
+ config_namespace! {
+ /// A config section
+ pub struct Foo {
+ /// Some doc comments
+ pub bar: bool, default = true
+ }
+ }
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]