#![doc(
html_logo_url = "https://raw.githubusercontent.com/apache/datafusion/19fe44cf2f30cbdd63d4a4f52c74055163c6cc38/docs/logos/standalone_logo/logo_original.svg",
html_favicon_url = "https://raw.githubusercontent.com/apache/datafusion/19fe44cf2f30cbdd63d4a4f52c74055163c6cc38/docs/logos/standalone_logo/logo_original.svg"
)]
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#![deny(clippy::clone_on_ref_ptr)]
use datafusion_common::Result;
use datafusion_execution::FunctionRegistry;
use datafusion_expr::ScalarUDF;
use log::debug;
use std::sync::Arc;
#[macro_use]
pub mod macros;
#[cfg(feature = "string_expressions")]
pub mod string;
make_stub_package!(string, "string_expressions");
pub mod core;
#[cfg(feature = "datetime_expressions")]
pub mod datetime;
make_stub_package!(datetime, "datetime_expressions");
#[cfg(feature = "encoding_expressions")]
pub mod encoding;
make_stub_package!(encoding, "encoding_expressions");
#[cfg(feature = "math_expressions")]
pub mod math;
make_stub_package!(math, "math_expressions");
#[cfg(feature = "regex_expressions")]
pub mod regex;
make_stub_package!(regex, "regex_expressions");
#[cfg(feature = "crypto_expressions")]
pub mod crypto;
make_stub_package!(crypto, "crypto_expressions");
#[cfg(feature = "unicode_expressions")]
pub mod unicode;
make_stub_package!(unicode, "unicode_expressions");
#[cfg(any(feature = "datetime_expressions", feature = "unicode_expressions"))]
pub mod planner;
pub mod strings;
pub mod utils;
pub mod expr_fn {
pub use super::core::expr_fn::*;
#[cfg(feature = "crypto_expressions")]
pub use super::crypto::expr_fn::*;
#[cfg(feature = "datetime_expressions")]
pub use super::datetime::expr_fn::*;
#[cfg(feature = "encoding_expressions")]
pub use super::encoding::expr_fn::*;
#[cfg(feature = "math_expressions")]
pub use super::math::expr_fn::*;
#[cfg(feature = "regex_expressions")]
pub use super::regex::expr_fn::*;
#[cfg(feature = "string_expressions")]
pub use super::string::expr_fn::*;
#[cfg(feature = "unicode_expressions")]
pub use super::unicode::expr_fn::*;
}
pub fn all_default_functions() -> Vec<Arc<ScalarUDF>> {
core::functions()
.into_iter()
.chain(datetime::functions())
.chain(encoding::functions())
.chain(math::functions())
.chain(regex::functions())
.chain(crypto::functions())
.chain(unicode::functions())
.chain(string::functions())
.collect::<Vec<_>>()
}
pub fn register_all(registry: &mut dyn FunctionRegistry) -> Result<()> {
let all_functions = all_default_functions();
all_functions.into_iter().try_for_each(|udf| {
let existing_udf = registry.register_udf(udf)?;
if let Some(existing_udf) = existing_udf {
debug!("Overwrite existing UDF: {}", existing_udf.name());
}
Ok(()) as Result<()>
})?;
Ok(())
}
#[cfg(test)]
mod tests {
use crate::all_default_functions;
use datafusion_common::Result;
use std::collections::HashSet;
#[test]
fn test_no_duplicate_name() -> Result<()> {
let mut names = HashSet::new();
for func in all_default_functions() {
assert!(
names.insert(func.name().to_string().to_lowercase()),
"duplicate function name: {}",
func.name()
);
for alias in func.aliases() {
assert!(
names.insert(alias.to_string().to_lowercase()),
"duplicate function name: {alias}"
);
}
}
Ok(())
}
}