Skip to content
Snippets Groups Projects
Commit bff021df authored by Yuming Wang's avatar Yuming Wang Committed by Xiao Li
Browse files

[SPARK-20751][SQL] Add built-in SQL Function - COT

## What changes were proposed in this pull request?

Add built-in SQL Function - COT.

## How was this patch tested?

unit tests

Author: Yuming Wang <wgyumg@gmail.com>

Closes #17999 from wangyum/SPARK-20751.
parent dba2ca2c
No related branches found
No related tags found
No related merge requests found
......@@ -234,6 +234,7 @@ object FunctionRegistry {
expression[StringToMap]("str_to_map"),
expression[Sqrt]("sqrt"),
expression[Tan]("tan"),
expression[Cot]("cot"),
expression[Tanh]("tanh"),
expression[Add]("+"),
......
......@@ -543,6 +543,20 @@ 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 = {
defineCodeGen(ctx, ev, c => s"${ev.value} = 1 / java.lang.Math.tan($c);")
}
}
@ExpressionDescription(
usage = "_FUNC_(expr) - Returns the hyperbolic tangent of `expr`.",
extended = """
......
......@@ -53,3 +53,9 @@ explain select 2 * 4 + 3 || 'b';
explain select 3 + 1 || 'a' || 4 / 2;
explain select 1 == 1 OR 'a' || 'b' == 'ab';
explain select 'a' || 'c' == 'ac' AND 2 == 3;
-- math functions
select cot(1);
select cot(null);
select cot(0);
select cot(-1);
-- Automatically generated by SQLQueryTestSuite
-- Number of queries: 34
-- Number of queries: 38
-- !query 0
......@@ -284,3 +284,35 @@ struct<plan:string>
== Physical Plan ==
*Project [false AS ((concat(a, c) = ac) AND (2 = 3))#x]
+- Scan OneRowRelation[]
-- !query 34
select cot(1)
-- !query 34 schema
struct<COT(CAST(1 AS DOUBLE)):double>
-- !query 34 output
0.6420926159343306
-- !query 35
select cot(null)
-- !query 35 schema
struct<COT(CAST(NULL AS DOUBLE)):double>
-- !query 35 output
NULL
-- !query 36
select cot(0)
-- !query 36 schema
struct<COT(CAST(0 AS DOUBLE)):double>
-- !query 36 output
Infinity
-- !query 37
select cot(-1)
-- !query 37 schema
struct<COT(CAST(-1 AS DOUBLE)):double>
-- !query 37 output
-0.6420926159343306
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment