diff --git a/datafusion/expr/src/built_in_function.rs b/datafusion/expr/src/built_in_function.rs index a1b3b717392e..744192e9a3e1 100644 --- a/datafusion/expr/src/built_in_function.rs +++ b/datafusion/expr/src/built_in_function.rs @@ -69,18 +69,8 @@ pub enum BuiltinScalarFunction { Pi, /// power Power, - /// radians - Radians, /// round Round, - /// signum - Signum, - /// sin - Sin, - /// sinh - Sinh, - /// sqrt - Sqrt, /// trunc Trunc, /// cot @@ -165,10 +155,6 @@ impl BuiltinScalarFunction { BuiltinScalarFunction::Pi => Volatility::Immutable, BuiltinScalarFunction::Power => Volatility::Immutable, BuiltinScalarFunction::Round => Volatility::Immutable, - BuiltinScalarFunction::Signum => Volatility::Immutable, - BuiltinScalarFunction::Sin => Volatility::Immutable, - BuiltinScalarFunction::Sinh => Volatility::Immutable, - BuiltinScalarFunction::Sqrt => Volatility::Immutable, BuiltinScalarFunction::Cbrt => Volatility::Immutable, BuiltinScalarFunction::Cot => Volatility::Immutable, BuiltinScalarFunction::Trunc => Volatility::Immutable, @@ -176,7 +162,6 @@ impl BuiltinScalarFunction { BuiltinScalarFunction::ConcatWithSeparator => Volatility::Immutable, BuiltinScalarFunction::EndsWith => Volatility::Immutable, BuiltinScalarFunction::InitCap => Volatility::Immutable, - BuiltinScalarFunction::Radians => Volatility::Immutable, // Volatile builtin functions BuiltinScalarFunction::Random => Volatility::Volatile, @@ -241,12 +226,7 @@ impl BuiltinScalarFunction { | BuiltinScalarFunction::Degrees | BuiltinScalarFunction::Exp | BuiltinScalarFunction::Floor - | BuiltinScalarFunction::Radians | BuiltinScalarFunction::Round - | BuiltinScalarFunction::Signum - | BuiltinScalarFunction::Sin - | BuiltinScalarFunction::Sinh - | BuiltinScalarFunction::Sqrt | BuiltinScalarFunction::Cbrt | BuiltinScalarFunction::Trunc | BuiltinScalarFunction::Cot => match input_expr_types[0] { @@ -335,11 +315,6 @@ impl BuiltinScalarFunction { | BuiltinScalarFunction::Degrees | BuiltinScalarFunction::Exp | BuiltinScalarFunction::Floor - | BuiltinScalarFunction::Radians - | BuiltinScalarFunction::Signum - | BuiltinScalarFunction::Sin - | BuiltinScalarFunction::Sinh - | BuiltinScalarFunction::Sqrt | BuiltinScalarFunction::Cot => { // math expressions expect 1 argument of type f64 or f32 // priority is given to f64 because e.g. `sqrt(1i32)` is in IR (real numbers) and thus we @@ -366,11 +341,7 @@ impl BuiltinScalarFunction { | BuiltinScalarFunction::Exp | BuiltinScalarFunction::Factorial | BuiltinScalarFunction::Floor - | BuiltinScalarFunction::Radians | BuiltinScalarFunction::Round - | BuiltinScalarFunction::Signum - | BuiltinScalarFunction::Sinh - | BuiltinScalarFunction::Sqrt | BuiltinScalarFunction::Cbrt | BuiltinScalarFunction::Trunc | BuiltinScalarFunction::Pi @@ -402,13 +373,8 @@ impl BuiltinScalarFunction { BuiltinScalarFunction::Nanvl => &["nanvl"], BuiltinScalarFunction::Pi => &["pi"], BuiltinScalarFunction::Power => &["power", "pow"], - BuiltinScalarFunction::Radians => &["radians"], BuiltinScalarFunction::Random => &["random"], BuiltinScalarFunction::Round => &["round"], - BuiltinScalarFunction::Signum => &["signum"], - BuiltinScalarFunction::Sin => &["sin"], - BuiltinScalarFunction::Sinh => &["sinh"], - BuiltinScalarFunction::Sqrt => &["sqrt"], BuiltinScalarFunction::Trunc => &["trunc"], // conditional functions diff --git a/datafusion/expr/src/expr_fn.rs b/datafusion/expr/src/expr_fn.rs index a2015787040f..1aa063b17539 100644 --- a/datafusion/expr/src/expr_fn.rs +++ b/datafusion/expr/src/expr_fn.rs @@ -534,12 +534,9 @@ macro_rules! nary_scalar_expr { // generate methods for creating the supported unary/binary expressions // math functions -scalar_expr!(Sqrt, sqrt, num, "square root of a number"); scalar_expr!(Cbrt, cbrt, num, "cube root of a number"); -scalar_expr!(Sin, sin, num, "sine"); scalar_expr!(Cos, cos, num, "cosine"); scalar_expr!(Cot, cot, num, "cotangent"); -scalar_expr!(Sinh, sinh, num, "hyperbolic sine"); scalar_expr!(Cosh, cosh, num, "hyperbolic cosine"); scalar_expr!(Factorial, factorial, num, "factorial"); scalar_expr!( @@ -555,14 +552,12 @@ scalar_expr!( "nearest integer greater than or equal to argument" ); scalar_expr!(Degrees, degrees, num, "converts radians to degrees"); -scalar_expr!(Radians, radians, num, "converts degrees to radians"); nary_scalar_expr!(Round, round, "round to nearest integer"); nary_scalar_expr!( Trunc, trunc, "truncate toward zero, with optional precision" ); -scalar_expr!(Signum, signum, num, "sign of the argument (-1, 0, +1) "); scalar_expr!(Exp, exp, num, "exponential"); scalar_expr!(Gcd, gcd, arg_1 arg_2, "greatest common divisor"); scalar_expr!(Lcm, lcm, arg_1 arg_2, "least common multiple"); @@ -885,8 +880,8 @@ impl WindowUDFImpl for SimpleWindowUDF { /// ``` /// use datafusion_expr::{col, lit, call_fn}; /// -/// // create the expression sin(x) < 0.2 -/// let expr = call_fn("sin", vec![col("x")]).unwrap().lt(lit(0.2)); +/// // create the expression trunc(x) < 0.2 +/// let expr = call_fn("trunc", vec![col("x")]).unwrap().lt(lit(0.2)); /// ``` pub fn call_fn(name: impl AsRef, args: Vec) -> Result { match name.as_ref().parse::() { @@ -967,23 +962,18 @@ mod test { #[test] fn scalar_function_definitions() { - test_unary_scalar_expr!(Sqrt, sqrt); test_unary_scalar_expr!(Cbrt, cbrt); - test_unary_scalar_expr!(Sin, sin); test_unary_scalar_expr!(Cos, cos); test_unary_scalar_expr!(Cot, cot); - test_unary_scalar_expr!(Sinh, sinh); 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_unary_scalar_expr!(Radians, radians); test_nary_scalar_expr!(Round, round, input); test_nary_scalar_expr!(Round, round, input, decimal_places); test_nary_scalar_expr!(Trunc, trunc, num); test_nary_scalar_expr!(Trunc, trunc, num, precision); - test_unary_scalar_expr!(Signum, signum); test_unary_scalar_expr!(Exp, exp); test_scalar_expr!(Nanvl, nanvl, x, y); test_scalar_expr!(Iszero, iszero, input); diff --git a/datafusion/functions/src/math/mod.rs b/datafusion/functions/src/math/mod.rs index ee53fcf96a8b..d6a44cfbdbf5 100644 --- a/datafusion/functions/src/math/mod.rs +++ b/datafusion/functions/src/math/mod.rs @@ -39,6 +39,12 @@ make_math_unary_udf!(AcoshFunc, ACOSH, acosh, acosh, Some(vec![Some(true)])); make_math_unary_udf!(AtanFunc, ATAN, atan, atan, Some(vec![Some(true)])); make_math_binary_udf!(Atan2, ATAN2, atan2, atan2, Some(vec![Some(true)])); +make_math_unary_udf!(RadiansFunc, RADIANS, radians, to_radians, None); +make_math_unary_udf!(SignumFunc, SIGNUM, signum, signum, None); +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); + // Export the functions out of this package, both as expr_fn as well as a list of functions export_functions!( ( @@ -66,5 +72,10 @@ export_functions!( (asinh, num, "returns inverse hyperbolic sine"), (acosh, num, "returns inverse hyperbolic cosine"), (atan, num, "returns inverse tangent"), - (atan2, y x, "returns inverse tangent of a division given in the argument") + (atan2, y x, "returns inverse tangent of a division given in the argument"), + (radians, num, "converts degrees to radians"), + (signum, num, "sign of the argument (-1, 0, +1)"), + (sin, num, "sine"), + (sinh, num, "hyperbolic sine"), + (sqrt, num, "square root of a number") ); diff --git a/datafusion/physical-expr/src/functions.rs b/datafusion/physical-expr/src/functions.rs index a1e471bdd422..f7be2704ab79 100644 --- a/datafusion/physical-expr/src/functions.rs +++ b/datafusion/physical-expr/src/functions.rs @@ -200,15 +200,10 @@ pub fn create_physical_fun( BuiltinScalarFunction::Nanvl => { Arc::new(|args| make_scalar_function_inner(math_expressions::nanvl)(args)) } - BuiltinScalarFunction::Radians => Arc::new(math_expressions::to_radians), BuiltinScalarFunction::Random => Arc::new(math_expressions::random), BuiltinScalarFunction::Round => { Arc::new(|args| make_scalar_function_inner(math_expressions::round)(args)) } - BuiltinScalarFunction::Signum => Arc::new(math_expressions::signum), - BuiltinScalarFunction::Sin => Arc::new(math_expressions::sin), - BuiltinScalarFunction::Sinh => Arc::new(math_expressions::sinh), - BuiltinScalarFunction::Sqrt => Arc::new(math_expressions::sqrt), 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 5339c12f6e93..acccb9cb3cd3 100644 --- a/datafusion/physical-expr/src/math_expressions.rs +++ b/datafusion/physical-expr/src/math_expressions.rs @@ -155,11 +155,8 @@ macro_rules! make_function_scalar_inputs_return_type { }}; } -math_unary_function!("sqrt", sqrt); math_unary_function!("cbrt", cbrt); -math_unary_function!("sin", sin); math_unary_function!("cos", cos); -math_unary_function!("sinh", sinh); math_unary_function!("cosh", cosh); math_unary_function!("asin", asin); math_unary_function!("acos", acos); @@ -169,13 +166,11 @@ math_unary_function!("acosh", acosh); math_unary_function!("atanh", atanh); math_unary_function!("floor", floor); math_unary_function!("ceil", ceil); -math_unary_function!("signum", signum); 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); -math_unary_function!("radians", to_radians); /// Factorial SQL function pub fn factorial(args: &[ArrayRef]) -> Result { diff --git a/datafusion/proto/proto/datafusion.proto b/datafusion/proto/proto/datafusion.proto index e959cad2a810..22a73aff1837 100644 --- a/datafusion/proto/proto/datafusion.proto +++ b/datafusion/proto/proto/datafusion.proto @@ -556,9 +556,9 @@ enum ScalarFunction { // 12 was Log10 // 13 was Log2 Round = 14; - Signum = 15; - Sin = 16; - Sqrt = 17; + // 15 was Signum + // 16 was Sin + // 17 was Sqrt // Tan = 18; Trunc = 19; // 20 was Array @@ -618,12 +618,12 @@ enum ScalarFunction { // 74 Acosh // 75 was Asinh // 76 was Atanh - Sinh = 77; + // 77 was Sinh Cosh = 78; // Tanh = 79; Pi = 80; Degrees = 81; - Radians = 82; + // 82 was Radians Factorial = 83; Lcm = 84; Gcd = 85; diff --git a/datafusion/proto/src/generated/pbjson.rs b/datafusion/proto/src/generated/pbjson.rs index d900d0031df3..aafb5b535b09 100644 --- a/datafusion/proto/src/generated/pbjson.rs +++ b/datafusion/proto/src/generated/pbjson.rs @@ -22920,9 +22920,6 @@ impl serde::Serialize for ScalarFunction { Self::Floor => "Floor", Self::Log => "Log", Self::Round => "Round", - Self::Signum => "Signum", - Self::Sin => "Sin", - Self::Sqrt => "Sqrt", Self::Trunc => "Trunc", Self::Concat => "Concat", Self::ConcatWithSeparator => "ConcatWithSeparator", @@ -22931,11 +22928,9 @@ impl serde::Serialize for ScalarFunction { Self::Coalesce => "Coalesce", Self::Power => "Power", Self::Cbrt => "Cbrt", - Self::Sinh => "Sinh", Self::Cosh => "Cosh", Self::Pi => "Pi", Self::Degrees => "Degrees", - Self::Radians => "Radians", Self::Factorial => "Factorial", Self::Lcm => "Lcm", Self::Gcd => "Gcd", @@ -22961,9 +22956,6 @@ impl<'de> serde::Deserialize<'de> for ScalarFunction { "Floor", "Log", "Round", - "Signum", - "Sin", - "Sqrt", "Trunc", "Concat", "ConcatWithSeparator", @@ -22972,11 +22964,9 @@ impl<'de> serde::Deserialize<'de> for ScalarFunction { "Coalesce", "Power", "Cbrt", - "Sinh", "Cosh", "Pi", "Degrees", - "Radians", "Factorial", "Lcm", "Gcd", @@ -23031,9 +23021,6 @@ impl<'de> serde::Deserialize<'de> for ScalarFunction { "Floor" => Ok(ScalarFunction::Floor), "Log" => Ok(ScalarFunction::Log), "Round" => Ok(ScalarFunction::Round), - "Signum" => Ok(ScalarFunction::Signum), - "Sin" => Ok(ScalarFunction::Sin), - "Sqrt" => Ok(ScalarFunction::Sqrt), "Trunc" => Ok(ScalarFunction::Trunc), "Concat" => Ok(ScalarFunction::Concat), "ConcatWithSeparator" => Ok(ScalarFunction::ConcatWithSeparator), @@ -23042,11 +23029,9 @@ impl<'de> serde::Deserialize<'de> for ScalarFunction { "Coalesce" => Ok(ScalarFunction::Coalesce), "Power" => Ok(ScalarFunction::Power), "Cbrt" => Ok(ScalarFunction::Cbrt), - "Sinh" => Ok(ScalarFunction::Sinh), "Cosh" => Ok(ScalarFunction::Cosh), "Pi" => Ok(ScalarFunction::Pi), "Degrees" => Ok(ScalarFunction::Degrees), - "Radians" => Ok(ScalarFunction::Radians), "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 753abb4e2756..81f390fff184 100644 --- a/datafusion/proto/src/generated/prost.rs +++ b/datafusion/proto/src/generated/prost.rs @@ -2855,9 +2855,9 @@ pub enum ScalarFunction { /// 12 was Log10 /// 13 was Log2 Round = 14, - Signum = 15, - Sin = 16, - Sqrt = 17, + /// 15 was Signum + /// 16 was Sin + /// 17 was Sqrt /// Tan = 18; Trunc = 19, /// 20 was Array @@ -2917,12 +2917,12 @@ pub enum ScalarFunction { /// 74 Acosh /// 75 was Asinh /// 76 was Atanh - Sinh = 77, + /// 77 was Sinh Cosh = 78, /// Tanh = 79; Pi = 80, Degrees = 81, - Radians = 82, + /// 82 was Radians Factorial = 83, Lcm = 84, Gcd = 85, @@ -2993,9 +2993,6 @@ impl ScalarFunction { ScalarFunction::Floor => "Floor", ScalarFunction::Log => "Log", ScalarFunction::Round => "Round", - ScalarFunction::Signum => "Signum", - ScalarFunction::Sin => "Sin", - ScalarFunction::Sqrt => "Sqrt", ScalarFunction::Trunc => "Trunc", ScalarFunction::Concat => "Concat", ScalarFunction::ConcatWithSeparator => "ConcatWithSeparator", @@ -3004,11 +3001,9 @@ impl ScalarFunction { ScalarFunction::Coalesce => "Coalesce", ScalarFunction::Power => "Power", ScalarFunction::Cbrt => "Cbrt", - ScalarFunction::Sinh => "Sinh", ScalarFunction::Cosh => "Cosh", ScalarFunction::Pi => "Pi", ScalarFunction::Degrees => "Degrees", - ScalarFunction::Radians => "Radians", ScalarFunction::Factorial => "Factorial", ScalarFunction::Lcm => "Lcm", ScalarFunction::Gcd => "Gcd", @@ -3028,9 +3023,6 @@ impl ScalarFunction { "Floor" => Some(Self::Floor), "Log" => Some(Self::Log), "Round" => Some(Self::Round), - "Signum" => Some(Self::Signum), - "Sin" => Some(Self::Sin), - "Sqrt" => Some(Self::Sqrt), "Trunc" => Some(Self::Trunc), "Concat" => Some(Self::Concat), "ConcatWithSeparator" => Some(Self::ConcatWithSeparator), @@ -3039,11 +3031,9 @@ impl ScalarFunction { "Coalesce" => Some(Self::Coalesce), "Power" => Some(Self::Power), "Cbrt" => Some(Self::Cbrt), - "Sinh" => Some(Self::Sinh), "Cosh" => Some(Self::Cosh), "Pi" => Some(Self::Pi), "Degrees" => Some(Self::Degrees), - "Radians" => Some(Self::Radians), "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 b39ce41bbe26..3694418412b1 100644 --- a/datafusion/proto/src/logical_plan/from_proto.rs +++ b/datafusion/proto/src/logical_plan/from_proto.rs @@ -42,9 +42,9 @@ use datafusion_expr::{ expr::{self, InList, Sort, WindowFunction}, factorial, floor, gcd, initcap, iszero, lcm, log, logical_plan::{PlanType, StringifiedPlan}, - nanvl, pi, power, radians, random, round, signum, sin, sinh, sqrt, trunc, - AggregateFunction, Between, BinaryExpr, BuiltInWindowFunction, BuiltinScalarFunction, - Case, Cast, Expr, GetFieldAccess, GetIndexedField, GroupingSet, + nanvl, pi, power, random, round, trunc, AggregateFunction, Between, BinaryExpr, + BuiltInWindowFunction, BuiltinScalarFunction, Case, Cast, Expr, GetFieldAccess, + GetIndexedField, GroupingSet, GroupingSet::GroupingSets, JoinConstraint, JoinType, Like, Operator, TryCast, WindowFrame, WindowFrameBound, WindowFrameUnits, @@ -421,17 +421,13 @@ impl From<&protobuf::ScalarFunction> for BuiltinScalarFunction { use protobuf::ScalarFunction; match f { ScalarFunction::Unknown => todo!(), - ScalarFunction::Sqrt => Self::Sqrt, ScalarFunction::Cbrt => Self::Cbrt, - ScalarFunction::Sin => Self::Sin, ScalarFunction::Cos => Self::Cos, ScalarFunction::Cot => Self::Cot, - ScalarFunction::Sinh => Self::Sinh, ScalarFunction::Cosh => Self::Cosh, ScalarFunction::Exp => Self::Exp, ScalarFunction::Log => Self::Log, ScalarFunction::Degrees => Self::Degrees, - ScalarFunction::Radians => Self::Radians, ScalarFunction::Factorial => Self::Factorial, ScalarFunction::Gcd => Self::Gcd, ScalarFunction::Lcm => Self::Lcm, @@ -440,7 +436,6 @@ impl From<&protobuf::ScalarFunction> for BuiltinScalarFunction { ScalarFunction::Round => Self::Round, ScalarFunction::Trunc => Self::Trunc, ScalarFunction::Concat => Self::Concat, - ScalarFunction::Signum => Self::Signum, ScalarFunction::ConcatWithSeparator => Self::ConcatWithSeparator, ScalarFunction::EndsWith => Self::EndsWith, ScalarFunction::InitCap => Self::InitCap, @@ -1311,19 +1306,13 @@ pub fn parse_expr( match scalar_function { ScalarFunction::Unknown => Err(proto_error("Unknown scalar function")), - ScalarFunction::Sqrt => Ok(sqrt(parse_expr(&args[0], registry, codec)?)), ScalarFunction::Cbrt => Ok(cbrt(parse_expr(&args[0], registry, codec)?)), - ScalarFunction::Sin => Ok(sin(parse_expr(&args[0], registry, codec)?)), ScalarFunction::Cos => Ok(cos(parse_expr(&args[0], registry, codec)?)), - ScalarFunction::Sinh => Ok(sinh(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::Radians => { - Ok(radians(parse_expr(&args[0], registry, codec)?)) - } ScalarFunction::Floor => { Ok(floor(parse_expr(&args[0], registry, codec)?)) } @@ -1333,9 +1322,6 @@ pub fn parse_expr( ScalarFunction::Ceil => Ok(ceil(parse_expr(&args[0], registry, codec)?)), ScalarFunction::Round => Ok(round(parse_exprs(args, registry, codec)?)), ScalarFunction::Trunc => Ok(trunc(parse_exprs(args, registry, codec)?)), - ScalarFunction::Signum => { - Ok(signum(parse_expr(&args[0], registry, codec)?)) - } ScalarFunction::InitCap => { Ok(initcap(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 39f8a913db94..ab488f3f551b 100644 --- a/datafusion/proto/src/logical_plan/to_proto.rs +++ b/datafusion/proto/src/logical_plan/to_proto.rs @@ -1408,12 +1408,9 @@ impl TryFrom<&BuiltinScalarFunction> for protobuf::ScalarFunction { fn try_from(scalar: &BuiltinScalarFunction) -> Result { let scalar_function = match scalar { - BuiltinScalarFunction::Sqrt => Self::Sqrt, BuiltinScalarFunction::Cbrt => Self::Cbrt, - BuiltinScalarFunction::Sin => Self::Sin, BuiltinScalarFunction::Cos => Self::Cos, BuiltinScalarFunction::Cot => Self::Cot, - BuiltinScalarFunction::Sinh => Self::Sinh, BuiltinScalarFunction::Cosh => Self::Cosh, BuiltinScalarFunction::Exp => Self::Exp, BuiltinScalarFunction::Factorial => Self::Factorial, @@ -1421,13 +1418,11 @@ impl TryFrom<&BuiltinScalarFunction> for protobuf::ScalarFunction { BuiltinScalarFunction::Lcm => Self::Lcm, BuiltinScalarFunction::Log => Self::Log, BuiltinScalarFunction::Degrees => Self::Degrees, - BuiltinScalarFunction::Radians => Self::Radians, BuiltinScalarFunction::Floor => Self::Floor, BuiltinScalarFunction::Ceil => Self::Ceil, BuiltinScalarFunction::Round => Self::Round, BuiltinScalarFunction::Trunc => Self::Trunc, BuiltinScalarFunction::Concat => Self::Concat, - BuiltinScalarFunction::Signum => Self::Signum, BuiltinScalarFunction::ConcatWithSeparator => Self::ConcatWithSeparator, BuiltinScalarFunction::EndsWith => Self::EndsWith, BuiltinScalarFunction::InitCap => Self::InitCap, diff --git a/datafusion/proto/tests/cases/roundtrip_logical_plan.rs b/datafusion/proto/tests/cases/roundtrip_logical_plan.rs index 22543c0dd1bf..4cd133dc21d4 100644 --- a/datafusion/proto/tests/cases/roundtrip_logical_plan.rs +++ b/datafusion/proto/tests/cases/roundtrip_logical_plan.rs @@ -45,11 +45,10 @@ use datafusion_expr::expr::{ }; use datafusion_expr::logical_plan::{Extension, UserDefinedLogicalNodeCore}; use datafusion_expr::{ - col, create_udaf, lit, Accumulator, AggregateFunction, BuiltinScalarFunction::Sqrt, - ColumnarValue, Expr, ExprSchemable, LogicalPlan, Operator, PartitionEvaluator, - ScalarUDF, ScalarUDFImpl, Signature, TryCast, Volatility, WindowFrame, - WindowFrameBound, WindowFrameUnits, WindowFunctionDefinition, WindowUDF, - WindowUDFImpl, + col, create_udaf, lit, Accumulator, AggregateFunction, ColumnarValue, Expr, + ExprSchemable, LogicalPlan, Operator, PartitionEvaluator, ScalarUDF, ScalarUDFImpl, + Signature, TryCast, Volatility, WindowFrame, WindowFrameBound, WindowFrameUnits, + WindowFunctionDefinition, WindowUDF, WindowUDFImpl, }; use datafusion_proto::bytes::{ logical_plan_from_bytes, logical_plan_from_bytes_with_extension_codec, @@ -1623,13 +1622,6 @@ fn roundtrip_qualified_wildcard() { roundtrip_expr_test(test_expr, ctx); } -#[test] -fn roundtrip_sqrt() { - let test_expr = Expr::ScalarFunction(ScalarFunction::new(Sqrt, vec![col("col")])); - let ctx = SessionContext::new(); - roundtrip_expr_test(test_expr, ctx); -} - #[test] fn roundtrip_like() { fn like(negated: bool, escape_char: Option) { diff --git a/datafusion/proto/tests/cases/roundtrip_physical_plan.rs b/datafusion/proto/tests/cases/roundtrip_physical_plan.rs index 4924128ae190..0238291c77e1 100644 --- a/datafusion/proto/tests/cases/roundtrip_physical_plan.rs +++ b/datafusion/proto/tests/cases/roundtrip_physical_plan.rs @@ -609,14 +609,14 @@ fn roundtrip_builtin_scalar_function() -> Result<()> { let input = Arc::new(EmptyExec::new(schema.clone())); - let fun_def = ScalarFunctionDefinition::BuiltIn(BuiltinScalarFunction::Sin); + let fun_def = ScalarFunctionDefinition::BuiltIn(BuiltinScalarFunction::Trunc); let expr = ScalarFunctionExpr::new( - "sin", + "trunc", fun_def, vec![col("a", &schema)?], DataType::Float64, - None, + Some(vec![Some(true)]), false, ); diff --git a/datafusion/sql/tests/sql_integration.rs b/datafusion/sql/tests/sql_integration.rs index a34f8f07fe92..f2f188105faf 100644 --- a/datafusion/sql/tests/sql_integration.rs +++ b/datafusion/sql/tests/sql_integration.rs @@ -2704,7 +2704,8 @@ fn logical_plan_with_dialect_and_options( "date_trunc", vec![DataType::Utf8, DataType::Timestamp(Nanosecond, None)], DataType::Int32, - )); + )) + .with_udf(make_udf("sqrt", vec![DataType::Int64], DataType::Int64)); let planner = SqlToRel::new_with_options(&context, options); let result = DFParser::parse_sql_with_dialect(sql, dialect); let mut ast = result?;