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:10:37 UTC
git commit: TAJO-392: Implement cbrt function. (DaeMyung Kang via
hyunsik)
Updated Branches:
refs/heads/master 2c7f552a5 -> 6df36b02d
TAJO-392: Implement cbrt 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/6df36b02
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tajo/tree/6df36b02
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tajo/diff/6df36b02
Branch: refs/heads/master
Commit: 6df36b02d495c9a591297cc85f7df27a58040cf3
Parents: 2c7f552
Author: Hyunsik Choi <hy...@apache.org>
Authored: Mon Dec 9 00:07:04 2013 +0900
Committer: Hyunsik Choi <hy...@apache.org>
Committed: Mon Dec 9 00:07:20 2013 +0900
----------------------------------------------------------------------
CHANGES.txt | 2 +
.../apache/tajo/engine/function/math/Cbrt.java | 50 ++++++++++++++++++++
.../java/org/apache/tajo/master/TajoMaster.java | 9 ++++
.../tajo/engine/function/TestMathFunctions.java | 22 +++++++++
4 files changed, 83 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/6df36b02/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 81eba7d..0a9ff68 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -4,6 +4,8 @@ Release 0.8.0 - unreleased
NEW FEATURES
+ TAJO-392: Implement cbrt function. (DaeMyung Kang via hyunsik)
+
TAJO-394: Implement abs function. (DaeMyung Kang via hyunsik)
TAJO-395: Implement exp function. (DaeMyung Kang via hyunsik)
http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/6df36b02/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/function/math/Cbrt.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/function/math/Cbrt.java b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/function/math/Cbrt.java
new file mode 100644
index 0000000..a805351
--- /dev/null
+++ b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/function/math/Cbrt.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 cbrt(value FLOAT8)
+ */
+public class Cbrt extends GeneralFunction {
+ public Cbrt() {
+ 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.cbrt(valueDatum.asFloat8()));
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/6df36b02/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 864afcb..fb48a56 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
@@ -670,6 +670,15 @@ public class TajoMaster extends CompositeService {
CatalogUtil.newSimpleDataTypeArray(Type.FLOAT8)));
+ sqlFuncs.add(
+ new FunctionDesc("cbrt", Cbrt.class, FunctionType.GENERAL,
+ CatalogUtil.newSimpleDataType(Type.FLOAT8),
+ CatalogUtil.newSimpleDataTypeArray(Type.FLOAT4)));
+ sqlFuncs.add(
+ new FunctionDesc("cbrt", Cbrt.class, FunctionType.GENERAL,
+ CatalogUtil.newSimpleDataType(Type.FLOAT8),
+ CatalogUtil.newSimpleDataTypeArray(Type.FLOAT8)));
+
return sqlFuncs;
}
http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/6df36b02/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 00c4510..738b6bf 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
@@ -320,4 +320,26 @@ public class TestMathFunctions extends ExprTestBase {
testEval(schema2, "table1", "0.033312347,-0.033312347", "select abs(col1), abs(col2) from table1",
new String[]{"0.033312347", "0.033312347"});
}
+
+ @Test
+ public void testCbrt() throws IOException {
+ testSimpleEval("select cbrt(27.0) as col1 ", new String[]{"3.0"});
+ testSimpleEval("select cbrt(64.0) as col1 ", new String[]{"4.0"});
+ testSimpleEval("select cbrt(8.0) as col1 ", new String[]{"2.0"});
+
+
+ Schema schema = new Schema();
+ schema.addColumn("col1", FLOAT4);
+ schema.addColumn("col2", FLOAT4);
+ schema.addColumn("col3", FLOAT4);
+ testEval(schema, "table1", "1.0, 0.2, 0.1", "select cbrt(col1 + col2 + col3) from table1",
+ new String[]{"1.0913928968221236"});
+
+ Schema schema2 = new Schema();
+ schema2.addColumn("col1", FLOAT8);
+ schema2.addColumn("col2", FLOAT8);
+ schema2.addColumn("col3", FLOAT8);
+ testEval(schema2, "table1", "1.0, 0.2, 0.1", "select cbrt(col1 + col2 + col3) from table1",
+ new String[]{"1.091392883061106"});
+ }
}