flink-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From twal...@apache.org
Subject flink git commit: [FLINK-6942] [table] Add E() support in Table API
Date Mon, 26 Jun 2017 08:45:25 GMT
Repository: flink
Updated Branches:
  refs/heads/master 524a1fa0f -> 2d8203027


[FLINK-6942] [table] Add E() support in Table API

This closes #4181.


Project: http://git-wip-us.apache.org/repos/asf/flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/2d820302
Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/2d820302
Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/2d820302

Branch: refs/heads/master
Commit: 2d82030277da58040b24a14ff665a9356a4ee4b2
Parents: 524a1fa
Author: twalthr <twalthr@apache.org>
Authored: Mon Jun 26 09:28:59 2017 +0200
Committer: twalthr <twalthr@apache.org>
Committed: Mon Jun 26 10:38:12 2017 +0200

----------------------------------------------------------------------
 docs/dev/table/tableApi.md                      | 22 ++++++++++++++++++++
 .../flink/table/api/scala/expressionDsl.scala   | 13 ++++++++++++
 .../table/expressions/mathExpressions.scala     | 11 ++++++++++
 .../flink/table/validate/FunctionCatalog.scala  |  1 +
 .../table/expressions/ScalarFunctionsTest.scala |  8 +++++--
 5 files changed, 53 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flink/blob/2d820302/docs/dev/table/tableApi.md
----------------------------------------------------------------------
diff --git a/docs/dev/table/tableApi.md b/docs/dev/table/tableApi.md
index 34cee24..02f3432 100644
--- a/docs/dev/table/tableApi.md
+++ b/docs/dev/table/tableApi.md
@@ -2071,6 +2071,17 @@ pi()
     <tr>
       <td>
         {% highlight java %}
+e()
+{% endhighlight %}
+      </td>
+      <td>
+        <p>Returns a value that is closer than any other value to e.</p>
+      </td>
+    </tr>
+
+    <tr>
+      <td>
+        {% highlight java %}
 rand()
 {% endhighlight %}
       </td>
@@ -3323,6 +3334,17 @@ pi()
     <tr>
       <td>
         {% highlight scala %}
+e()
+{% endhighlight %}
+      </td>
+      <td>
+        <p>Returns a value that is closer than any other value to e.</p>
+      </td>
+    </tr>
+
+    <tr>
+      <td>
+        {% highlight scala %}
 rand()
 {% endhighlight %}
       </td>

http://git-wip-us.apache.org/repos/asf/flink/blob/2d820302/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 0fb940f..9370c57 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
@@ -924,6 +924,19 @@ object pi {
 }
 
 /**
+  * Returns a value that is closer than any other value to e.
+  */
+object e {
+
+  /**
+    * Returns a value that is closer than any other value to e.
+    */
+  def apply(): Expression = {
+    E()
+  }
+}
+
+/**
   * Returns a pseudorandom double value between 0.0 (inclusive) and 1.0 (exclusive).
   */
 object rand {

http://git-wip-us.apache.org/repos/asf/flink/blob/2d820302/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 f78d917..3f8085b 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
@@ -22,6 +22,7 @@ import org.apache.calcite.sql.fun.SqlStdOperatorTable
 import org.apache.calcite.tools.RelBuilder
 import org.apache.flink.api.common.typeinfo.BasicTypeInfo._
 import org.apache.flink.api.common.typeinfo.{BasicTypeInfo, TypeInformation}
+import org.apache.flink.table.functions.sql.ScalarSqlFunctions
 import org.apache.flink.table.typeutils.TypeCheckUtils
 import org.apache.flink.table.validate._
 
@@ -287,6 +288,16 @@ case class Pi() extends LeafExpression {
   }
 }
 
+case class E() extends LeafExpression {
+  override private[flink] def resultType: TypeInformation[_] = DOUBLE_TYPE_INFO
+
+  override def toString: String = s"e()"
+
+  override private[flink] def toRexNode(implicit relBuilder: RelBuilder): RexNode = {
+    relBuilder.call(ScalarSqlFunctions.E)
+  }
+}
+
 case class Rand(seed: Expression) extends Expression with InputTypeSpec {
 
   def this() = this(null)

http://git-wip-us.apache.org/repos/asf/flink/blob/2d820302/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 4bc6364..6d3006d 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
@@ -223,6 +223,7 @@ object FunctionCatalog {
     "sign" -> classOf[Sign],
     "round" -> classOf[Round],
     "pi" -> classOf[Pi],
+    "e" -> classOf[E],
     "rand" -> classOf[Rand],
     "randInteger" -> classOf[RandInteger],
 

http://git-wip-us.apache.org/repos/asf/flink/blob/2d820302/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 b684108..d4c2a45 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
@@ -1149,11 +1149,15 @@ class ScalarFunctionsTest extends ExpressionTestBase {
 
   @Test
   def testE(): Unit = {
-    testSqlApi(
+    testAllApis(
+      e(),
+      "E()",
       "E()",
       math.E.toString)
 
-    testSqlApi(
+    testAllApis(
+      e(),
+      "e()",
       "e()",
       math.E.toString)
   }


Mime
View raw message