Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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]("+"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = """
Expand Down
6 changes: 6 additions & 0 deletions sql/core/src/test/resources/sql-tests/inputs/operators.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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);
34 changes: 33 additions & 1 deletion sql/core/src/test/resources/sql-tests/results/operators.sql.out
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- Automatically generated by SQLQueryTestSuite
-- Number of queries: 34
-- Number of queries: 38


-- !query 0
Expand Down Expand Up @@ -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