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

git commit: TAJO-365: Implement degrees/radians function. (DaeMyung Kang via hyunsik)

Updated Branches:
  refs/heads/master 25944a912 -> 0ddf6ef4a


TAJO-365: Implement degrees/radians function. (DaeMyung Kang via hyunsik)


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

Branch: refs/heads/master
Commit: 0ddf6ef4aa2991d88e4a26346e6678da5c14267b
Parents: 25944a9
Author: Hyunsik Choi <hy...@apache.org>
Authored: Mon Dec 9 00:45:44 2013 +0900
Committer: Hyunsik Choi <hy...@apache.org>
Committed: Mon Dec 9 00:46:11 2013 +0900

----------------------------------------------------------------------
 CHANGES.txt                                     |  2 +
 .../tajo/engine/function/math/Degrees.java      | 50 ++++++++++++++++++++
 .../tajo/engine/function/math/Radians.java      | 50 ++++++++++++++++++++
 .../java/org/apache/tajo/master/TajoMaster.java | 19 ++++++++
 .../tajo/engine/function/TestMathFunctions.java | 40 ++++++++++++++++
 5 files changed, 161 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/0ddf6ef4/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index eedeb5e..11626ea 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -4,6 +4,8 @@ Release 0.8.0 - unreleased
 
   NEW FEATURES
 
+    TAJO-365: Implement degrees/radians function. (DaeMyung Kang via hyunsik)
+
     TAJO-368: Implement quote_ident function. (Seungun Choe via hyunsik)
 
     TAJO-392: Implement cbrt function. (DaeMyung Kang via hyunsik)

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/0ddf6ef4/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/function/math/Degrees.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/function/math/Degrees.java b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/function/math/Degrees.java
new file mode 100644
index 0000000..e9e4932
--- /dev/null
+++ b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/function/math/Degrees.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
+ *
+ * FLOAT8 degrees(value FLOAT8)
+ */
+public class Degrees extends GeneralFunction {
+  public Degrees() {
+    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.toDegrees(valueDatum.asFloat8()));
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/0ddf6ef4/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/function/math/Radians.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/function/math/Radians.java b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/function/math/Radians.java
new file mode 100644
index 0000000..97ac9c4
--- /dev/null
+++ b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/function/math/Radians.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
+ *
+ * FLOAT8 radians(value FLOAT8)
+ */
+public class Radians extends GeneralFunction {
+  public Radians() {
+    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.toRadians(valueDatum.asFloat8()));
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/0ddf6ef4/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 e28a59f..4c79e50 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
@@ -605,6 +605,25 @@ public class TajoMaster extends CompositeService {
             CatalogUtil.newSimpleDataType(Type.INT8),
             CatalogUtil.newSimpleDataTypeArray(Type.INT8, Type.INT4)));
 
+     sqlFuncs.add(
+         new FunctionDesc("degrees", Degrees.class, FunctionType.GENERAL,
+             CatalogUtil.newSimpleDataType(Type.FLOAT8),
+             CatalogUtil.newSimpleDataTypeArray(Type.FLOAT8)));
+     sqlFuncs.add(
+         new FunctionDesc("degrees", Degrees.class, FunctionType.GENERAL,
+             CatalogUtil.newSimpleDataType(Type.FLOAT8),
+             CatalogUtil.newSimpleDataTypeArray(Type.FLOAT4)));
+
+     sqlFuncs.add(
+         new FunctionDesc("radians", Radians.class, FunctionType.GENERAL,
+             CatalogUtil.newSimpleDataType(Type.FLOAT8),
+             CatalogUtil.newSimpleDataTypeArray(Type.FLOAT8)));
+     sqlFuncs.add(
+         new FunctionDesc("radians", Radians.class, FunctionType.GENERAL,
+             CatalogUtil.newSimpleDataType(Type.FLOAT8),
+             CatalogUtil.newSimpleDataTypeArray(Type.FLOAT4)));
+
+
     sqlFuncs.add(
         new FunctionDesc("initcap", InitCap.class, FunctionType.GENERAL,
             CatalogUtil.newSimpleDataType(Type.TEXT),

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/0ddf6ef4/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 738b6bf..4ea7007 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
@@ -342,4 +342,44 @@ public class TestMathFunctions extends ExprTestBase {
     testEval(schema2, "table1", "1.0, 0.2, 0.1", "select cbrt(col1 + col2 + col3) from table1",
         new String[]{"1.091392883061106"});
   }
+
+  @Test
+  public void testDegrees() throws IOException {
+    testSimpleEval("select degrees(0.0) as col1 ", new String[]{String.valueOf(Math.toDegrees(0.0))});
+    testSimpleEval("select degrees(0.8) as col1 ", new String[]{String.valueOf(Math.toDegrees(0.8))});
+    testSimpleEval("select degrees(2.7) as col1 ", new String[]{String.valueOf(Math.toDegrees(2.7))});
+    testSimpleEval("select degrees(-0.8) as col1 ", new String[]{String.valueOf(Math.toDegrees(-0.8))});
+
+    Schema schema = new Schema();
+    schema.addColumn("col1", FLOAT4);
+    schema.addColumn("col2", FLOAT8);
+    schema.addColumn("col3", FLOAT8);
+
+    testEval(schema, "table1", "0.8,2.7,-0.8", "select degrees(col1), degrees(col2), degrees(col3) from table1",
+        new String[]{
+            String.valueOf(Math.toDegrees((float)0.8)),
+            String.valueOf(Math.toDegrees(2.7)),
+            String.valueOf(Math.toDegrees(-0.8))
+        });
+  }
+
+  @Test
+  public void testRadians() throws IOException {
+    testSimpleEval("select radians(0.0) as col1 ", new String[]{String.valueOf(Math.toRadians(0.0))});
+    testSimpleEval("select radians(0.8) as col1 ", new String[]{String.valueOf(Math.toRadians(0.8))});
+    testSimpleEval("select radians(2.7) as col1 ", new String[]{String.valueOf(Math.toRadians(2.7))});
+    testSimpleEval("select radians(-0.8) as col1 ", new String[]{String.valueOf(Math.toRadians(-0.8))});
+
+    Schema schema = new Schema();
+    schema.addColumn("col1", FLOAT4);
+    schema.addColumn("col2", FLOAT8);
+    schema.addColumn("col3", FLOAT8);
+
+    testEval(schema, "table1", "0.8,2.7,-0.8", "select radians(col1), radians(col2), radians(col3) from table1",
+        new String[]{
+            String.valueOf(Math.toRadians((float)0.8)),
+            String.valueOf(Math.toRadians(2.7)),
+            String.valueOf(Math.toRadians(-0.8))
+        });
+  }
 }