Repository: flink
Updated Branches:
  refs/heads/master a13a98f65 -> 524a1fa0f


[FLINK-6960] [table] Support E() on SQL.

This closes #4152


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

Branch: refs/heads/master
Commit: 524a1fa0fecbcbd14d3cb6b9e99d20f424d58004
Parents: a13a98f
Author: sunjincheng121 <sunjincheng...@gmail.com>
Authored: Wed Jun 21 16:29:15 2017 +0800
Committer: Jark Wu <j...@apache.org>
Committed: Sun Jun 25 22:51:54 2017 +0800

----------------------------------------------------------------------
 docs/dev/table/sql.md                           | 10 ++++++
 .../table/codegen/calls/FunctionGenerator.scala |  8 +++--
 .../functions/sql/ScalarSqlFunctions.scala      | 34 ++++++++++++++++++++
 .../flink/table/validate/FunctionCatalog.scala  |  3 ++
 .../table/expressions/ScalarFunctionsTest.scala | 11 +++++++
 5 files changed, 64 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flink/blob/524a1fa0/docs/dev/table/sql.md
----------------------------------------------------------------------
diff --git a/docs/dev/table/sql.md b/docs/dev/table/sql.md
index 931a7ca..a736477 100644
--- a/docs/dev/table/sql.md
+++ b/docs/dev/table/sql.md
@@ -1385,6 +1385,16 @@ PI()
         <p>Returns a value that is closer than any other value to pi.</p>
       </td>
     </tr>
+    <tr>
+      <td>
+        {% highlight text %}
+E()
+{% endhighlight %}
+      </td>
+      <td>
+        <p>Returns a value that is closer than any other value to e.</p>
+      </td>
+    </tr>
 
     <tr>
       <td>

http://git-wip-us.apache.org/repos/asf/flink/blob/524a1fa0/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 ed18811..4da5514 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
@@ -28,9 +28,8 @@ import org.apache.calcite.util.BuiltInMethod
 import org.apache.flink.api.common.typeinfo.BasicTypeInfo._
 import org.apache.flink.api.common.typeinfo.{BasicTypeInfo, SqlTimeTypeInfo, 
TypeInformation}
 import org.apache.flink.api.java.typeutils.GenericTypeInfo
-import org.apache.flink.table.codegen.{CodeGenerator, GeneratedExpression}
 import org.apache.flink.table.functions.utils.{ScalarSqlFunction, 
TableSqlFunction}
-
+import org.apache.flink.table.functions.sql.ScalarSqlFunctions._
 import scala.collection.mutable
 
 /**
@@ -395,6 +394,11 @@ object FunctionGenerator {
     Seq(INT_TYPE_INFO, INT_TYPE_INFO),
     new RandCallGen(isRandInteger = true, hasSeed = true))
 
+  addSqlFunction(
+    E,
+    Seq(),
+    new ConstantCallGen(DOUBLE_TYPE_INFO, Math.E.toString))
+
   // 
----------------------------------------------------------------------------------------------
   // Temporal functions
   // 
----------------------------------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/flink/blob/524a1fa0/flink-libraries/flink-table/src/main/scala/org/apache/flink/table/functions/sql/ScalarSqlFunctions.scala
----------------------------------------------------------------------
diff --git 
a/flink-libraries/flink-table/src/main/scala/org/apache/flink/table/functions/sql/ScalarSqlFunctions.scala
 
b/flink-libraries/flink-table/src/main/scala/org/apache/flink/table/functions/sql/ScalarSqlFunctions.scala
new file mode 100644
index 0000000..84f2d21
--- /dev/null
+++ 
b/flink-libraries/flink-table/src/main/scala/org/apache/flink/table/functions/sql/ScalarSqlFunctions.scala
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.flink.table.functions.sql
+
+import org.apache.calcite.sql.{SqlFunction, SqlFunctionCategory, SqlKind}
+import org.apache.calcite.sql.`type`._
+
+/**
+  * All build-in scalar sql functions.
+  */
+object ScalarSqlFunctions {
+  val E = new SqlFunction(
+    "E",
+    SqlKind.OTHER_FUNCTION,
+    ReturnTypes.DOUBLE,
+    null,
+    OperandTypes.NILADIC,
+    SqlFunctionCategory.NUMERIC)
+}

http://git-wip-us.apache.org/repos/asf/flink/blob/524a1fa0/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 a280bc8..4bc6364 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
@@ -23,6 +23,7 @@ import org.apache.calcite.sql.util.{ChainedSqlOperatorTable, 
ListSqlOperatorTabl
 import org.apache.calcite.sql.{SqlFunction, SqlOperator, SqlOperatorTable}
 import org.apache.flink.table.api._
 import org.apache.flink.table.expressions._
+import org.apache.flink.table.functions.sql.ScalarSqlFunctions
 import org.apache.flink.table.functions.utils.{AggSqlFunction, 
ScalarSqlFunction, TableSqlFunction}
 import org.apache.flink.table.functions.{AggregateFunction, ScalarFunction, 
TableFunction}
 
@@ -391,6 +392,8 @@ class BasicOperatorTable extends ReflectiveSqlOperatorTable 
{
     SqlStdOperatorTable.PI,
     SqlStdOperatorTable.RAND,
     SqlStdOperatorTable.RAND_INTEGER,
+    ScalarSqlFunctions.E,
+
     // EXTENSIONS
     SqlStdOperatorTable.TUMBLE,
     SqlStdOperatorTable.TUMBLE_START,

http://git-wip-us.apache.org/repos/asf/flink/blob/524a1fa0/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 5f3baa3..b684108 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
@@ -1147,6 +1147,17 @@ class ScalarFunctionsTest extends ExpressionTestBase {
       random4.nextInt(44).toString)
   }
 
+  @Test
+  def testE(): Unit = {
+    testSqlApi(
+      "E()",
+      math.E.toString)
+
+    testSqlApi(
+      "e()",
+      math.E.toString)
+  }
+
   // 
----------------------------------------------------------------------------------------------
   // Temporal functions
   // 
----------------------------------------------------------------------------------------------

Reply via email to