Uh oh!
There was an error while loading. Please reload this page.
[SPARK-28133][SQL] Add acosh/asinh/atanh functions to SQL - #25041
[SPARK-28133][SQL] Add acosh/asinh/atanh functions to SQL#25041Tonix517 wants to merge 15 commits into
Conversation
HyukjinKwon
commented
Jul 3, 2019
ok to test |
dongjoon-hyun
commented
Jul 3, 2019
cc @gatorsmile |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
dongjoon-hyun
commented
Jul 3, 2019
Welcome, @Tonix517 . Thank you for your first contribution. |
acosh/asinh/atanh functionsacosh/asinh/atanh functionsSparkQA
commented
Jul 3, 2019
Test build #107156 has finished for PR 25041 at commit
|
SparkQA
commented
Jul 3, 2019
Test build #107152 has finished for PR 25041 at commit
|
SparkQA
commented
Jul 3, 2019
Test build #107159 has finished for PR 25041 at commit
|
Tonix517
commented
Jul 3, 2019
Anyway to rerun the test? It failed with a SIGKILL as below:
|
mgaido91
commented
Jul 3, 2019
retest this please |
SparkQA
commented
Jul 3, 2019
Test build #107188 has finished for PR 25041 at commit
|
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Tonix517
commented
Jul 3, 2019
retest this please |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
SparkQA
commented
Jul 12, 2019
Test build #107607 has finished for PR 25041 at commit
|
Uh oh!
There was an error while loading. Please reload this page.
SparkQA
commented
Jul 13, 2019
Test build #107617 has finished for PR 25041 at commit
|
SparkQA
commented
Jul 13, 2019
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 |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Tonix517
commented
Jul 14, 2019
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. |
dongjoon-hyun
commented
Jul 14, 2019
I'm doing the final review. If there is no issue, I can merge this tonight, @Tonix517 . |
SparkQA
commented
Jul 14, 2019
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.
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.
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.
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.
dongjoon-hyun
commented
Jul 14, 2019
@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. |
dongjoon-hyun
commented
Jul 14, 2019
For the second case,
I tested some, but like line 37, it's declared already |
dongjoon-hyun
commented
Jul 14, 2019
@mgaido91 . Do you have a counter-example? For me, this function avoids both two corner cases. |
mgaido91
commented
Jul 14, 2019
@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 |
dongjoon-hyun
commented
Jul 15, 2019
Thank you, @mgaido91 . Yes, I tried in several use cases including |
Tonix517
commented
Jul 15, 2019
@dongjoon-hyun@mgaido91 Thank you very much for all your guidance and patience. Learned a lot :) |
HyukjinKwon
commented
Jul 15, 2019
+1 looks fine to me too. |
mgaido91
commented
Jul 15, 2019
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" ``` Closesapache#25041 from Tonix517/SPARK-28133. Authored-by: Tony Zhang <tony.zhang@uber.com> Signed-off-by: Dongjoon Hyun <dhyun@apple.com>
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?