Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
comphead committed Oct 24, 2024
1 parent e03085c commit 73a4764
Showing 1 changed file with 14 additions and 25 deletions.
39 changes: 14 additions & 25 deletions datafusion/functions/src/math/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

//! Math function: `log()`.
use datafusion_macros::udf_doc;
use std::any::Any;
use std::sync::{Arc, OnceLock};

Expand All @@ -37,7 +36,6 @@ use datafusion_expr::{
};
use datafusion_expr::{ScalarUDFImpl, Signature, Volatility};

#[udf_doc(description = "log_description", example = "log_example")]
#[derive(Debug)]
pub struct LogFunc {
signature: Signature,
Expand Down Expand Up @@ -110,11 +108,11 @@ impl ScalarUDFImpl for LogFunc {
};
match (num_sort_properties, base_sort_properties) {
(first @ SortProperties::Ordered(num), SortProperties::Ordered(base))
if num.descending != base.descending
&& num.nulls_first == base.nulls_first =>
{
Ok(first)
}
if num.descending != base.descending
&& num.nulls_first == base.nulls_first =>
{
Ok(first)
}
(
first @ (SortProperties::Ordered(_) | SortProperties::Singleton),
SortProperties::Singleton,
Expand Down Expand Up @@ -187,6 +185,10 @@ impl ScalarUDFImpl for LogFunc {
Ok(ColumnarValue::Array(arr))
}

fn documentation(&self) -> Option<&Documentation> {
Some(get_log_doc())
}

/// Simplify the `log` function by the relevant rules:
/// 1. Log(a, 1) ===> 0
/// 2. Log(a, Power(a, b)) ===> b
Expand Down Expand Up @@ -221,11 +223,11 @@ impl ScalarUDFImpl for LogFunc {
)?)))
}
Expr::ScalarFunction(ScalarFunction { func, mut args })
if is_pow(&func) && args.len() == 2 && base == args[0] =>
{
let b = args.pop().unwrap(); // length checked above
Ok(ExprSimplifyResult::Simplified(b))
}
if is_pow(&func) && args.len() == 2 && base == args[0] =>
{
let b = args.pop().unwrap(); // length checked above
Ok(ExprSimplifyResult::Simplified(b))
}
number => {
if number == base {
Ok(ExprSimplifyResult::Simplified(lit(ScalarValue::new_one(
Expand Down Expand Up @@ -265,7 +267,6 @@ mod tests {
use datafusion_common::DFSchema;
use datafusion_expr::execution_props::ExecutionProps;
use datafusion_expr::simplify::SimplifyContext;
use datafusion_pre_macros::DocumentationTest;

#[test]
#[should_panic]
Expand Down Expand Up @@ -653,16 +654,4 @@ mod tests {
SortProperties::Unordered
);
}

#[test]
fn test_doc() {
let log = LogFunc::new();
assert_eq!(
log.documentation_test(),
Some(DocumentationTest {
description: "log_description".to_string(),
syntax_example: "log_example".to_string(),
})
);
}
}

0 comments on commit 73a4764

Please sign in to comment.