Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move cbrt, cos, cosh, degrees to datafusion-functions #9938

Merged
merged 1 commit into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 1 addition & 27 deletions datafusion/expr/src/built_in_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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 => {
Expand All @@ -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
) {
Expand All @@ -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"],
Expand Down
8 changes: 0 additions & 8 deletions datafusion/expr/src/expr_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions datafusion/expr/src/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion datafusion/functions/src/math/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
(
Expand Down Expand Up @@ -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")
);
4 changes: 0 additions & 4 deletions datafusion/physical-expr/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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))
}
Expand Down
4 changes: 0 additions & 4 deletions datafusion/physical-expr/src/math_expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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<ArrayRef> {
Expand Down
10 changes: 5 additions & 5 deletions datafusion/proto/proto/datafusion.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
12 changes: 0 additions & 12 deletions datafusion/proto/src/generated/pbjson.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 5 additions & 13 deletions datafusion/proto/src/generated/prost.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 1 addition & 12 deletions datafusion/proto/src/logical_plan/from_proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)?))
}
Expand Down
Loading
Loading