-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-28133][SQL] Add acosh/asinh/atanh functions to SQL #25041
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
Conversation
|
ok to test |
|
cc @gatorsmile |
|
Welcome, @Tonix517 . Thank you for your first contribution. |
acosh/asinh/atanh functions
acosh/asinh/atanh functions|
Test build #107156 has finished for PR 25041 at commit
|
|
Test build #107152 has finished for PR 25041 at commit
|
|
Test build #107159 has finished for PR 25041 at commit
|
|
Anyway to rerun the test? It failed with a SIGKILL as below:
|
|
retest this please |
|
Test build #107188 has finished for PR 25041 at commit
|
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/FunctionRegistry.scala
Outdated
Show resolved
Hide resolved
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/FunctionRegistry.scala
Outdated
Show resolved
Hide resolved
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/FunctionRegistry.scala
Outdated
Show resolved
Hide resolved
|
retest this please |
...catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/MathExpressionsSuite.scala
Outdated
Show resolved
Hide resolved
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/mathExpressions.scala
Outdated
Show resolved
Hide resolved
...catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/MathExpressionsSuite.scala
Show resolved
Hide resolved
|
Test build #107607 has finished for PR 25041 at commit
|
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/mathExpressions.scala
Outdated
Show resolved
Hide resolved
|
Test build #107617 has finished for PR 25041 at commit
|
|
Test build #107618 has finished for PR 25041 at commit
|
|
@Tonix517 . I'm still hitting the following weird codegen result. I really meant it to see the generate code by your eyes. |
|
As @mgaido91 's suggestion, you had better rewrite with |
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/mathExpressions.scala
Outdated
Show resolved
Hide resolved
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/mathExpressions.scala
Outdated
Show resolved
Hide resolved
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/mathExpressions.scala
Outdated
Show resolved
Hide resolved
|
Thanks @dongjoon-hyun . @mgaido91 's suggestion is correct. With his suggestion, now the generated code will be:
which is in much better shape than previous implementations. and apparently
|
|
@Tonix517 .
Anyway, yes. The newly generate code is right now. Thanks. |
|
I'm doing the final review. If there is no issue, I can merge this tonight, @Tonix517 . |
|
Test build #107635 has finished for PR 25041 at commit
|
| 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 => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as I mentioned earlier, I would prefer rewriting this as an if. There may be stage cases where $c contains a cast or something similar which may cause issues (I has similar problem in another PR, Janino is not perfect with this syntax in the version we're using). So it think it would be safer to rewrite as an if
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also agreed to that. Could you give us the pointer to that PR(or some example)? Actually, I tried to reproduce that kind of issue within the scope of this PR. Until now, I didn't succeed. Maybe, we had better a test case for that to make it sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR was this one: #24636. The bug opened there for janino cannot happen here, but I remember I also had issues in that PR in a case when there was a cast added to the terms.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @mgaido91 !
|
@Tonix517 and @mgaido91 . In the old PR #24636, we also used
It seems that we are not in that case, but let me check that again today. |
|
For the second case,
I tested some, but like line 37, it's declared already |
|
@mgaido91 . Do you have a counter-example? For me, this function avoids both two corner cases. |
|
@dongjoon-hyun , thanks for checking. I agree with you that case 1, which is the bug reported to janino cannot happen here, so it is not an issue here. I am more worried about case 2. Because case 2 depends on what is the input of the function and I think it is hard to predict.
No I don't have honestly. So I'd prefer the |
|
Thank you, @mgaido91 . Yes, I tried in several use cases including |
dongjoon-hyun
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
@dongjoon-hyun @mgaido91 Thank you very much for all your guidance and patience. Learned a lot :) |
|
+1 looks fine to me too. |
|
Thank you @dongjoon-hyun and thank you @Tonix517 for your contribution! |
## What changes were proposed in this pull request? Adding support to hyperbolic functions like asinh\acosh\atanh in spark SQL. Feature parity: https://www.postgresql.org/docs/12/functions-math.html#FUNCTIONS-MATH-HYP-TABLE The followings are the diffence from PostgreSQL. ``` spark-sql> SELECT acosh(0); (PostgreSQL returns `ERROR: input is out of range`) NaN spark-sql> SELECT atanh(2); (PostgreSQL returns `ERROR: input is out of range`) NaN ``` Teradata has similar behavior as PostgreSQL with out of range input float values - It outputs **Invalid Input: numeric value within range only.** These newly added asinh/acosh/atanh handles special input(NaN, +-Infinity) in the same way as existing cos/sin/tan/acos/asin/atan in spark. For which input value range is not (-∞, ∞)): out of range float values: Spark returns NaN and PostgreSQL shows input is out of range NaN: Spark returns NaN, PostgreSQL also returns NaN Infinity: Spark return NaN, PostgreSQL shows input is out of range ## How was this patch tested? ``` spark.sql("select asinh(xx)") spark.sql("select acosh(xx)") spark.sql("select atanh(xx)") ./build/sbt "testOnly org.apache.spark.sql.MathFunctionsSuite" ./build/sbt "testOnly org.apache.spark.sql.catalyst.expressions.MathExpressionsSuite" ``` Closes apache#25041 from Tonix517/SPARK-28133. Authored-by: Tony Zhang <[email protected]> Signed-off-by: Dongjoon Hyun <[email protected]>
What changes were proposed in this pull request?
Adding support to hyperbolic functions like asinh\acosh\atanh in spark SQL.
Feature parity: https://www.postgresql.org/docs/12/functions-math.html#FUNCTIONS-MATH-HYP-TABLE
The followings are the diffence from PostgreSQL.
Teradata has similar behavior as PostgreSQL with out of range input float values - It outputs Invalid Input: numeric value within range only.
These newly added asinh/acosh/atanh handles special input(NaN, +-Infinity) in the same way as existing cos/sin/tan/acos/asin/atan in spark. For which input value range is not (-∞, ∞)):
out of range float values: Spark returns NaN and PostgreSQL shows input is out of range
NaN: Spark returns NaN, PostgreSQL also returns NaN
Infinity: Spark return NaN, PostgreSQL shows input is out of range
How was this patch tested?