Skip to content

Conversation

@wangyum
Copy link
Member

@wangyum wangyum commented May 16, 2017

What changes were proposed in this pull request?

Add built-in SQL Function - COT.

How was this patch tested?

unit tests

@SparkQA
Copy link

SparkQA commented May 16, 2017

Test build #76959 has finished for PR 17999 at commit d30484c.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds the following public classes (experimental):
  • case class Cot(child: Expression)

""")
case class Cot(child: Expression)
extends UnaryMathExpression((x: Double) => 1 / math.tan(x), "COT") {
override def doGenCode(ctx: CodegenContext, ev: ExprCode): ExprCode = {
Copy link
Member

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) {
Copy link
Member

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.

@gatorsmile
Copy link
Member

Thanks for working on it. You need to add it to FunctionRegistry and add the SQL-related test cases to operators.sql. Also covers all the edge cases. For example, 0 that should trigger infinity, null, and so on.

* @since 2.2.0
*/
def cot(colName: String): Column = cot(Column(colName))

Copy link
Member

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

Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: 2.3.0?

@SparkQA
Copy link

SparkQA commented May 17, 2017

Test build #77025 has finished for PR 17999 at commit 3782512.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@maropu
Copy link
Member

maropu commented May 17, 2017

As @gatorsmile said, you need to add tests in operators.sql (https://github.com/apache/spark/blob/master/sql/core/src/test/resources/sql-tests/inputs/operators.sql). See SQLQueryTestSuite for these test cases.

@SparkQA
Copy link

SparkQA commented May 18, 2017

Test build #77041 has started for PR 17999 at commit c80c184.

* @since 2.3.0
*/
def cot(colName: String): Column = cot(Column(colName))

Copy link
Member

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)

@SparkQA
Copy link

SparkQA commented May 18, 2017

Test build #77057 has started for PR 17999 at commit 3bd1e1e.

*
* @group math_funcs
* @since 2.3.0
*/
Copy link
Member

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})"),
Copy link
Member

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);
Copy link
Member

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);
"""
Copy link
Member

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);")

@gatorsmile
Copy link
Member

Thanks for working on it!

LGTM except a few minor comments.

@SparkQA
Copy link

SparkQA commented May 19, 2017

Test build #77067 has finished for PR 17999 at commit ea10dee.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@gatorsmile
Copy link
Member

Thanks! Merging to master.

@asfgit asfgit closed this in bff021d May 19, 2017
@rxin
Copy link
Contributor

rxin commented May 19, 2017

hmnmm

seems like we should be following how we test tan, cos, etc in MathExpressionsSuite?

ghost pushed a commit to dbtsai/spark that referenced this pull request May 22, 2017
## 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.
lycplus pushed a commit to lycplus/spark that referenced this pull request May 24, 2017
## 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.
lycplus pushed a commit to lycplus/spark that referenced this pull request May 24, 2017
## 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.
@wangyum wangyum deleted the SPARK-20751 branch October 8, 2019 04:24
sarutak pushed a commit that referenced this pull request Sep 20, 2021
### 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]>
a0x8o added a commit to a0x8o/spark that referenced this pull request Sep 20, 2021
### 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants