tajo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jihoon...@apache.org
Subject git commit: TAJO-413: Implement pi function. (DaeMyung Kang via jihoon)
Date Fri, 13 Dec 2013 13:08:31 GMT
Updated Branches:
  refs/heads/master fe7515d66 -> 1d0d458bf


TAJO-413: Implement pi function. (DaeMyung Kang via jihoon)


Project: http://git-wip-us.apache.org/repos/asf/incubator-tajo/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tajo/commit/1d0d458b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tajo/tree/1d0d458b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tajo/diff/1d0d458b

Branch: refs/heads/master
Commit: 1d0d458bf28af7cfb5a4134c41d0fb0e874f78f9
Parents: fe7515d
Author: Jihoon Son <jihoonson@apache.org>
Authored: Fri Dec 13 22:08:24 2013 +0900
Committer: Jihoon Son <jihoonson@apache.org>
Committed: Fri Dec 13 22:08:24 2013 +0900

----------------------------------------------------------------------
 CHANGES.txt                                     |  2 +
 .../apache/tajo/engine/function/math/Pi.java    | 45 ++++++++++++++++++++
 .../tajo/engine/planner/LogicalPlanner.java     |  5 +++
 .../java/org/apache/tajo/master/TajoMaster.java |  4 ++
 .../tajo/engine/function/TestMathFunctions.java |  4 ++
 5 files changed, 60 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/1d0d458b/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 46bf1ce..452cace 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -4,6 +4,8 @@ Release 0.8.0 - unreleased
 
   NEW FEATURES
 
+    TAJO-413: Implement pi function. (DaeMyung Kang via jihoon)
+
     TAJO-61: Implement Time Datum Type. (DaeMyung Kang via hyunsik)
 
     TAJO-60: Implement Date Datum Type. (hyunsik)

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/1d0d458b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/function/math/Pi.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/function/math/Pi.java
b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/function/math/Pi.java
new file mode 100644
index 0000000..5074439
--- /dev/null
+++ b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/function/math/Pi.java
@@ -0,0 +1,45 @@
+/**
+ * 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.tajo.engine.function.math;
+
+import org.apache.tajo.catalog.Column;
+import org.apache.tajo.common.TajoDataTypes;
+import org.apache.tajo.datum.Datum;
+import org.apache.tajo.datum.DatumFactory;
+import org.apache.tajo.datum.NullDatum;
+import org.apache.tajo.engine.function.GeneralFunction;
+import org.apache.tajo.storage.Tuple;
+
+/**
+ * Function definition
+ *
+ * INT8 ceil(value FLOAT8)
+ */
+public class Pi extends GeneralFunction {
+  public Pi() {
+    super(new Column[] {
+      new Column("value", TajoDataTypes.Type.NULL_TYPE)
+    });
+  }
+
+  @Override
+  public Datum eval(Tuple params) {
+    return DatumFactory.createFloat8(Math.PI);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/1d0d458b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/LogicalPlanner.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/LogicalPlanner.java
b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/LogicalPlanner.java
index 720de53..f43566d 100644
--- a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/LogicalPlanner.java
+++ b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/LogicalPlanner.java
@@ -1205,6 +1205,11 @@ public class LogicalPlanner extends BaseAlgebraVisitor<LogicalPlanner.PlanContex
         FunctionExpr function = (FunctionExpr) expr;
         // Given parameters
         Expr[] params = function.getParams();
+        if (params == null) {
+            params = new Expr[1];
+            params[0] = new NullValue();
+        }
+
         EvalNode[] givenArgs = new EvalNode[params.length];
         DataType[] paramTypes = new DataType[params.length];
 

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/1d0d458b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/master/TajoMaster.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/master/TajoMaster.java
b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/master/TajoMaster.java
index 807e597..f98cecb 100644
--- a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/master/TajoMaster.java
+++ b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/master/TajoMaster.java
@@ -797,6 +797,10 @@ public class TajoMaster extends CompositeService {
             CatalogUtil.newSimpleDataType(Type.FLOAT8),
             CatalogUtil.newSimpleDataTypeArray(Type.FLOAT8, Type.INT8)));
 
+    sqlFuncs.add(
+        new FunctionDesc("pi", Pi.class, FunctionType.GENERAL,
+            CatalogUtil.newSimpleDataType(Type.FLOAT8),
+            CatalogUtil.newSimpleDataTypeArray(Type.NULL_TYPE)));
     return sqlFuncs;
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/1d0d458b/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/function/TestMathFunctions.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/function/TestMathFunctions.java
b/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/function/TestMathFunctions.java
index 350d9a2..b84b90d 100644
--- a/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/function/TestMathFunctions.java
+++ b/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/function/TestMathFunctions.java
@@ -402,4 +402,8 @@ public class TestMathFunctions extends ExprTestBase {
         });
   }
 
+  @Test
+  public void testPi() throws IOException {
+    testSimpleEval("select pi() as col1 ", new String[]{String.valueOf(Math.PI)});
+  }
 }


Mime
View raw message