Skip to content

Commit bbc7169

Browse files
authored
feat: hyperbolic functions (#5884)
1 parent 444465c commit bbc7169

File tree

13 files changed

+222
-15
lines changed

13 files changed

+222
-15
lines changed

datafusion/core/tests/sql/expr.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,12 @@ async fn test_mathematical_expressions_with_null() -> Result<()> {
683683
test_expression!("asin(NULL)", "NULL");
684684
test_expression!("acos(NULL)", "NULL");
685685
test_expression!("atan(NULL)", "NULL");
686+
test_expression!("sinh(NULL)", "NULL");
687+
test_expression!("cosh(NULL)", "NULL");
688+
test_expression!("tanh(NULL)", "NULL");
689+
test_expression!("asinh(NULL)", "NULL");
690+
test_expression!("acosh(NULL)", "NULL");
691+
test_expression!("atanh(NULL)", "NULL");
686692
test_expression!("floor(NULL)", "NULL");
687693
test_expression!("ceil(NULL)", "NULL");
688694
test_expression!("round(NULL)", "NULL");

datafusion/expr/src/built_in_function.rs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,22 @@ pub enum BuiltinScalarFunction {
3636
Atan,
3737
/// atan2
3838
Atan2,
39+
/// acosh
40+
Acosh,
41+
/// asinh
42+
Asinh,
43+
/// atanh
44+
Atanh,
45+
/// cbrt
46+
Cbrt,
3947
/// ceil
4048
Ceil,
4149
/// coalesce
4250
Coalesce,
4351
/// cos
4452
Cos,
53+
/// cos
54+
Cosh,
4555
/// Digest
4656
Digest,
4757
/// exp
@@ -64,12 +74,14 @@ pub enum BuiltinScalarFunction {
6474
Signum,
6575
/// sin
6676
Sin,
77+
/// sinh
78+
Sinh,
6779
/// sqrt
6880
Sqrt,
69-
/// cbrt
70-
Cbrt,
7181
/// tan
7282
Tan,
83+
/// tanh
84+
Tanh,
7385
/// trunc
7486
Trunc,
7587

@@ -200,9 +212,13 @@ impl BuiltinScalarFunction {
200212
BuiltinScalarFunction::Asin => Volatility::Immutable,
201213
BuiltinScalarFunction::Atan => Volatility::Immutable,
202214
BuiltinScalarFunction::Atan2 => Volatility::Immutable,
215+
BuiltinScalarFunction::Acosh => Volatility::Immutable,
216+
BuiltinScalarFunction::Asinh => Volatility::Immutable,
217+
BuiltinScalarFunction::Atanh => Volatility::Immutable,
203218
BuiltinScalarFunction::Ceil => Volatility::Immutable,
204219
BuiltinScalarFunction::Coalesce => Volatility::Immutable,
205220
BuiltinScalarFunction::Cos => Volatility::Immutable,
221+
BuiltinScalarFunction::Cosh => Volatility::Immutable,
206222
BuiltinScalarFunction::Exp => Volatility::Immutable,
207223
BuiltinScalarFunction::Floor => Volatility::Immutable,
208224
BuiltinScalarFunction::Ln => Volatility::Immutable,
@@ -213,9 +229,11 @@ impl BuiltinScalarFunction {
213229
BuiltinScalarFunction::Round => Volatility::Immutable,
214230
BuiltinScalarFunction::Signum => Volatility::Immutable,
215231
BuiltinScalarFunction::Sin => Volatility::Immutable,
232+
BuiltinScalarFunction::Sinh => Volatility::Immutable,
216233
BuiltinScalarFunction::Sqrt => Volatility::Immutable,
217234
BuiltinScalarFunction::Cbrt => Volatility::Immutable,
218235
BuiltinScalarFunction::Tan => Volatility::Immutable,
236+
BuiltinScalarFunction::Tanh => Volatility::Immutable,
219237
BuiltinScalarFunction::Trunc => Volatility::Immutable,
220238
BuiltinScalarFunction::MakeArray => Volatility::Immutable,
221239
BuiltinScalarFunction::Ascii => Volatility::Immutable,
@@ -293,9 +311,13 @@ impl FromStr for BuiltinScalarFunction {
293311
"acos" => BuiltinScalarFunction::Acos,
294312
"asin" => BuiltinScalarFunction::Asin,
295313
"atan" => BuiltinScalarFunction::Atan,
314+
"acosh" => BuiltinScalarFunction::Acosh,
315+
"asinh" => BuiltinScalarFunction::Asinh,
316+
"atanh" => BuiltinScalarFunction::Atanh,
296317
"atan2" => BuiltinScalarFunction::Atan2,
297318
"ceil" => BuiltinScalarFunction::Ceil,
298319
"cos" => BuiltinScalarFunction::Cos,
320+
"cosh" => BuiltinScalarFunction::Cosh,
299321
"exp" => BuiltinScalarFunction::Exp,
300322
"floor" => BuiltinScalarFunction::Floor,
301323
"ln" => BuiltinScalarFunction::Ln,
@@ -306,9 +328,11 @@ impl FromStr for BuiltinScalarFunction {
306328
"round" => BuiltinScalarFunction::Round,
307329
"signum" => BuiltinScalarFunction::Signum,
308330
"sin" => BuiltinScalarFunction::Sin,
331+
"sinh" => BuiltinScalarFunction::Sinh,
309332
"sqrt" => BuiltinScalarFunction::Sqrt,
310333
"cbrt" => BuiltinScalarFunction::Cbrt,
311334
"tan" => BuiltinScalarFunction::Tan,
335+
"tanh" => BuiltinScalarFunction::Tanh,
312336
"trunc" => BuiltinScalarFunction::Trunc,
313337

314338
// conditional functions

datafusion/expr/src/expr_fn.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,9 +450,15 @@ scalar_expr!(Cbrt, cbrt, num, "cube root of a number");
450450
scalar_expr!(Sin, sin, num, "sine");
451451
scalar_expr!(Cos, cos, num, "cosine");
452452
scalar_expr!(Tan, tan, num, "tangent");
453+
scalar_expr!(Sinh, sinh, num, "hyperbolic sine");
454+
scalar_expr!(Cosh, cosh, num, "hyperbolic cosine");
455+
scalar_expr!(Tanh, tanh, num, "hyperbolic tangent");
453456
scalar_expr!(Asin, asin, num, "inverse sine");
454457
scalar_expr!(Acos, acos, num, "inverse cosine");
455458
scalar_expr!(Atan, atan, num, "inverse tangent");
459+
scalar_expr!(Asinh, asinh, num, "inverse hyperbolic sine");
460+
scalar_expr!(Acosh, acosh, num, "inverse hyperbolic cosine");
461+
scalar_expr!(Atanh, atanh, num, "inverse hyperbolic tangent");
456462
scalar_expr!(
457463
Floor,
458464
floor,
@@ -763,9 +769,15 @@ mod test {
763769
test_unary_scalar_expr!(Sin, sin);
764770
test_unary_scalar_expr!(Cos, cos);
765771
test_unary_scalar_expr!(Tan, tan);
772+
test_unary_scalar_expr!(Sinh, sinh);
773+
test_unary_scalar_expr!(Cosh, cosh);
774+
test_unary_scalar_expr!(Tanh, tanh);
766775
test_unary_scalar_expr!(Asin, asin);
767776
test_unary_scalar_expr!(Acos, acos);
768777
test_unary_scalar_expr!(Atan, atan);
778+
test_unary_scalar_expr!(Asinh, asinh);
779+
test_unary_scalar_expr!(Acosh, acosh);
780+
test_unary_scalar_expr!(Atanh, atanh);
769781
test_unary_scalar_expr!(Floor, floor);
770782
test_unary_scalar_expr!(Ceil, ceil);
771783
test_nary_scalar_expr!(Round, round, input);

datafusion/expr/src/function.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,12 @@ pub fn return_type(
281281
| BuiltinScalarFunction::Acos
282282
| BuiltinScalarFunction::Asin
283283
| BuiltinScalarFunction::Atan
284+
| BuiltinScalarFunction::Acosh
285+
| BuiltinScalarFunction::Asinh
286+
| BuiltinScalarFunction::Atanh
284287
| BuiltinScalarFunction::Ceil
285288
| BuiltinScalarFunction::Cos
289+
| BuiltinScalarFunction::Cosh
286290
| BuiltinScalarFunction::Exp
287291
| BuiltinScalarFunction::Floor
288292
| BuiltinScalarFunction::Ln
@@ -291,9 +295,11 @@ pub fn return_type(
291295
| BuiltinScalarFunction::Round
292296
| BuiltinScalarFunction::Signum
293297
| BuiltinScalarFunction::Sin
298+
| BuiltinScalarFunction::Sinh
294299
| BuiltinScalarFunction::Sqrt
295300
| BuiltinScalarFunction::Cbrt
296301
| BuiltinScalarFunction::Tan
302+
| BuiltinScalarFunction::Tanh
297303
| BuiltinScalarFunction::Trunc => match input_expr_types[0] {
298304
DataType::Float32 => Ok(DataType::Float32),
299305
_ => Ok(DataType::Float64),

datafusion/physical-expr/src/functions.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,12 @@ pub fn create_physical_fun(
339339
BuiltinScalarFunction::Acos => Arc::new(math_expressions::acos),
340340
BuiltinScalarFunction::Asin => Arc::new(math_expressions::asin),
341341
BuiltinScalarFunction::Atan => Arc::new(math_expressions::atan),
342+
BuiltinScalarFunction::Acosh => Arc::new(math_expressions::acosh),
343+
BuiltinScalarFunction::Asinh => Arc::new(math_expressions::asinh),
344+
BuiltinScalarFunction::Atanh => Arc::new(math_expressions::atanh),
342345
BuiltinScalarFunction::Ceil => Arc::new(math_expressions::ceil),
343346
BuiltinScalarFunction::Cos => Arc::new(math_expressions::cos),
347+
BuiltinScalarFunction::Cosh => Arc::new(math_expressions::cosh),
344348
BuiltinScalarFunction::Exp => Arc::new(math_expressions::exp),
345349
BuiltinScalarFunction::Floor => Arc::new(math_expressions::floor),
346350
BuiltinScalarFunction::Ln => Arc::new(math_expressions::ln),
@@ -352,9 +356,11 @@ pub fn create_physical_fun(
352356
}
353357
BuiltinScalarFunction::Signum => Arc::new(math_expressions::signum),
354358
BuiltinScalarFunction::Sin => Arc::new(math_expressions::sin),
359+
BuiltinScalarFunction::Sinh => Arc::new(math_expressions::sinh),
355360
BuiltinScalarFunction::Sqrt => Arc::new(math_expressions::sqrt),
356361
BuiltinScalarFunction::Cbrt => Arc::new(math_expressions::cbrt),
357362
BuiltinScalarFunction::Tan => Arc::new(math_expressions::tan),
363+
BuiltinScalarFunction::Tanh => Arc::new(math_expressions::tanh),
358364
BuiltinScalarFunction::Trunc => Arc::new(math_expressions::trunc),
359365
BuiltinScalarFunction::Power => {
360366
Arc::new(|args| make_scalar_function(math_expressions::power)(args))

datafusion/physical-expr/src/math_expressions.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,15 @@ math_unary_function!("cbrt", cbrt);
146146
math_unary_function!("sin", sin);
147147
math_unary_function!("cos", cos);
148148
math_unary_function!("tan", tan);
149+
math_unary_function!("sinh", sinh);
150+
math_unary_function!("cosh", cosh);
151+
math_unary_function!("tanh", tanh);
149152
math_unary_function!("asin", asin);
150153
math_unary_function!("acos", acos);
151154
math_unary_function!("atan", atan);
155+
math_unary_function!("asinh", asinh);
156+
math_unary_function!("acosh", acosh);
157+
math_unary_function!("atanh", atanh);
152158
math_unary_function!("floor", floor);
153159
math_unary_function!("ceil", ceil);
154160
math_unary_function!("trunc", trunc);

datafusion/proto/proto/datafusion.proto

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,12 @@ enum ScalarFunction {
524524
CurrentTime = 71;
525525
Uuid = 72;
526526
Cbrt = 73;
527+
Acosh = 74;
528+
Asinh = 75;
529+
Atanh = 76;
530+
Sinh = 77;
531+
Cosh = 78;
532+
Tanh = 79;
527533
}
528534

529535
message ScalarFunctionNode {

datafusion/proto/src/generated/pbjson.rs

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

datafusion/proto/src/generated/prost.rs

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

datafusion/proto/src/logical_plan/from_proto.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,16 @@ use datafusion_common::{
3333
ScalarValue,
3434
};
3535
use datafusion_expr::{
36-
abs, acos, array, ascii, asin, atan, atan2, bit_length, btrim, cbrt, ceil,
37-
character_length, chr, coalesce, concat_expr, concat_ws_expr, cos, date_bin,
38-
date_part, date_trunc, digest, exp,
36+
abs, acos, acosh, array, ascii, asin, asinh, atan, atan2, atanh, bit_length, btrim,
37+
cbrt, ceil, character_length, chr, coalesce, concat_expr, concat_ws_expr, cos, cosh,
38+
date_bin, date_part, date_trunc, digest, exp,
3939
expr::{self, Sort, WindowFunction},
4040
floor, from_unixtime, left, ln, log, log10, log2,
4141
logical_plan::{PlanType, StringifiedPlan},
4242
lower, lpad, ltrim, md5, now, nullif, octet_length, power, random, regexp_match,
4343
regexp_replace, repeat, replace, reverse, right, round, rpad, rtrim, sha224, sha256,
44-
sha384, sha512, signum, sin, split_part, sqrt, starts_with, strpos, substr,
45-
substring, tan, to_hex, to_timestamp_micros, to_timestamp_millis,
44+
sha384, sha512, signum, sin, sinh, split_part, sqrt, starts_with, strpos, substr,
45+
substring, tan, tanh, to_hex, to_timestamp_micros, to_timestamp_millis,
4646
to_timestamp_seconds, translate, trim, trunc, upper, uuid,
4747
window_frame::regularize,
4848
AggregateFunction, Between, BinaryExpr, BuiltInWindowFunction, BuiltinScalarFunction,
@@ -407,6 +407,12 @@ impl From<&protobuf::ScalarFunction> for BuiltinScalarFunction {
407407
ScalarFunction::Asin => Self::Asin,
408408
ScalarFunction::Acos => Self::Acos,
409409
ScalarFunction::Atan => Self::Atan,
410+
ScalarFunction::Sinh => Self::Sinh,
411+
ScalarFunction::Cosh => Self::Cosh,
412+
ScalarFunction::Tanh => Self::Tanh,
413+
ScalarFunction::Asinh => Self::Asinh,
414+
ScalarFunction::Acosh => Self::Acosh,
415+
ScalarFunction::Atanh => Self::Atanh,
410416
ScalarFunction::Exp => Self::Exp,
411417
ScalarFunction::Log => Self::Log,
412418
ScalarFunction::Ln => Self::Ln,
@@ -1123,6 +1129,8 @@ pub fn parse_expr(
11231129
match scalar_function {
11241130
ScalarFunction::Asin => Ok(asin(parse_expr(&args[0], registry)?)),
11251131
ScalarFunction::Acos => Ok(acos(parse_expr(&args[0], registry)?)),
1132+
ScalarFunction::Asinh => Ok(asinh(parse_expr(&args[0], registry)?)),
1133+
ScalarFunction::Acosh => Ok(acosh(parse_expr(&args[0], registry)?)),
11261134
ScalarFunction::Array => Ok(array(
11271135
args.to_owned()
11281136
.iter()
@@ -1135,6 +1143,10 @@ pub fn parse_expr(
11351143
ScalarFunction::Cos => Ok(cos(parse_expr(&args[0], registry)?)),
11361144
ScalarFunction::Tan => Ok(tan(parse_expr(&args[0], registry)?)),
11371145
ScalarFunction::Atan => Ok(atan(parse_expr(&args[0], registry)?)),
1146+
ScalarFunction::Sinh => Ok(sinh(parse_expr(&args[0], registry)?)),
1147+
ScalarFunction::Cosh => Ok(cosh(parse_expr(&args[0], registry)?)),
1148+
ScalarFunction::Tanh => Ok(tanh(parse_expr(&args[0], registry)?)),
1149+
ScalarFunction::Atanh => Ok(atanh(parse_expr(&args[0], registry)?)),
11381150
ScalarFunction::Exp => Ok(exp(parse_expr(&args[0], registry)?)),
11391151
ScalarFunction::Log2 => Ok(log2(parse_expr(&args[0], registry)?)),
11401152
ScalarFunction::Ln => Ok(ln(parse_expr(&args[0], registry)?)),

0 commit comments

Comments
 (0)