diff --git a/datafusion/expr/src/built_in_function.rs b/datafusion/expr/src/built_in_function.rs index 744192e9a3e1..dc1fc98a5c02 100644 --- a/datafusion/expr/src/built_in_function.rs +++ b/datafusion/expr/src/built_in_function.rs @@ -37,18 +37,10 @@ use strum_macros::EnumIter; #[derive(Debug, Clone, PartialEq, Eq, Hash, EnumIter, Copy)] pub enum BuiltinScalarFunction { // math functions - /// cbrt - Cbrt, /// ceil Ceil, /// coalesce Coalesce, - /// cos - Cos, - /// cos - Cosh, - /// degrees - Degrees, /// exp Exp, /// factorial @@ -141,9 +133,6 @@ impl BuiltinScalarFunction { // Immutable scalar builtins BuiltinScalarFunction::Ceil => Volatility::Immutable, BuiltinScalarFunction::Coalesce => Volatility::Immutable, - BuiltinScalarFunction::Cos => Volatility::Immutable, - BuiltinScalarFunction::Cosh => Volatility::Immutable, - BuiltinScalarFunction::Degrees => Volatility::Immutable, BuiltinScalarFunction::Exp => Volatility::Immutable, BuiltinScalarFunction::Factorial => Volatility::Immutable, BuiltinScalarFunction::Floor => Volatility::Immutable, @@ -155,7 +144,6 @@ impl BuiltinScalarFunction { BuiltinScalarFunction::Pi => Volatility::Immutable, BuiltinScalarFunction::Power => Volatility::Immutable, BuiltinScalarFunction::Round => Volatility::Immutable, - BuiltinScalarFunction::Cbrt => Volatility::Immutable, BuiltinScalarFunction::Cot => Volatility::Immutable, BuiltinScalarFunction::Trunc => Volatility::Immutable, BuiltinScalarFunction::Concat => Volatility::Immutable, @@ -221,13 +209,9 @@ impl BuiltinScalarFunction { BuiltinScalarFunction::Iszero => Ok(Boolean), BuiltinScalarFunction::Ceil - | BuiltinScalarFunction::Cos - | BuiltinScalarFunction::Cosh - | BuiltinScalarFunction::Degrees | BuiltinScalarFunction::Exp | BuiltinScalarFunction::Floor | BuiltinScalarFunction::Round - | BuiltinScalarFunction::Cbrt | BuiltinScalarFunction::Trunc | BuiltinScalarFunction::Cot => match input_expr_types[0] { Float32 => Ok(Float32), @@ -308,11 +292,7 @@ impl BuiltinScalarFunction { BuiltinScalarFunction::Gcd | BuiltinScalarFunction::Lcm => { Signature::uniform(2, vec![Int64], self.volatility()) } - BuiltinScalarFunction::Cbrt - | BuiltinScalarFunction::Ceil - | BuiltinScalarFunction::Cos - | BuiltinScalarFunction::Cosh - | BuiltinScalarFunction::Degrees + BuiltinScalarFunction::Ceil | BuiltinScalarFunction::Exp | BuiltinScalarFunction::Floor | BuiltinScalarFunction::Cot => { @@ -337,12 +317,10 @@ impl BuiltinScalarFunction { if matches!( &self, BuiltinScalarFunction::Ceil - | BuiltinScalarFunction::Degrees | BuiltinScalarFunction::Exp | BuiltinScalarFunction::Factorial | BuiltinScalarFunction::Floor | BuiltinScalarFunction::Round - | BuiltinScalarFunction::Cbrt | BuiltinScalarFunction::Trunc | BuiltinScalarFunction::Pi ) { @@ -357,12 +335,8 @@ impl BuiltinScalarFunction { /// Returns all names that can be used to call this function pub fn aliases(&self) -> &'static [&'static str] { match self { - BuiltinScalarFunction::Cbrt => &["cbrt"], BuiltinScalarFunction::Ceil => &["ceil"], - BuiltinScalarFunction::Cos => &["cos"], BuiltinScalarFunction::Cot => &["cot"], - BuiltinScalarFunction::Cosh => &["cosh"], - BuiltinScalarFunction::Degrees => &["degrees"], BuiltinScalarFunction::Exp => &["exp"], BuiltinScalarFunction::Factorial => &["factorial"], BuiltinScalarFunction::Floor => &["floor"], diff --git a/datafusion/expr/src/expr_fn.rs b/datafusion/expr/src/expr_fn.rs index 5294ca754532..a1235a093d76 100644 --- a/datafusion/expr/src/expr_fn.rs +++ b/datafusion/expr/src/expr_fn.rs @@ -536,10 +536,7 @@ macro_rules! nary_scalar_expr { // generate methods for creating the supported unary/binary expressions // math functions -scalar_expr!(Cbrt, cbrt, num, "cube root of a number"); -scalar_expr!(Cos, cos, num, "cosine of a number"); scalar_expr!(Cot, cot, num, "cotangent of a number"); -scalar_expr!(Cosh, cosh, num, "hyperbolic cosine of a number"); scalar_expr!(Factorial, factorial, num, "factorial"); scalar_expr!( Floor, @@ -553,7 +550,6 @@ scalar_expr!( num, "nearest integer greater than or equal to argument" ); -scalar_expr!(Degrees, degrees, num, "converts radians to degrees"); nary_scalar_expr!(Round, round, "round to nearest integer"); nary_scalar_expr!( Trunc, @@ -1060,14 +1056,10 @@ mod test { #[test] fn scalar_function_definitions() { - test_unary_scalar_expr!(Cbrt, cbrt); - test_unary_scalar_expr!(Cos, cos); test_unary_scalar_expr!(Cot, cot); - test_unary_scalar_expr!(Cosh, cosh); test_unary_scalar_expr!(Factorial, factorial); test_unary_scalar_expr!(Floor, floor); test_unary_scalar_expr!(Ceil, ceil); - test_unary_scalar_expr!(Degrees, degrees); test_nary_scalar_expr!(Round, round, input); test_nary_scalar_expr!(Round, round, input, decimal_places); test_nary_scalar_expr!(Trunc, trunc, num); diff --git a/datafusion/expr/src/signature.rs b/datafusion/expr/src/signature.rs index 0d65c068c4a0..89f456f337f9 100644 --- a/datafusion/expr/src/signature.rs +++ b/datafusion/expr/src/signature.rs @@ -39,8 +39,7 @@ pub const FIXED_SIZE_LIST_WILDCARD: i32 = i32::MIN; #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Hash)] pub enum Volatility { /// An immutable function will always return the same output when given the same - /// input. An example of this is [super::BuiltinScalarFunction::Cos]. DataFusion - /// will attempt to inline immutable functions during planning. + /// input. DataFusion will attempt to inline immutable functions during planning. Immutable, /// A stable function may return different values given the same input across different /// queries but must return the same value for a given input within a query. An example of diff --git a/datafusion/functions/src/math/mod.rs b/datafusion/functions/src/math/mod.rs index a3ec2e3b90ce..f241c8b3250b 100644 --- a/datafusion/functions/src/math/mod.rs +++ b/datafusion/functions/src/math/mod.rs @@ -45,6 +45,11 @@ make_math_unary_udf!(SinFunc, SIN, sin, sin, None); make_math_unary_udf!(SinhFunc, SINH, sinh, sinh, None); make_math_unary_udf!(SqrtFunc, SQRT, sqrt, sqrt, None); +make_math_unary_udf!(CbrtFunc, CBRT, cbrt, cbrt, None); +make_math_unary_udf!(CosFunc, COS, cos, cos, None); +make_math_unary_udf!(CoshFunc, COSH, cosh, cosh, None); +make_math_unary_udf!(DegreesFunc, DEGREES, degrees, to_degrees, None); + // Export the functions out of this package, both as expr_fn as well as a list of functions export_functions!( ( @@ -77,5 +82,9 @@ export_functions!( (signum, num, "sign of the argument (-1, 0, +1)"), (sin, num, "sine"), (sinh, num, "hyperbolic sine"), - (sqrt, num, "square root of a number") + (sqrt, num, "square root of a number"), + (cbrt, num, "cube root of a number"), + (cos, num, "cosine"), + (cosh, num, "hyperbolic cosine"), + (degrees, num, "converts radians to degrees") ); diff --git a/datafusion/physical-expr/src/functions.rs b/datafusion/physical-expr/src/functions.rs index f201deb50f41..770d9184325a 100644 --- a/datafusion/physical-expr/src/functions.rs +++ b/datafusion/physical-expr/src/functions.rs @@ -180,9 +180,6 @@ pub fn create_physical_fun( Ok(match fun { // math functions BuiltinScalarFunction::Ceil => Arc::new(math_expressions::ceil), - BuiltinScalarFunction::Cos => Arc::new(math_expressions::cos), - BuiltinScalarFunction::Cosh => Arc::new(math_expressions::cosh), - BuiltinScalarFunction::Degrees => Arc::new(math_expressions::to_degrees), BuiltinScalarFunction::Exp => Arc::new(math_expressions::exp), BuiltinScalarFunction::Factorial => { Arc::new(|args| make_scalar_function_inner(math_expressions::factorial)(args)) @@ -204,7 +201,6 @@ pub fn create_physical_fun( BuiltinScalarFunction::Round => { Arc::new(|args| make_scalar_function_inner(math_expressions::round)(args)) } - BuiltinScalarFunction::Cbrt => Arc::new(math_expressions::cbrt), BuiltinScalarFunction::Trunc => { Arc::new(|args| make_scalar_function_inner(math_expressions::trunc)(args)) } diff --git a/datafusion/physical-expr/src/math_expressions.rs b/datafusion/physical-expr/src/math_expressions.rs index acccb9cb3cd3..f8244ad9525f 100644 --- a/datafusion/physical-expr/src/math_expressions.rs +++ b/datafusion/physical-expr/src/math_expressions.rs @@ -155,9 +155,6 @@ macro_rules! make_function_scalar_inputs_return_type { }}; } -math_unary_function!("cbrt", cbrt); -math_unary_function!("cos", cos); -math_unary_function!("cosh", cosh); math_unary_function!("asin", asin); math_unary_function!("acos", acos); math_unary_function!("atan", atan); @@ -170,7 +167,6 @@ math_unary_function!("exp", exp); math_unary_function!("ln", ln); math_unary_function!("log2", log2); math_unary_function!("log10", log10); -math_unary_function!("degrees", to_degrees); /// Factorial SQL function pub fn factorial(args: &[ArrayRef]) -> Result { diff --git a/datafusion/proto/proto/datafusion.proto b/datafusion/proto/proto/datafusion.proto index 22a73aff1837..6eb4a6b109ff 100644 --- a/datafusion/proto/proto/datafusion.proto +++ b/datafusion/proto/proto/datafusion.proto @@ -547,7 +547,7 @@ enum ScalarFunction { // 3 was Atan // 4 was Ascii Ceil = 5; - Cos = 6; + // 6 was Cos // 7 was Digest Exp = 8; Floor = 9; @@ -614,15 +614,15 @@ enum ScalarFunction { // 70 was CurrentDate // 71 was CurrentTime // 72 was Uuid - Cbrt = 73; + // 73 was Cbrt // 74 Acosh // 75 was Asinh // 76 was Atanh // 77 was Sinh - Cosh = 78; - // Tanh = 79; + // 78 was Cosh + // Tanh = 79 Pi = 80; - Degrees = 81; + // 81 was Degrees // 82 was Radians Factorial = 83; Lcm = 84; diff --git a/datafusion/proto/src/generated/pbjson.rs b/datafusion/proto/src/generated/pbjson.rs index aafb5b535b09..658f06cfc175 100644 --- a/datafusion/proto/src/generated/pbjson.rs +++ b/datafusion/proto/src/generated/pbjson.rs @@ -22915,7 +22915,6 @@ impl serde::Serialize for ScalarFunction { let variant = match self { Self::Unknown => "unknown", Self::Ceil => "Ceil", - Self::Cos => "Cos", Self::Exp => "Exp", Self::Floor => "Floor", Self::Log => "Log", @@ -22927,10 +22926,7 @@ impl serde::Serialize for ScalarFunction { Self::Random => "Random", Self::Coalesce => "Coalesce", Self::Power => "Power", - Self::Cbrt => "Cbrt", - Self::Cosh => "Cosh", Self::Pi => "Pi", - Self::Degrees => "Degrees", Self::Factorial => "Factorial", Self::Lcm => "Lcm", Self::Gcd => "Gcd", @@ -22951,7 +22947,6 @@ impl<'de> serde::Deserialize<'de> for ScalarFunction { const FIELDS: &[&str] = &[ "unknown", "Ceil", - "Cos", "Exp", "Floor", "Log", @@ -22963,10 +22958,7 @@ impl<'de> serde::Deserialize<'de> for ScalarFunction { "Random", "Coalesce", "Power", - "Cbrt", - "Cosh", "Pi", - "Degrees", "Factorial", "Lcm", "Gcd", @@ -23016,7 +23008,6 @@ impl<'de> serde::Deserialize<'de> for ScalarFunction { match value { "unknown" => Ok(ScalarFunction::Unknown), "Ceil" => Ok(ScalarFunction::Ceil), - "Cos" => Ok(ScalarFunction::Cos), "Exp" => Ok(ScalarFunction::Exp), "Floor" => Ok(ScalarFunction::Floor), "Log" => Ok(ScalarFunction::Log), @@ -23028,10 +23019,7 @@ impl<'de> serde::Deserialize<'de> for ScalarFunction { "Random" => Ok(ScalarFunction::Random), "Coalesce" => Ok(ScalarFunction::Coalesce), "Power" => Ok(ScalarFunction::Power), - "Cbrt" => Ok(ScalarFunction::Cbrt), - "Cosh" => Ok(ScalarFunction::Cosh), "Pi" => Ok(ScalarFunction::Pi), - "Degrees" => Ok(ScalarFunction::Degrees), "Factorial" => Ok(ScalarFunction::Factorial), "Lcm" => Ok(ScalarFunction::Lcm), "Gcd" => Ok(ScalarFunction::Gcd), diff --git a/datafusion/proto/src/generated/prost.rs b/datafusion/proto/src/generated/prost.rs index 81f390fff184..ea13bac0f62a 100644 --- a/datafusion/proto/src/generated/prost.rs +++ b/datafusion/proto/src/generated/prost.rs @@ -2846,7 +2846,7 @@ pub enum ScalarFunction { /// 3 was Atan /// 4 was Ascii Ceil = 5, - Cos = 6, + /// 6 was Cos /// 7 was Digest Exp = 8, Floor = 9, @@ -2913,15 +2913,15 @@ pub enum ScalarFunction { /// 70 was CurrentDate /// 71 was CurrentTime /// 72 was Uuid - Cbrt = 73, + /// 73 was Cbrt /// 74 Acosh /// 75 was Asinh /// 76 was Atanh /// 77 was Sinh - Cosh = 78, - /// Tanh = 79; + /// 78 was Cosh + /// Tanh = 79 Pi = 80, - Degrees = 81, + /// 81 was Degrees /// 82 was Radians Factorial = 83, Lcm = 84, @@ -2988,7 +2988,6 @@ impl ScalarFunction { match self { ScalarFunction::Unknown => "unknown", ScalarFunction::Ceil => "Ceil", - ScalarFunction::Cos => "Cos", ScalarFunction::Exp => "Exp", ScalarFunction::Floor => "Floor", ScalarFunction::Log => "Log", @@ -3000,10 +2999,7 @@ impl ScalarFunction { ScalarFunction::Random => "Random", ScalarFunction::Coalesce => "Coalesce", ScalarFunction::Power => "Power", - ScalarFunction::Cbrt => "Cbrt", - ScalarFunction::Cosh => "Cosh", ScalarFunction::Pi => "Pi", - ScalarFunction::Degrees => "Degrees", ScalarFunction::Factorial => "Factorial", ScalarFunction::Lcm => "Lcm", ScalarFunction::Gcd => "Gcd", @@ -3018,7 +3014,6 @@ impl ScalarFunction { match value { "unknown" => Some(Self::Unknown), "Ceil" => Some(Self::Ceil), - "Cos" => Some(Self::Cos), "Exp" => Some(Self::Exp), "Floor" => Some(Self::Floor), "Log" => Some(Self::Log), @@ -3030,10 +3025,7 @@ impl ScalarFunction { "Random" => Some(Self::Random), "Coalesce" => Some(Self::Coalesce), "Power" => Some(Self::Power), - "Cbrt" => Some(Self::Cbrt), - "Cosh" => Some(Self::Cosh), "Pi" => Some(Self::Pi), - "Degrees" => Some(Self::Degrees), "Factorial" => Some(Self::Factorial), "Lcm" => Some(Self::Lcm), "Gcd" => Some(Self::Gcd), diff --git a/datafusion/proto/src/logical_plan/from_proto.rs b/datafusion/proto/src/logical_plan/from_proto.rs index 6a536b2fa375..30d01cc7584c 100644 --- a/datafusion/proto/src/logical_plan/from_proto.rs +++ b/datafusion/proto/src/logical_plan/from_proto.rs @@ -37,8 +37,7 @@ use datafusion_expr::expr::Unnest; use datafusion_expr::expr::{Alias, Placeholder}; use datafusion_expr::window_frame::{check_window_frame, regularize_window_order_by}; use datafusion_expr::{ - cbrt, ceil, coalesce, concat_expr, concat_ws_expr, cos, cosh, cot, degrees, - ends_with, exp, + ceil, coalesce, concat_expr, concat_ws_expr, cot, ends_with, exp, expr::{self, InList, Sort, WindowFunction}, factorial, floor, gcd, initcap, iszero, lcm, log, logical_plan::{PlanType, StringifiedPlan}, @@ -421,13 +420,9 @@ impl From<&protobuf::ScalarFunction> for BuiltinScalarFunction { use protobuf::ScalarFunction; match f { ScalarFunction::Unknown => todo!(), - ScalarFunction::Cbrt => Self::Cbrt, - ScalarFunction::Cos => Self::Cos, ScalarFunction::Cot => Self::Cot, - ScalarFunction::Cosh => Self::Cosh, ScalarFunction::Exp => Self::Exp, ScalarFunction::Log => Self::Log, - ScalarFunction::Degrees => Self::Degrees, ScalarFunction::Factorial => Self::Factorial, ScalarFunction::Gcd => Self::Gcd, ScalarFunction::Lcm => Self::Lcm, @@ -1306,13 +1301,7 @@ pub fn parse_expr( match scalar_function { ScalarFunction::Unknown => Err(proto_error("Unknown scalar function")), - ScalarFunction::Cbrt => Ok(cbrt(parse_expr(&args[0], registry, codec)?)), - ScalarFunction::Cos => Ok(cos(parse_expr(&args[0], registry, codec)?)), - ScalarFunction::Cosh => Ok(cosh(parse_expr(&args[0], registry, codec)?)), ScalarFunction::Exp => Ok(exp(parse_expr(&args[0], registry, codec)?)), - ScalarFunction::Degrees => { - Ok(degrees(parse_expr(&args[0], registry, codec)?)) - } ScalarFunction::Floor => { Ok(floor(parse_expr(&args[0], registry, codec)?)) } diff --git a/datafusion/proto/src/logical_plan/to_proto.rs b/datafusion/proto/src/logical_plan/to_proto.rs index ab488f3f551b..4382ee0ff01c 100644 --- a/datafusion/proto/src/logical_plan/to_proto.rs +++ b/datafusion/proto/src/logical_plan/to_proto.rs @@ -1408,16 +1408,12 @@ impl TryFrom<&BuiltinScalarFunction> for protobuf::ScalarFunction { fn try_from(scalar: &BuiltinScalarFunction) -> Result { let scalar_function = match scalar { - BuiltinScalarFunction::Cbrt => Self::Cbrt, - BuiltinScalarFunction::Cos => Self::Cos, BuiltinScalarFunction::Cot => Self::Cot, - BuiltinScalarFunction::Cosh => Self::Cosh, BuiltinScalarFunction::Exp => Self::Exp, BuiltinScalarFunction::Factorial => Self::Factorial, BuiltinScalarFunction::Gcd => Self::Gcd, BuiltinScalarFunction::Lcm => Self::Lcm, BuiltinScalarFunction::Log => Self::Log, - BuiltinScalarFunction::Degrees => Self::Degrees, BuiltinScalarFunction::Floor => Self::Floor, BuiltinScalarFunction::Ceil => Self::Ceil, BuiltinScalarFunction::Round => Self::Round,