diff --git a/sql/core/src/main/scala/org/apache/spark/sql/functions.scala b/sql/core/src/main/scala/org/apache/spark/sql/functions.scala index 2c545fe762b6..e0082476297d 100644 --- a/sql/core/src/main/scala/org/apache/spark/sql/functions.scala +++ b/sql/core/src/main/scala/org/apache/spark/sql/functions.scala @@ -1427,6 +1427,22 @@ object functions { */ def acos(columnName: String): Column = acos(Column(columnName)) + /** + * @return inverse hyperbolic cosine of `e` + * + * @group math_funcs + * @since 3.1.0 + */ + def acosh(e: Column): Column = withExpr { Acosh(e.expr) } + + /** + * @return inverse hyperbolic cosine of `columnName` + * + * @group math_funcs + * @since 3.1.0 + */ + def acosh(columnName: String): Column = acosh(Column(columnName)) + /** * @return inverse sine of `e` in radians, as if computed by `java.lang.Math.asin` * @@ -1444,7 +1460,23 @@ object functions { def asin(columnName: String): Column = asin(Column(columnName)) /** - * @return inverse tangent of `e`, as if computed by `java.lang.Math.atan` + * @return inverse hyperbolic sine of `e` + * + * @group math_funcs + * @since 3.1.0 + */ + def asinh(e: Column): Column = withExpr { Asinh(e.expr) } + + /** + * @return inverse hyperbolic sine of `columnName` + * + * @group math_funcs + * @since 3.1.0 + */ + def asinh(columnName: String): Column = asinh(Column(columnName)) + + /** + * @return inverse tangent of `e` as if computed by `java.lang.Math.atan` * * @group math_funcs * @since 1.4.0 @@ -1572,6 +1604,22 @@ object functions { */ def atan2(yValue: Double, xName: String): Column = atan2(yValue, Column(xName)) + /** + * @return inverse hyperbolic tangent of `e` + * + * @group math_funcs + * @since 3.1.0 + */ + def atanh(e: Column): Column = withExpr { Atanh(e.expr) } + + /** + * @return inverse hyperbolic tangent of `columnName` + * + * @group math_funcs + * @since 3.1.0 + */ + def atanh(columnName: String): Column = atanh(Column(columnName)) + /** * An expression that returns the string representation of the binary value of the given long * column. For example, bin("12") returns "1100". diff --git a/sql/core/src/test/scala/org/apache/spark/sql/MathFunctionsSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/MathFunctionsSuite.scala index bd86c2ec075b..cd9297657123 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/MathFunctionsSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/MathFunctionsSuite.scala @@ -125,6 +125,11 @@ class MathFunctionsSuite extends QueryTest with SharedSparkSession { testOneToOneMathFunction(sinh, math.sinh) } + test("asinh") { + testOneToOneMathFunction(asinh, + (x: Double) => math.log(x + math.sqrt(x * x + 1)) ) + } + test("cos") { testOneToOneMathFunction(cos, math.cos) } @@ -137,6 +142,11 @@ class MathFunctionsSuite extends QueryTest with SharedSparkSession { testOneToOneMathFunction(cosh, math.cosh) } + test("acosh") { + testOneToOneMathFunction(acosh, + (x: Double) => math.log(x + math.sqrt(x * x - 1)) ) + } + test("tan") { testOneToOneMathFunction(tan, math.tan) } @@ -149,6 +159,11 @@ class MathFunctionsSuite extends QueryTest with SharedSparkSession { testOneToOneMathFunction(tanh, math.tanh) } + test("atanh") { + testOneToOneMathFunction(atanh, + (x: Double) => (0.5 * (math.log1p(x) - math.log1p(-x))) ) + } + test("degrees") { testOneToOneMathFunction(degrees, math.toDegrees) checkAnswer(