-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-20751][SQL] Add built-in SQL Function - COT #17999
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
|
Test build #76959 has finished for PR 17999 at commit
|
| """) | ||
| case class Cot(child: Expression) | ||
| extends UnaryMathExpression((x: Double) => 1 / math.tan(x), "COT") { | ||
| override def doGenCode(ctx: CodegenContext, ev: ExprCode): ExprCode = { |
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.
Please use defineCodeGen
| override def doGenCode(ctx: CodegenContext, ev: ExprCode): ExprCode = { | ||
| nullSafeCodeGen(ctx, ev, c => | ||
| s""" | ||
| if (${ev.value} == null) { |
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.
Internally, it is already nullSafeCodeGen, and thus, this is not needed.
|
Thanks for working on it. You need to add it to |
| * @since 2.2.0 | ||
| */ | ||
| def cot(colName: String): Column = cot(Column(colName)) | ||
|
|
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'm not sure though, do we strictly need to add this function in this file? If we add this in FunctionRegistry, you know we can use this thru selectExpr. ISTM this file seems to include frequently-used functions only. cc: @gatorsmile
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.
Sure. Let us keep this file untouched in this PR.
| /** | ||
| * Computes the cotangent of the given column. | ||
| * | ||
| * @group math_funcs |
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.
nit: 2.3.0?
|
Test build #77025 has finished for PR 17999 at commit
|
|
As @gatorsmile said, you need to add tests in |
|
Test build #77041 has started for PR 17999 at commit |
| * @since 2.3.0 | ||
| */ | ||
| def cot(colName: String): Column = cot(Column(colName)) | ||
|
|
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.
We do not add these functions here in this pr. See: #17999 (diff)
|
Test build #77057 has started for PR 17999 at commit |
| * | ||
| * @group math_funcs | ||
| * @since 2.3.0 | ||
| */ |
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.
Let us remove this too. Thanks!
| test("cot") { | ||
| testOneToOneMathFunction(cot, (d: Double) => 1 / math.tan(d)) | ||
| checkAnswer( | ||
| sql(s"SELECT cot(null), cot(0), cot(-1), cot(${Double.MaxValue})"), |
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.
Could you move these tests to operators.sql?
| select 2 * 5; | ||
| select 5 % 3; | ||
| select pmod(-7, 3); | ||
| select cot(1); |
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.
Could you move this to the end of this .sql file? It can reduce the line of code changes.
| defineCodeGen(ctx, ev, c => | ||
| s""" | ||
| ${ev.value} = 1 / java.lang.Math.tan($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.
Since it fits one line, could you change it to?
defineCodeGen(ctx, ev, c => s"${ev.value} = 1 / java.lang.Math.tan($c);")|
Thanks for working on it! LGTM except a few minor comments. |
|
Test build #77067 has finished for PR 17999 at commit
|
|
Thanks! Merging to master. |
|
hmnmm seems like we should be following how we test tan, cos, etc in MathExpressionsSuite? |
## What changes were proposed in this pull request? Add cot test in MathExpressionsSuite as apache#17999 (comment). ## How was this patch tested? unit tests Author: Yuming Wang <[email protected]> Closes apache#18039 from wangyum/SPARK-20751-test.
## What changes were proposed in this pull request? Add built-in SQL Function - COT. ## How was this patch tested? unit tests Author: Yuming Wang <[email protected]> Closes apache#17999 from wangyum/SPARK-20751.
## What changes were proposed in this pull request? Add cot test in MathExpressionsSuite as apache#17999 (comment). ## How was this patch tested? unit tests Author: Yuming Wang <[email protected]> Closes apache#18039 from wangyum/SPARK-20751-test.
### What changes were proposed in this pull request? Add new built-in SQL functions: secant and cosecant, and add them as Scala and Python functions. ### Why are the changes needed? Cotangent has been supported in Spark SQL but Secant and Cosecant are missing though I believe they can be used as much as cot. Related Links: [SPARK-20751](#17999) [SPARK-36660](#33906) ### Does this PR introduce _any_ user-facing change? Yes, users can now use these functions. ### How was this patch tested? Unit tests Closes #33988 from yutoacts/SPARK-36683. Authored-by: Yuto Akutsu <[email protected]> Signed-off-by: Kousuke Saruta <[email protected]>
### What changes were proposed in this pull request? Add new built-in SQL functions: secant and cosecant, and add them as Scala and Python functions. ### Why are the changes needed? Cotangent has been supported in Spark SQL but Secant and Cosecant are missing though I believe they can be used as much as cot. Related Links: [SPARK-20751](apache/spark#17999) [SPARK-36660](apache/spark#33906) ### Does this PR introduce _any_ user-facing change? Yes, users can now use these functions. ### How was this patch tested? Unit tests Closes #33988 from yutoacts/SPARK-36683. Authored-by: Yuto Akutsu <[email protected]> Signed-off-by: Kousuke Saruta <[email protected]>
What changes were proposed in this pull request?
Add built-in SQL Function - COT.
How was this patch tested?
unit tests