Skip to content

Apache DataFusion SQL Query Engine

refactor: reduce duplication in make_udf_function macro (#18733)

Shashidhar B M6cb3d7ec4e36
diff --git a/datafusion/functions/src/macros.rs b/datafusion/functions/src/macros.rs
index 077690cd3f..471b0a053e 100644
--- a/datafusion/functions/src/macros.rs
+++ b/datafusion/functions/src/macros.rs
@@ -83,7 +83,7 @@ macro_rules! export_functions {
/// This is used to ensure creating the list of `ScalarUDF` only happens once.
#[macro_export]
macro_rules! make_udf_function {
- ($UDF:ty, $NAME:ident) => {
+ ($UDF:ty, $NAME:ident, $CTOR:expr) => {
#[allow(rustdoc::redundant_explicit_links)]
#[doc = concat!("Return a [`ScalarUDF`](datafusion_expr::ScalarUDF) implementation of ", stringify!($NAME))]
pub fn $NAME() -> std::sync::Arc<datafusion_expr::ScalarUDF> {
@@ -92,26 +92,14 @@ macro_rules! make_udf_function {
std::sync::Arc<datafusion_expr::ScalarUDF>,
> = std::sync::LazyLock::new(|| {
std::sync::Arc::new(datafusion_expr::ScalarUDF::new_from_impl(
- <$UDF>::new(),
+ ($CTOR)(),
))
});
std::sync::Arc::clone(&INSTANCE)
}
};
- ($UDF:ty, $NAME:ident, $CTOR:path) => {
- #[allow(rustdoc::redundant_explicit_links)]
- #[doc = concat!("Return a [`ScalarUDF`](datafusion_expr::ScalarUDF) implementation of ", stringify!($NAME))]
- pub fn $NAME() -> std::sync::Arc<datafusion_expr::ScalarUDF> {
- // Singleton instance of the function
- static INSTANCE: std::sync::LazyLock<
- std::sync::Arc<datafusion_expr::ScalarUDF>,
- > = std::sync::LazyLock::new(|| {
- std::sync::Arc::new(datafusion_expr::ScalarUDF::new_from_impl(
- $CTOR(),
- ))
- });
- std::sync::Arc::clone(&INSTANCE)
- }
+ ($UDF:ty, $NAME:ident) => {
+ make_udf_function!($UDF, $NAME, <$UDF>::new);
};
}