Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
[SPARK-23329][SQL] Fix documentation of trigonometric functions
  • Loading branch information
misutoth committed Feb 16, 2018
commit 0a0c4aede61a89465b474d292baf9aef773f7a80
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ case class Pi() extends LeafMathExpression(math.Pi, "PI")

// scalastyle:off line.size.limit
@ExpressionDescription(
usage = "_FUNC_(expr) - Returns the inverse cosine (a.k.a. arccosine) of `expr` if -1<=`expr`<=1 or NaN otherwise.",
usage = "_FUNC_(expr) - Returns the inverse cosine (a.k.a. arc cosine) of `expr`, as if computed by `java.lang.Math._FUNC_`.",
examples = """
Examples:
> SELECT _FUNC_(1);
Expand All @@ -183,7 +183,7 @@ case class Acos(child: Expression) extends UnaryMathExpression(math.acos, "ACOS"

// scalastyle:off line.size.limit
@ExpressionDescription(
usage = "_FUNC_(expr) - Returns the inverse sine (a.k.a. arcsine) the arc sin of `expr` if -1<=`expr`<=1 or NaN otherwise.",
usage = "_FUNC_(expr) - Returns the inverse sine (a.k.a. arc sine) the arc sin of `expr`, as if computed by `java.lang.Math._FUNC_`.",
examples = """
Examples:
> SELECT _FUNC_(0);
Expand All @@ -196,7 +196,7 @@ case class Asin(child: Expression) extends UnaryMathExpression(math.asin, "ASIN"

// scalastyle:off line.size.limit
@ExpressionDescription(
usage = "_FUNC_(expr) - Returns the inverse tangent (a.k.a. arctangent).",
usage = "_FUNC_(expr) - Returns the inverse tangent (a.k.a. arc tangent) of `expr`, as if computed by `java.lang.Math._FUNC_`.",
examples = """
Examples:
> SELECT _FUNC_(0);
Expand Down Expand Up @@ -252,7 +252,12 @@ case class Ceil(child: Expression) extends UnaryMathExpression(math.ceil, "CEIL"
}

@ExpressionDescription(
usage = "_FUNC_(expr) - Returns the cosine of `expr`.",
usage = "_FUNC_(expr) - Returns the cosine of `expr`, as if computed by `java.lang.Math._FUNC_`.",
arguments =
"""
Arguments:
* expr - angle in radians
""",
Copy link
Member

Choose a reason for hiding this comment

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

Let's remote two spaces ->

      * expr - angle in radians
  """,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, indeed that is used elsewhere

examples = """
Examples:
> SELECT _FUNC_(0);
Expand All @@ -262,6 +267,11 @@ case class Cos(child: Expression) extends UnaryMathExpression(math.cos, "COS")

@ExpressionDescription(
usage = "_FUNC_(expr) - Returns the hyperbolic cosine of `expr`.",
Copy link
Member

Choose a reason for hiding this comment

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

Shall we add java.lang.Math. _FUNC_ here too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, we should

arguments =
"""
Copy link
Member

Choose a reason for hiding this comment

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

I mean ...

arguments = """
  Arguments:
    * expr - hyperbolic angle.
""",

to be consistent other styles here. For example:

arguments = """
Arguments:
* str - a string expression
* regexp - a string expression. The pattern string should be a Java regular expression.
Since Spark 2.0, string literals (including regex patterns) are unescaped in our SQL
parser. For example, to match "\abc", a regular expression for `regexp` can be
"^\\abc$".
There is a SQL config 'spark.sql.parser.escapedStringLiterals' that can be used to
fallback to the Spark 1.6 behavior regarding string literal parsing. For example,
if the config is enabled, the `regexp` that can match "\abc" is "^\abc$".
""",

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right, I will fix this.

Arguments:
* expr - hyperbolic angle.
Copy link
Member

Choose a reason for hiding this comment

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

not a big deal but let's remove the trailing . for consistency.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

""",
examples = """
Examples:
> SELECT _FUNC_(0);
Expand Down Expand Up @@ -512,16 +522,27 @@ case class Rint(child: Expression) extends UnaryMathExpression(math.rint, "ROUND
case class Signum(child: Expression) extends UnaryMathExpression(math.signum, "SIGNUM")

@ExpressionDescription(
usage = "_FUNC_(expr) - Returns the sine of `expr`.",
usage = "_FUNC_(expr) - Returns the sine of `expr`, as if computed by `java.lang.Math._FUNC_`.",
Copy link
Member

Choose a reason for hiding this comment

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

I don't know the history of why the text is different here vs python/R https://github.com/apache/spark/blob/master/R/pkg/R/functions.R#L1466

I don't think the doc grouping in R is relevant - the text is there. Generally we try to match the text in scala but I don't feel strongly either way in this case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As far as the trigonometric functions concerned they should be now in sync I think.

arguments =
"""
Copy link
Member

Choose a reason for hiding this comment

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

Can we have the same format for it and the same instances - #20618 (comment)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I applied to all places in scope.

Arguments:
* expr - angle in radians
""",
examples = """
Examples:
> SELECT _FUNC_(0);
0.0
""")
case class Sin(child: Expression) extends UnaryMathExpression(math.sin, "SIN")

// scalastyle:off line.size.limit
Copy link
Member

Choose a reason for hiding this comment

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

I think we should turn this on again

@ExpressionDescription(
usage = "_FUNC_(expr) - Returns the hyperbolic sine of `expr`.",
usage = "_FUNC_(expr) - Returns hyperbolic sine of `expr`, as if computed by `java.lang.Math._FUNC_`.",
arguments =
"""
Arguments:
* expr - hyperbolic angle
""",
examples = """
Examples:
> SELECT _FUNC_(0);
Expand All @@ -538,8 +559,14 @@ case class Sinh(child: Expression) extends UnaryMathExpression(math.sinh, "SINH"
""")
case class Sqrt(child: Expression) extends UnaryMathExpression(math.sqrt, "SQRT")

// scalastyle:off line.size.limit
Copy link
Member

Choose a reason for hiding this comment

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

Ditto for turning it on

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Turned it on for all trigonometric functions.

@ExpressionDescription(
usage = "_FUNC_(expr) - Returns the tangent of `expr`.",
usage = "_FUNC_(expr) - Returns the tangent of `expr`, as if computed by `java.lang.Math._FUNC_`.",
arguments =
"""
Arguments:
* expr - angle in radians
""",
examples = """
Examples:
> SELECT _FUNC_(0);
Expand All @@ -548,7 +575,13 @@ 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`.",
usage = "_FUNC_(expr) - Returns the cotangent of `expr` ," +
Copy link
Member

Choose a reason for hiding this comment

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

Ditto for formatting

"as if computed by `1/java.lang.Math._FUNC_`.",
arguments =
"""
Arguments:
* expr - angle in radians
""",
examples = """
Examples:
> SELECT _FUNC_(1);
Expand All @@ -562,7 +595,12 @@ case class Cot(child: Expression)
}

@ExpressionDescription(
usage = "_FUNC_(expr) - Returns the hyperbolic tangent of `expr`.",
usage = "_FUNC_(expr) - Returns the hyperbolic tangent of `expr`, as if computed by `java.lang.Math._FUNC_`.",
Copy link
Member

Choose a reason for hiding this comment

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

Seems line limit is reached here.

arguments =
"""
Arguments:
* expr - hyperbolic angle
""",
examples = """
Examples:
> SELECT _FUNC_(0);
Expand All @@ -572,6 +610,11 @@ case class Tanh(child: Expression) extends UnaryMathExpression(math.tanh, "TANH"

@ExpressionDescription(
usage = "_FUNC_(expr) - Converts radians to degrees.",
arguments =
"""
Arguments:
* expr - angle in radians
""",
examples = """
Examples:
> SELECT _FUNC_(3.141592653589793);
Expand All @@ -583,6 +626,11 @@ case class ToDegrees(child: Expression) extends UnaryMathExpression(math.toDegre

@ExpressionDescription(
usage = "_FUNC_(expr) - Converts degrees to radians.",
arguments =
"""
Arguments:
* expr - angle in degrees
""",
examples = """
Examples:
> SELECT _FUNC_(180);
Expand Down Expand Up @@ -770,7 +818,13 @@ case class Unhex(child: Expression) extends UnaryExpression with ImplicitCastInp

// scalastyle:off line.size.limit
@ExpressionDescription(
usage = "_FUNC_(expr1, expr2) - Returns the angle in radians between the positive x-axis of a plane and the point given by the coordinates (`expr1`, `expr2`).",
Copy link
Member

Choose a reason for hiding this comment

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

It looks like the declaration of atan2 should group with the trig functions. I think that's OK to fix here.

Copy link
Member

Choose a reason for hiding this comment

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

I believe this should still be moved with this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now I got it. Sorry, earlier I just misunderstood it. Are you proposing to move this case class inside the file to be next to the other trigonometric function? Based on the comments it seems the functions are group based on the number of arguments. This function has 2 arguments that is why it is under // Binary math functions section. Even though this does not seem to create big cohesion inside such a group I guess we do not want to reorganize the file now?

Copy link
Member

Choose a reason for hiding this comment

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

Oh, I get it now, that's my mistake. "Binary" means "two arg" and not perhaps "bitwise" or something. Leave it then.

usage = "_FUNC_(exprY, exprX) - Returns the angle in radians between the positive x-axis of a plane and the point given by the coordinates (`exprX`, `exprY`), as if computed by `java.lang.Math._FUNC_`.",
arguments =
"""
Arguments:
* exprY - coordinate on y-axis
* exprX - coordinate on x-axis
""",
examples = """
Examples:
> SELECT _FUNC_(0, 0);
Expand Down Expand Up @@ -804,7 +858,6 @@ case class Pow(left: Expression, right: Expression)
}
}


Copy link
Member

Choose a reason for hiding this comment

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

Seems unrelated change. Could we just revert this back?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure

/**
* Bitwise left shift.
*
Expand Down Expand Up @@ -916,7 +969,6 @@ case class ShiftRightUnsigned(left: Expression, right: Expression)
case class Hypot(left: Expression, right: Expression)
extends BinaryMathExpression(math.hypot, "HYPOT")


Copy link
Member

Choose a reason for hiding this comment

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

Ditto for revert

/**
* Computes the logarithm of a number.
*
Expand Down
Loading