You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tajo.apache.org by bl...@apache.org on 2013/12/03 08:12:17 UTC

git commit: TAJO-339: Implement sin( x ) - returns the sine of x (x is in radians). (Jae Young Lee via jaehwa)

Updated Branches:
  refs/heads/master 19c7585cc -> 2659cda4a


TAJO-339: Implement sin( x ) - returns the sine of x (x is in radians). (Jae Young Lee via jaehwa)


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

Branch: refs/heads/master
Commit: 2659cda4a88d074a7664babc39ac6ec1719778eb
Parents: 19c7585
Author: blrunner <jh...@gruter.com>
Authored: Tue Dec 3 16:11:55 2013 +0900
Committer: blrunner <jh...@gruter.com>
Committed: Tue Dec 3 16:11:55 2013 +0900

----------------------------------------------------------------------
 CHANGES.txt                                     |  2 +
 .../apache/tajo/engine/function/math/Sin.java   | 50 ++++++++++++++++++++
 .../java/org/apache/tajo/master/TajoMaster.java | 10 ++++
 .../tajo/engine/function/TestMathFunctions.java | 17 +++++++
 4 files changed, 79 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/2659cda4/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 5967f4b..257dd93 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -4,6 +4,8 @@ Release 0.8.0 - unreleased
 
   NEW FEATURES
 
+    TAJO-339: Implement sin( x ) - returns the sine of x (x is in radians). (Jae Young Lee via jaehwa)
+
     TAJO-348: Implement octet_length(text). (DaeMyung Kang via jaehwa)
 
     TAJO-357: Fix invalid filename TestMethFunction to TestMathFUnction.

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/2659cda4/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/function/math/Sin.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/function/math/Sin.java b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/function/math/Sin.java
new file mode 100644
index 0000000..158fad2
--- /dev/null
+++ b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/function/math/Sin.java
@@ -0,0 +1,50 @@
+/**
+ * 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 sin(value FLOAT8)
+ */
+public class Sin extends GeneralFunction {
+    public Sin() {
+        super(new Column[] {
+                new Column("value", TajoDataTypes.Type.FLOAT8)
+        });
+    }
+
+    @Override
+    public Datum eval(Tuple params) {
+        Datum valueDatum = params.get(0);
+        if(valueDatum instanceof NullDatum) {
+            return NullDatum.get();
+        }
+
+        return DatumFactory.createFloat8(Math.sin(valueDatum.asFloat8()));
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/2659cda4/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 8139b8e..d3e9cae 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
@@ -478,6 +478,16 @@ public class TajoMaster extends CompositeService {
             CatalogUtil.newSimpleDataType(Type.INT4),
             CatalogUtil.newSimpleDataTypeArray(Type.TEXT, Type.TEXT)));
 
+    sqlFuncs.add(
+        new FunctionDesc("sin", Sin.class, FunctionType.GENERAL,
+            CatalogUtil.newSimpleDataType(Type.FLOAT8),
+            CatalogUtil.newSimpleDataTypeArray(Type.FLOAT8)));
+
+    sqlFuncs.add(
+        new FunctionDesc("sin", Sin.class, FunctionType.GENERAL,
+            CatalogUtil.newSimpleDataType(Type.FLOAT8),
+            CatalogUtil.newSimpleDataTypeArray(Type.FLOAT4)));
+
     return sqlFuncs;
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/2659cda4/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 6a59b7a..2c95043 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
@@ -80,4 +80,21 @@ public class TestMathFunctions extends ExprTestBase {
     testEval(schema, "table1", "1.0, 0.2, 0.1", "select ceil(col1 + col2 + col3) from table1",
         new String[]{"2"});
   }
+
+  @Test
+  public void testSin() throws IOException {
+    testSimpleEval("select sin(0.0) as col1 ", new String[]{"0.0"});
+    testSimpleEval("select sin(0.7) as col1 ", new String[]{"0.6442176781200616"});
+    testSimpleEval("select sin(1.2) as col1 ", new String[]{"0.9320391032457895"});
+//    testSimpleEval("select sin(-0.5) as col1 ", new String[]{"-0.479425538604203"});
+
+    Schema schema = new Schema();
+    schema.addColumn("col1", FLOAT8);
+    schema.addColumn("col2", FLOAT8);
+    schema.addColumn("col3", FLOAT8);
+
+    testEval(schema, "table1", "1.0, 0.2, 0.1", "select sin(col1 + col2 + col3) from table1",
+       new String[]{"0.963558185417193"});
+}
+
 }