-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -543,6 +543,28 @@ case class Sqrt(child: Expression) extends UnaryMathExpression(math.sqrt, "SQRT" | |
| """) | ||
| case class Tan(child: Expression) extends UnaryMathExpression(math.tan, "TAN") | ||
|
|
||
| @ExpressionDescription( | ||
| usage = "_FUNC_(expr) - Returns the cotangent of `expr`.", | ||
| extended = """ | ||
| Examples: | ||
| > SELECT _FUNC_(1); | ||
| 0.6420926159343306 | ||
| """) | ||
| case class Cot(child: Expression) | ||
| extends UnaryMathExpression((x: Double) => 1 / math.tan(x), "COT") { | ||
| override def doGenCode(ctx: CodegenContext, ev: ExprCode): ExprCode = { | ||
| nullSafeCodeGen(ctx, ev, c => | ||
| s""" | ||
| if (${ev.value} == null) { | ||
| ${ev.isNull} = true; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Internally, it is already |
||
| } else { | ||
| ${ev.value} = 1 / java.lang.Math.tan($c); | ||
| } | ||
| """ | ||
| ) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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);") |
||
| } | ||
| } | ||
|
|
||
| @ExpressionDescription( | ||
| usage = "_FUNC_(expr) - Returns the hyperbolic tangent of `expr`.", | ||
| extended = """ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1990,6 +1990,22 @@ object functions { | |
| */ | ||
| def tan(columnName: String): Column = tan(Column(columnName)) | ||
|
|
||
| /** | ||
| * Computes the cotangent of the given column. | ||
| * | ||
| * @group math_funcs | ||
| * @since 2.2.0 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: |
||
| */ | ||
| def cot(e: Column): Column = withExpr { Cot(e.expr) } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let us remove this too. Thanks! |
||
|
|
||
| /** | ||
| * Computes the cotangent of the given column name. | ||
| * | ||
| * @group math_funcs | ||
| * @since 2.2.0 | ||
| */ | ||
| def cot(colName: String): Column = cot(Column(colName)) | ||
|
|
||
| /** | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure. Let us keep this file untouched in this PR.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) |
||
| * Computes the hyperbolic tangent of the given value. | ||
| * | ||
|
|
||
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