Skip to content
Closed
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
50 changes: 49 additions & 1 deletion sql/core/src/main/scala/org/apache/spark/sql/functions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably have @since annotation here and for the remaining ones.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't sure whether this is something I should put in during the pull-request, or whether it gets added at a later stage.

Shall I presume that this is destined for Spark-3.1, or maybe 3.0.2?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be 3.1, as new functions are not added in maintenance releases.

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`
*
Expand All @@ -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
Expand Down Expand Up @@ -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".
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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(
Expand Down