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 14:17:46 UTC
git commit: TAJO-395: Implement exp function. (DaeMyung Kang via
hyunsik)
Updated Branches:
refs/heads/master 595675cc7 -> c4d331352
TAJO-395: Implement exp 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/c4d33135
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tajo/tree/c4d33135
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tajo/diff/c4d33135
Branch: refs/heads/master
Commit: c4d331352daf6b9a742b23696ddfa235761e9c68
Parents: 595675c
Author: Hyunsik Choi <hy...@apache.org>
Authored: Sun Dec 8 22:16:27 2013 +0900
Committer: Hyunsik Choi <hy...@apache.org>
Committed: Sun Dec 8 22:16:53 2013 +0900
----------------------------------------------------------------------
CHANGES.txt | 2 +
.../apache/tajo/engine/function/math/Exp.java | 50 ++++++++++++++++++++
.../java/org/apache/tajo/master/TajoMaster.java | 10 ++++
.../tajo/engine/function/TestMathFunctions.java | 20 ++++++++
4 files changed, 82 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/c4d33135/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 91a68e2..72e3c9f 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -4,6 +4,8 @@ Release 0.8.0 - unreleased
NEW FEATURES
+ TAJO-395: Implement exp function. (DaeMyung Kang via hyunsik)
+
TAJO-396: Implement sqrt function. (DaeMyung Kang via hyunsik)
TAJO-397: Implement sign function. (DaeMyung Kang via hyunsik)
http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/c4d33135/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/function/math/Exp.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/function/math/Exp.java b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/function/math/Exp.java
new file mode 100644
index 0000000..5614809
--- /dev/null
+++ b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/function/math/Exp.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 exp(value FLOAT8)
+ */
+public class Exp extends GeneralFunction {
+ public Exp() {
+ 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.exp(valueDatum.asFloat8()));
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/c4d33135/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 86ba42a..190de12 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
@@ -645,6 +645,16 @@ public class TajoMaster extends CompositeService {
CatalogUtil.newSimpleDataType(Type.FLOAT8),
CatalogUtil.newSimpleDataTypeArray(Type.FLOAT8)));
+ sqlFuncs.add(
+ new FunctionDesc("exp", Exp.class, FunctionType.GENERAL,
+ CatalogUtil.newSimpleDataType(Type.FLOAT8),
+ CatalogUtil.newSimpleDataTypeArray(Type.FLOAT4)));
+
+ sqlFuncs.add(
+ new FunctionDesc("exp", Exp.class, FunctionType.GENERAL,
+ CatalogUtil.newSimpleDataType(Type.FLOAT8),
+ CatalogUtil.newSimpleDataTypeArray(Type.FLOAT8)));
+
return sqlFuncs;
}
http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/c4d33135/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 4132238..e01b3fa 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
@@ -278,4 +278,24 @@ public class TestMathFunctions extends ExprTestBase {
testEval(schema2, "table1", "1.0, 0.2, 0.1", "select sqrt(col1 + col2 + col3) from table1",
new String[]{"1.140175425099138"});
}
+
+ @Test
+ public void testExp() throws IOException {
+ testSimpleEval("select exp(1.0) as col1 ", new String[]{"2.718281828459045"});
+ testSimpleEval("select exp(1.1) as col1 ", new String[]{"3.0041660239464334"});
+ testSimpleEval("select exp(1.2) as col1 ", new String[]{"3.3201169227365472"});
+
+
+ Schema schema = new Schema();
+ schema.addColumn("col1", FLOAT4);
+
+ testEval(schema, "table1", "1.123", "select exp(col1) from table1",
+ new String[]{"3.074062650703663"});
+
+ Schema schema2 = new Schema();
+ schema2.addColumn("col1", FLOAT8);
+
+ testEval(schema2, "table1", "1.123", "select exp(col1) from table1",
+ new String[]{"3.07406257154899"});
+ }
}