[FLINK-6112] [table] Improve documentation, consistency, and fix bugs
Project: http://git-wip-us.apache.org/repos/asf/flink/repo Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/0a334312 Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/0a334312 Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/0a334312 Branch: refs/heads/table-retraction Commit: 0a3343128be3c0f28772f803f82d14c23b084221 Parents: a06b322 Author: twalthr <twal...@apache.org> Authored: Sun Apr 30 15:03:33 2017 +0200 Committer: twalthr <twal...@apache.org> Committed: Sun Apr 30 15:12:46 2017 +0200 ---------------------------------------------------------------------- docs/dev/table_api.md | 297 ++++++++++--------- .../flink/table/api/scala/expressionDsl.scala | 16 +- .../table/codegen/calls/ConstantCallGen.scala | 2 +- .../table/codegen/calls/FunctionGenerator.scala | 66 ++--- .../table/expressions/mathExpressions.scala | 22 +- .../flink/table/validate/FunctionCatalog.scala | 4 +- .../table/expressions/ScalarFunctionsTest.scala | 48 ++- .../table/expressions/SqlExpressionTest.scala | 3 +- 8 files changed, 249 insertions(+), 209 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flink/blob/0a334312/docs/dev/table_api.md ---------------------------------------------------------------------- diff --git a/docs/dev/table_api.md b/docs/dev/table_api.md index 6d52a78..022a73d 100644 --- a/docs/dev/table_api.md +++ b/docs/dev/table_api.md @@ -1977,303 +1977,303 @@ BOOLEAN.isNotFalse </td> </tr> + </tbody> +</table> + + +<table class="table table-bordered"> + <thead> <tr> + <th class="text-left" style="width: 40%">Arithmetic functions</th> + <th class="text-center">Description</th> + </tr> + </thead> + + <tbody> + + <tr> <td> {% highlight java %} -NUMERIC.sin() ++ numeric {% endhighlight %} </td> <td> - <p>Calculates the sine of a given number.</p> + <p>Returns <i>numeric</i>.</p> </td> </tr> <tr> <td> {% highlight java %} -NUMERIC.cos() +- numeric {% endhighlight %} </td> <td> - <p>Calculates the cosine of a given number.</p> + <p>Returns negative <i>numeric</i>.</p> </td> </tr> - + <tr> <td> {% highlight java %} -NUMERIC.tan() +numeric1 + numeric2 {% endhighlight %} </td> <td> - <p>Calculates the tangent of a given number.</p> + <p>Returns <i>numeric1</i> plus <i>numeric2</i>.</p> </td> </tr> <tr> <td> {% highlight java %} -NUMERIC.cot() +numeric1 - numeric2 {% endhighlight %} </td> <td> - <p>Calculates the tangent of a given number.</p> + <p>Returns <i>numeric1</i> minus <i>numeric2</i>.</p> </td> </tr> <tr> <td> {% highlight java %} -NUMERIC.asin() +numeric1 * numeric2 {% endhighlight %} </td> <td> - <p>Calculates the tangent of a given number.</p> + <p>Returns <i>numeric1</i> multiplied by <i>numeric2</i>.</p> </td> </tr> <tr> <td> {% highlight java %} -NUMERIC.acos() +numeric1 / numeric2 {% endhighlight %} </td> <td> - <p>Calculates the tangent of a given number.</p> + <p>Returns <i>numeric1</i> divided by <i>numeric2</i>.</p> </td> </tr> <tr> <td> {% highlight java %} -NUMERIC.atan() +numeric1.power(numeric2) {% endhighlight %} </td> <td> - <p>Calculates the tangent of a given number.</p> + <p>Returns <i>numeric1</i> raised to the power of <i>numeric2</i>.</p> </td> </tr> <tr> <td> {% highlight java %} -NUMERIC.degrees() +NUMERIC.abs() {% endhighlight %} </td> <td> - <p>Converts <i>numeric</i> from radians to degrees.</p> + <p>Calculates the absolute value of given value.</p> </td> </tr> <tr> <td> {% highlight java %} -NUMERIC.radians() +numeric1 % numeric2 {% endhighlight %} </td> <td> - <p>Converts <i>numeric</i> from degrees to radians.</p> + <p>Returns the remainder (modulus) of <i>numeric1</i> divided by <i>numeric2</i>. The result is negative only if <i>numeric1</i> is negative.</p> </td> </tr> <tr> <td> {% highlight java %} -NUMERIC.sign() +NUMERIC.sqrt() {% endhighlight %} </td> <td> - <p>Calculates the signum of a given number.</p> + <p>Calculates the square root of a given value.</p> </td> </tr> <tr> <td> {% highlight java %} -NUMERIC.round(numeric2) +NUMERIC.ln() {% endhighlight %} </td> <td> - <p>Rounds the given number to the other value places right to the decimal point.</p> + <p>Calculates the natural logarithm of given value.</p> </td> </tr> - </tbody> -</table> - - -<table class="table table-bordered"> - <thead> <tr> - <th class="text-left" style="width: 40%">Arithmetic functions</th> - <th class="text-center">Description</th> - </tr> - </thead> - - <tbody> - - <tr> <td> {% highlight java %} -+ numeric +NUMERIC.log10() {% endhighlight %} </td> <td> - <p>Returns <i>numeric</i>.</p> + <p>Calculates the base 10 logarithm of given value.</p> </td> </tr> <tr> <td> {% highlight java %} -- numeric +NUMERIC.exp() {% endhighlight %} </td> <td> - <p>Returns negative <i>numeric</i>.</p> + <p>Calculates the Euler's number raised to the given power.</p> </td> </tr> - + <tr> <td> {% highlight java %} -numeric1 + numeric2 +NUMERIC.ceil() {% endhighlight %} </td> <td> - <p>Returns <i>numeric1</i> plus <i>numeric2</i>.</p> + <p>Calculates the smallest integer greater than or equal to a given number.</p> </td> </tr> <tr> <td> {% highlight java %} -numeric1 - numeric2 +NUMERIC.floor() {% endhighlight %} </td> <td> - <p>Returns <i>numeric1</i> minus <i>numeric2</i>.</p> + <p>Calculates the largest integer less than or equal to a given number.</p> </td> </tr> <tr> <td> {% highlight java %} -numeric1 * numeric2 +NUMERIC.sin() {% endhighlight %} </td> <td> - <p>Returns <i>numeric1</i> multiplied by <i>numeric2</i>.</p> + <p>Calculates the sine of a given number.</p> </td> </tr> <tr> <td> {% highlight java %} -numeric1 / numeric2 +NUMERIC.cos() {% endhighlight %} </td> <td> - <p>Returns <i>numeric1</i> divided by <i>numeric2</i>.</p> + <p>Calculates the cosine of a given number.</p> </td> </tr> <tr> <td> {% highlight java %} -numeric1.power(numeric2) +NUMERIC.tan() {% endhighlight %} </td> <td> - <p>Returns <i>numeric1</i> raised to the power of <i>numeric2</i>.</p> + <p>Calculates the tangent of a given number.</p> </td> </tr> <tr> <td> {% highlight java %} -NUMERIC.abs() +NUMERIC.cot() {% endhighlight %} </td> <td> - <p>Calculates the absolute value of given value.</p> + <p>Calculates the cotangent of a given number.</p> </td> </tr> <tr> <td> {% highlight java %} -numeric1 % numeric2 +NUMERIC.asin() {% endhighlight %} </td> <td> - <p>Returns the remainder (modulus) of <i>numeric1</i> divided by <i>numeric2</i>. The result is negative only if <i>numeric1</i> is negative.</p> + <p>Calculates the arc sine of a given number.</p> </td> </tr> <tr> <td> {% highlight java %} -NUMERIC.sqrt() +NUMERIC.acos() {% endhighlight %} </td> <td> - <p>Calculates the square root of a given value.</p> + <p>Calculates the arc cosine of a given number.</p> </td> </tr> <tr> <td> {% highlight java %} -NUMERIC.ln() +NUMERIC.atan() {% endhighlight %} </td> <td> - <p>Calculates the natural logarithm of given value.</p> + <p>Calculates the arc tangent of a given number.</p> </td> </tr> <tr> <td> {% highlight java %} -NUMERIC.log10() +NUMERIC.degrees() {% endhighlight %} </td> <td> - <p>Calculates the base 10 logarithm of given value.</p> + <p>Converts <i>numeric</i> from radians to degrees.</p> </td> </tr> <tr> <td> {% highlight java %} -NUMERIC.exp() +NUMERIC.radians() {% endhighlight %} </td> <td> - <p>Calculates the Euler's number raised to the given power.</p> + <p>Converts <i>numeric</i> from degrees to radians.</p> </td> </tr> <tr> <td> {% highlight java %} -NUMERIC.ceil() +NUMERIC.sign() {% endhighlight %} </td> <td> - <p>Calculates the smallest integer greater than or equal to a given number.</p> + <p>Calculates the signum of a given number.</p> </td> </tr> <tr> <td> {% highlight java %} -NUMERIC.floor() +NUMERIC.round(INT) {% endhighlight %} </td> <td> - <p>Calculates the largest integer less than or equal to a given number.</p> + <p>Rounds the given number to <i>integer</i> places right to the decimal point.</p> </td> </tr> @@ -2284,7 +2284,7 @@ pi() {% endhighlight %} </td> <td> - <p> Returns pi.</p> + <p>Returns a value that is closer than any other value to pi.</p> </td> </tr> @@ -3337,7 +3337,7 @@ NUMERIC.tan() {% endhighlight %} </td> <td> - <p>Calculates the tangent of a given number.</p> + <p>Calculates the cotangent of a given number.</p> </td> </tr> @@ -3348,7 +3348,7 @@ NUMERIC.cot() {% endhighlight %} </td> <td> - <p>Calculates the tangent of a given number.</p> + <p>Calculates the arc sine of a given number.</p> </td> </tr> @@ -3359,7 +3359,7 @@ NUMERIC.asin() {% endhighlight %} </td> <td> - <p>Calculates the tangent of a given number.</p> + <p>Calculates the arc cosine of a given number.</p> </td> </tr> @@ -3370,7 +3370,7 @@ NUMERIC.acos() {% endhighlight %} </td> <td> - <p>Calculates the tangent of a given number.</p> + <p>Calculates the arc tangent of a given number.</p> </td> </tr> @@ -3421,11 +3421,11 @@ NUMERIC.sign() <tr> <td> {% highlight scala %} -NUMERIC.round(numeric2) +NUMERIC.round(INT) {% endhighlight %} </td> <td> - <p>Rounds the given number to the other value places right to the decimal point.</p> + <p>Rounds the given number to <i>integer</i> places right to the decimal point.</p> </td> </tr> @@ -3436,7 +3436,7 @@ pi() {% endhighlight %} </td> <td> - <p> Returns pi.</p> + <p>Returns a value that is closer than any other value to pi.</p> </td> </tr> @@ -4436,312 +4436,313 @@ boolean IS NOT UNKNOWN </td> </tr> + </tbody> +</table> + +<table class="table table-bordered"> + <thead> + <tr> + <th class="text-left" style="width: 40%">Arithmetic functions</th> + <th class="text-center">Description</th> + </tr> + </thead> + + <tbody> <tr> <td> {% highlight text %} -SIN(numeric) ++ numeric {% endhighlight %} </td> <td> - <p>Calculates the sine of a given number.</p> + <p>Returns <i>numeric</i>.</p> </td> </tr> <tr> <td> {% highlight text %} -COS(numeric) +- numeric {% endhighlight %} </td> <td> - <p>Calculates the cosine of a given number.</p> + <p>Returns negative <i>numeric</i>.</p> </td> </tr> - + <tr> <td> {% highlight text %} -TAN(numeric) +numeric1 + numeric2 {% endhighlight %} </td> <td> - <p>Calculates the tangent of a given number.</p> + <p>Returns <i>numeric1</i> plus <i>numeric2</i>.</p> </td> </tr> <tr> <td> {% highlight text %} -COT(numeric) +numeric1 - numeric2 {% endhighlight %} </td> <td> - <p>Calculates the tangent of a given number.</p> + <p>Returns <i>numeric1</i> minus <i>numeric2</i>.</p> </td> </tr> <tr> <td> {% highlight text %} -ASIN(numeric) +numeric1 * numeric2 {% endhighlight %} </td> <td> - <p>Calculates the tangent of a given number.</p> + <p>Returns <i>numeric1</i> multiplied by <i>numeric2</i>.</p> </td> </tr> <tr> <td> {% highlight text %} -ACOS(numeric) +numeric1 / numeric2 {% endhighlight %} </td> <td> - <p>Calculates the tangent of a given number.</p> + <p>Returns <i>numeric1</i> divided by <i>numeric2</i>.</p> </td> </tr> <tr> <td> {% highlight text %} -ATAN(numeric) +POWER(numeric1, numeric2) {% endhighlight %} </td> <td> - <p>Calculates the tangent of a given number.</p> + <p>Returns <i>numeric1</i> raised to the power of <i>numeric2</i>.</p> </td> </tr> <tr> <td> {% highlight text %} -DEGREES(numeric) +ABS(numeric) {% endhighlight %} </td> <td> - <p>Converts <i>numeric</i> from radians to degrees.</p> + <p>Returns the absolute value of <i>numeric</i>.</p> </td> </tr> <tr> <td> {% highlight text %} -RADIANS(numeric) +MOD(numeric1, numeric2) {% endhighlight %} </td> <td> - <p>Converts <i>numeric</i> from degrees to radians.</p> + <p>Returns the remainder (modulus) of <i>numeric1</i> divided by <i>numeric2</i>. The result is negative only if <i>numeric1</i> is negative.</p> </td> </tr> <tr> <td> {% highlight text %} -SIGN(numeric) +SQRT(numeric) {% endhighlight %} </td> <td> - <p>Calculates the signum of a given number.</p> + <p>Returns the square root of <i>numeric</i>.</p> </td> </tr> <tr> <td> {% highlight text %} -ROUND(numeric1, numeric2) +LN(numeric) {% endhighlight %} </td> <td> - <p>Rounds the given number to the other value places right to the decimal point.</p> + <p>Returns the natural logarithm (base e) of <i>numeric</i>.</p> </td> </tr> <tr> <td> {% highlight text %} -PI +LOG10(numeric) {% endhighlight %} </td> <td> - <p> Returns pi.</p> + <p>Returns the base 10 logarithm of <i>numeric</i>.</p> </td> </tr> - </tbody> -</table> - -<table class="table table-bordered"> - <thead> - <tr> - <th class="text-left" style="width: 40%">Arithmetic functions</th> - <th class="text-center">Description</th> - </tr> - </thead> - - <tbody> <tr> <td> {% highlight text %} -+ numeric +EXP(numeric) {% endhighlight %} </td> <td> - <p>Returns <i>numeric</i>.</p> + <p>Returns e raised to the power of <i>numeric</i>.</p> </td> - </tr> + </tr> <tr> <td> {% highlight text %} -- numeric +CEIL(numeric) +CEILING(numeric) {% endhighlight %} </td> <td> - <p>Returns negative <i>numeric</i>.</p> + <p>Rounds <i>numeric</i> up, and returns the smallest number that is greater than or equal to <i>numeric</i>.</p> </td> - </tr> - + </tr> + <tr> <td> {% highlight text %} -numeric1 + numeric2 +FLOOR(numeric) {% endhighlight %} </td> <td> - <p>Returns <i>numeric1</i> plus <i>numeric2</i>.</p> + <p>Rounds <i>numeric</i> down, and returns the largest number that is less than or equal to <i>numeric</i>.</p> </td> </tr> <tr> <td> {% highlight text %} -numeric1 - numeric2 +SIN(numeric) {% endhighlight %} </td> <td> - <p>Returns <i>numeric1</i> minus <i>numeric2</i>.</p> + <p>Calculates the sine of a given number.</p> </td> </tr> <tr> <td> {% highlight text %} -numeric1 * numeric2 +COS(numeric) {% endhighlight %} </td> <td> - <p>Returns <i>numeric1</i> multiplied by <i>numeric2</i>.</p> + <p>Calculates the cosine of a given number.</p> </td> </tr> <tr> <td> {% highlight text %} -numeric1 / numeric2 +TAN(numeric) {% endhighlight %} </td> <td> - <p>Returns <i>numeric1</i> divided by <i>numeric2</i>.</p> + <p>Calculates the tangent of a given number.</p> </td> </tr> <tr> <td> {% highlight text %} -POWER(numeric1, numeric2) +COT(numeric) {% endhighlight %} </td> <td> - <p>Returns <i>numeric1</i> raised to the power of <i>numeric2</i>.</p> + <p>Calculates the cotangent of a given number.</p> </td> </tr> <tr> <td> {% highlight text %} -ABS(numeric) +ASIN(numeric) {% endhighlight %} </td> <td> - <p>Returns the absolute value of <i>numeric</i>.</p> + <p>Calculates the arc sine of a given number.</p> </td> </tr> <tr> <td> {% highlight text %} -MOD(numeric1, numeric2) +ACOS(numeric) {% endhighlight %} </td> <td> - <p>Returns the remainder (modulus) of <i>numeric1</i> divided by <i>numeric2</i>. The result is negative only if <i>numeric1</i> is negative.</p> + <p>Calculates the arc cosine of a given number.</p> </td> </tr> <tr> <td> {% highlight text %} -SQRT(numeric) +ATAN(numeric) {% endhighlight %} </td> <td> - <p>Returns the square root of <i>numeric</i>.</p> + <p>Calculates the arc tangent of a given number.</p> </td> </tr> <tr> <td> {% highlight text %} -LN(numeric) +DEGREES(numeric) {% endhighlight %} </td> <td> - <p>Returns the natural logarithm (base e) of <i>numeric</i>.</p> + <p>Converts <i>numeric</i> from radians to degrees.</p> </td> </tr> <tr> <td> {% highlight text %} -LOG10(numeric) +RADIANS(numeric) {% endhighlight %} </td> <td> - <p>Returns the base 10 logarithm of <i>numeric</i>.</p> + <p>Converts <i>numeric</i> from degrees to radians.</p> </td> </tr> <tr> <td> {% highlight text %} -EXP(numeric) +SIGN(numeric) {% endhighlight %} </td> <td> - <p>Returns e raised to the power of <i>numeric</i>.</p> + <p>Calculates the signum of a given number.</p> </td> - </tr> + </tr> <tr> <td> {% highlight text %} -CEIL(numeric) +ROUND(numeric, int) {% endhighlight %} </td> <td> - <p>Rounds <i>numeric</i> up, and returns the smallest number that is greater than or equal to <i>numeric</i>.</p> + <p>Rounds the given number to <i>integer</i> places right to the decimal point.</p> </td> - </tr> + </tr> <tr> <td> {% highlight text %} -FLOOR(numeric) +PI() {% endhighlight %} </td> <td> - <p>Rounds <i>numeric</i> down, and returns the largest number that is less than or equal to <i>numeric</i>.</p> + <p>Returns a value that is closer than any other value to pi.</p> </td> </tr> http://git-wip-us.apache.org/repos/asf/flink/blob/0a334312/flink-libraries/flink-table/src/main/scala/org/apache/flink/table/api/scala/expressionDsl.scala ---------------------------------------------------------------------- diff --git a/flink-libraries/flink-table/src/main/scala/org/apache/flink/table/api/scala/expressionDsl.scala b/flink-libraries/flink-table/src/main/scala/org/apache/flink/table/api/scala/expressionDsl.scala index 169a729..a512098 100644 --- a/flink-libraries/flink-table/src/main/scala/org/apache/flink/table/api/scala/expressionDsl.scala +++ b/flink-libraries/flink-table/src/main/scala/org/apache/flink/table/api/scala/expressionDsl.scala @@ -291,22 +291,22 @@ trait ImplicitExpressionOperations { def tan() = Tan(expr) /** - * Calculates the tangent of a given number. + * Calculates the cotangent of a given number. */ def cot() = Cot(expr) /** - * Calculates the tangent of a given number. + * Calculates the arc sine of a given number. */ def asin() = Asin(expr) /** - * Calculates the tangent of a given number. + * Calculates the arc cosine of a given number. */ def acos() = Acos(expr) /** - * Calculates the tangent of a given number. + * Calculates the arc tangent of a given number. */ def atan() = Atan(expr) @@ -326,9 +326,9 @@ trait ImplicitExpressionOperations { def sign() = Sign(expr) /** - * Rounds the given number to the other value places right to the decimal point. + * Rounds the given number to integer places right to the decimal point. */ - def round(other: Expression) = Round(expr, other) + def round(places: Expression) = Round(expr, places) // String operations @@ -863,12 +863,12 @@ object array { } /** - * Returns pi. + * Returns a value that is closer than any other value to pi. */ object pi { /** - * Returns pi. + * Returns a value that is closer than any other value to pi. */ def apply(): Expression = { Pi() http://git-wip-us.apache.org/repos/asf/flink/blob/0a334312/flink-libraries/flink-table/src/main/scala/org/apache/flink/table/codegen/calls/ConstantCallGen.scala ---------------------------------------------------------------------- diff --git a/flink-libraries/flink-table/src/main/scala/org/apache/flink/table/codegen/calls/ConstantCallGen.scala b/flink-libraries/flink-table/src/main/scala/org/apache/flink/table/codegen/calls/ConstantCallGen.scala index 39fb13b..779d077 100644 --- a/flink-libraries/flink-table/src/main/scala/org/apache/flink/table/codegen/calls/ConstantCallGen.scala +++ b/flink-libraries/flink-table/src/main/scala/org/apache/flink/table/codegen/calls/ConstantCallGen.scala @@ -22,7 +22,7 @@ import org.apache.flink.api.common.typeinfo.TypeInformation import org.apache.flink.table.codegen.{CodeGenerator, GeneratedExpression} /** - * Generates a function call which return a constant. + * Generates a function call which returns a constant. */ class ConstantCallGen( targetType: TypeInformation[_], http://git-wip-us.apache.org/repos/asf/flink/blob/0a334312/flink-libraries/flink-table/src/main/scala/org/apache/flink/table/codegen/calls/FunctionGenerator.scala ---------------------------------------------------------------------- diff --git a/flink-libraries/flink-table/src/main/scala/org/apache/flink/table/codegen/calls/FunctionGenerator.scala b/flink-libraries/flink-table/src/main/scala/org/apache/flink/table/codegen/calls/FunctionGenerator.scala index b8b001f..a0d132b 100644 --- a/flink-libraries/flink-table/src/main/scala/org/apache/flink/table/codegen/calls/FunctionGenerator.scala +++ b/flink-libraries/flink-table/src/main/scala/org/apache/flink/table/codegen/calls/FunctionGenerator.scala @@ -179,6 +179,36 @@ object FunctionGenerator { DOUBLE_TYPE_INFO, BuiltInMethods.POWER_DEC) + addSqlFunction( + ABS, + Seq(DOUBLE_TYPE_INFO), + new MultiTypeMethodCallGen(BuiltInMethods.ABS)) + + addSqlFunction( + ABS, + Seq(BIG_DEC_TYPE_INFO), + new MultiTypeMethodCallGen(BuiltInMethods.ABS_DEC)) + + addSqlFunction( + FLOOR, + Seq(DOUBLE_TYPE_INFO), + new FloorCeilCallGen(BuiltInMethod.FLOOR.method)) + + addSqlFunction( + FLOOR, + Seq(BIG_DEC_TYPE_INFO), + new FloorCeilCallGen(BuiltInMethod.FLOOR.method)) + + addSqlFunction( + CEIL, + Seq(DOUBLE_TYPE_INFO), + new FloorCeilCallGen(BuiltInMethod.CEIL.method)) + + addSqlFunction( + CEIL, + Seq(BIG_DEC_TYPE_INFO), + new FloorCeilCallGen(BuiltInMethod.CEIL.method)) + addSqlFunctionMethod( SIN, Seq(DOUBLE_TYPE_INFO), @@ -287,11 +317,6 @@ object FunctionGenerator { DOUBLE_TYPE_INFO, BuiltInMethods.RADIANS_DEC) - addSqlFunction( - PI, - Seq(), - new ConstantCallGen(DOUBLE_TYPE_INFO, Math.PI.toString)) - addSqlFunctionMethod( SIGN, Seq(DOUBLE_TYPE_INFO), @@ -341,34 +366,9 @@ object FunctionGenerator { BuiltInMethods.ROUND_DOUBLE) addSqlFunction( - ABS, - Seq(DOUBLE_TYPE_INFO), - new MultiTypeMethodCallGen(BuiltInMethods.ABS)) - - addSqlFunction( - ABS, - Seq(BIG_DEC_TYPE_INFO), - new MultiTypeMethodCallGen(BuiltInMethods.ABS_DEC)) - - addSqlFunction( - FLOOR, - Seq(DOUBLE_TYPE_INFO), - new FloorCeilCallGen(BuiltInMethod.FLOOR.method)) - - addSqlFunction( - FLOOR, - Seq(BIG_DEC_TYPE_INFO), - new FloorCeilCallGen(BuiltInMethod.FLOOR.method)) - - addSqlFunction( - CEIL, - Seq(DOUBLE_TYPE_INFO), - new FloorCeilCallGen(BuiltInMethod.CEIL.method)) - - addSqlFunction( - CEIL, - Seq(BIG_DEC_TYPE_INFO), - new FloorCeilCallGen(BuiltInMethod.CEIL.method)) + PI, + Seq(), + new ConstantCallGen(DOUBLE_TYPE_INFO, Math.PI.toString)) // ---------------------------------------------------------------------------------------------- // Temporal functions http://git-wip-us.apache.org/repos/asf/flink/blob/0a334312/flink-libraries/flink-table/src/main/scala/org/apache/flink/table/expressions/mathExpressions.scala ---------------------------------------------------------------------- diff --git a/flink-libraries/flink-table/src/main/scala/org/apache/flink/table/expressions/mathExpressions.scala b/flink-libraries/flink-table/src/main/scala/org/apache/flink/table/expressions/mathExpressions.scala index 16cb34a..fae4470 100644 --- a/flink-libraries/flink-table/src/main/scala/org/apache/flink/table/expressions/mathExpressions.scala +++ b/flink-libraries/flink-table/src/main/scala/org/apache/flink/table/expressions/mathExpressions.scala @@ -241,17 +241,7 @@ case class Radians(child: Expression) extends UnaryExpression { override def toString: String = s"radians($child)" override private[flink] def toRexNode(implicit relBuilder: RelBuilder): RexNode = { - relBuilder.call(SqlStdOperatorTable.DEGREES, child.toRexNode) - } -} - -case class Pi() extends LeafExpression { - override private[flink] def resultType: TypeInformation[_] = DOUBLE_TYPE_INFO - - override def toString: String = s"pi()" - - override private[flink] def toRexNode(implicit relBuilder: RelBuilder): RexNode = { - relBuilder.call(SqlStdOperatorTable.PI) + relBuilder.call(SqlStdOperatorTable.RADIANS, child.toRexNode) } } @@ -285,3 +275,13 @@ case class Round(left: Expression, right: Expression) extends BinaryExpression { relBuilder.call(SqlStdOperatorTable.ROUND, left.toRexNode, right.toRexNode) } } + +case class Pi() extends LeafExpression { + override private[flink] def resultType: TypeInformation[_] = DOUBLE_TYPE_INFO + + override def toString: String = s"pi()" + + override private[flink] def toRexNode(implicit relBuilder: RelBuilder): RexNode = { + relBuilder.call(SqlStdOperatorTable.PI) + } +} http://git-wip-us.apache.org/repos/asf/flink/blob/0a334312/flink-libraries/flink-table/src/main/scala/org/apache/flink/table/validate/FunctionCatalog.scala ---------------------------------------------------------------------- diff --git a/flink-libraries/flink-table/src/main/scala/org/apache/flink/table/validate/FunctionCatalog.scala b/flink-libraries/flink-table/src/main/scala/org/apache/flink/table/validate/FunctionCatalog.scala index 97a7e96..729ad48 100644 --- a/flink-libraries/flink-table/src/main/scala/org/apache/flink/table/validate/FunctionCatalog.scala +++ b/flink-libraries/flink-table/src/main/scala/org/apache/flink/table/validate/FunctionCatalog.scala @@ -210,9 +210,9 @@ object FunctionCatalog { "atan" -> classOf[Atan], "degrees" -> classOf[Degrees], "radians" -> classOf[Radians], - "pi" -> classOf[Pi], "sign" -> classOf[Sign], "round" -> classOf[Round], + "pi" -> classOf[Pi], // temporal functions "extract" -> classOf[Extract], @@ -369,9 +369,9 @@ class BasicOperatorTable extends ReflectiveSqlOperatorTable { SqlStdOperatorTable.ATAN, SqlStdOperatorTable.DEGREES, SqlStdOperatorTable.RADIANS, - SqlStdOperatorTable.PI, SqlStdOperatorTable.SIGN, SqlStdOperatorTable.ROUND, + SqlStdOperatorTable.PI, // EXTENSIONS EventTimeExtractor, ProcTimeExtractor, http://git-wip-us.apache.org/repos/asf/flink/blob/0a334312/flink-libraries/flink-table/src/test/scala/org/apache/flink/table/expressions/ScalarFunctionsTest.scala ---------------------------------------------------------------------- diff --git a/flink-libraries/flink-table/src/test/scala/org/apache/flink/table/expressions/ScalarFunctionsTest.scala b/flink-libraries/flink-table/src/test/scala/org/apache/flink/table/expressions/ScalarFunctionsTest.scala index 85804bc..c1c2508 100644 --- a/flink-libraries/flink-table/src/test/scala/org/apache/flink/table/expressions/ScalarFunctionsTest.scala +++ b/flink-libraries/flink-table/src/test/scala/org/apache/flink/table/expressions/ScalarFunctionsTest.scala @@ -1027,12 +1027,42 @@ class ScalarFunctionsTest extends ExpressionTestBase { } @Test - def testPi(): Unit = { + def testRadians(): Unit = { testAllApis( - pi(), - "pi()", - "PI", - math.Pi.toString) + 'f2.radians(), + "f2.radians()", + "RADIANS(f2)", + math.toRadians(42.toByte).toString) + + testAllApis( + 'f3.radians(), + "f3.radians()", + "RADIANS(f3)", + math.toRadians(43.toShort).toString) + + testAllApis( + 'f4.radians(), + "f4.radians()", + "RADIANS(f4)", + math.toRadians(44.toLong).toString) + + testAllApis( + 'f5.radians(), + "f5.radians()", + "RADIANS(f5)", + math.toRadians(4.5.toFloat).toString) + + testAllApis( + 'f6.radians(), + "f6.radians()", + "RADIANS(f6)", + math.toRadians(4.6).toString) + + testAllApis( + 'f15.radians(), + "radians(f15)", + "RADIANS(f15)", + math.toRadians(-1231.1231231321321321111).toString) } @Test @@ -1075,7 +1105,15 @@ class ScalarFunctionsTest extends ExpressionTestBase { "f4.round(f32)", "ROUND(f4, f32)", 40.toString) + } + @Test + def testPi(): Unit = { + testAllApis( + pi(), + "pi()", + "PI", + math.Pi.toString) } // ---------------------------------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flink/blob/0a334312/flink-libraries/flink-table/src/test/scala/org/apache/flink/table/expressions/SqlExpressionTest.scala ---------------------------------------------------------------------- diff --git a/flink-libraries/flink-table/src/test/scala/org/apache/flink/table/expressions/SqlExpressionTest.scala b/flink-libraries/flink-table/src/test/scala/org/apache/flink/table/expressions/SqlExpressionTest.scala index b11e291..5cc8bd1 100644 --- a/flink-libraries/flink-table/src/test/scala/org/apache/flink/table/expressions/SqlExpressionTest.scala +++ b/flink-libraries/flink-table/src/test/scala/org/apache/flink/table/expressions/SqlExpressionTest.scala @@ -110,9 +110,10 @@ class SqlExpressionTest extends ExpressionTestBase { testSqlApi("ACOS(0.5)", "1.0471975511965979") testSqlApi("ATAN(0.5)", "0.4636476090008061") testSqlApi("DEGREES(0.5)", "28.64788975654116") - testSqlApi("PI", "3.141592653589793") + testSqlApi("RADIANS(0.5)", "0.008726646259971648") testSqlApi("SIGN(-1.1)", "-1") testSqlApi("ROUND(-12.345, 2)", "-12.35") + testSqlApi("PI", "3.141592653589793") } @Test