dongjoon-hyun commented on a change in pull request #25041: [SPARK-28133][SQL]
Add acosh/asinh/atanh functions to SQL
URL: https://github.com/apache/spark/pull/25041#discussion_r302839725
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/mathExpressions.scala
##########
@@ -557,6 +581,32 @@ case class Sin(child: Expression) extends
UnaryMathExpression(math.sin, "SIN")
""")
case class Sinh(child: Expression) extends UnaryMathExpression(math.sinh,
"SINH")
+@ExpressionDescription(
+ usage = """
+ _FUNC_(expr) - Returns inverse hyperbolic sine of `expr`.
+ """,
+ arguments = """
+ Arguments:
+ * expr - hyperbolic angle
+ """,
+ examples = """
+ Examples:
+ > SELECT _FUNC_(0);
+ 0.0
+ """,
+ since = "3.0.0")
+case class Asinh(child: Expression)
+ extends UnaryMathExpression((x: Double) => x match {
+ case Double.NegativeInfinity => Double.NegativeInfinity
+ case _ => math.log(x + math.sqrt(x * x + 1.0)) }, "ASINH") {
+ override def doGenCode(ctx: CodegenContext, ev: ExprCode): ExprCode = {
+ defineCodeGen(ctx, ev, c =>
+ s"""${ev.value} = \"$c\" == \"Double.NEGATIVE_INFINITY\" ? """ +
Review comment:
@Tonix517 . This will fail like the following.
```
spark-sql> CREATE TABLE i AS SELECT double('-Infinity') a;
spark-sql> SELECT asinh(a) FROM i;
NaN
```
`codegen` part is difficult for new developers. You need to check the
generated java code by your PR manually. For example, the following is the
generated code by this PR.
```
/* 035 */ project_value_0 = project_value_0 = "inputadapter_value_0"
== "Double.NEGATIVE_INFINITY" ?
java.lang.Double.NEGATIVE_INFINITY :
java.lang.Math.log(inputadapter_value_0 +
java.lang.Math.sqrt(inputadapter_value_0 * inputadapter_value_0 + 1.0));;
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]