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 13:34:23 UTC
git commit: TAJO-397: Implement sign function. (DaeMyung Kang via
hyunsik)
Updated Branches:
refs/heads/master 17d9cd735 -> 3a05bbf3d
TAJO-397: Implement sign 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/3a05bbf3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tajo/tree/3a05bbf3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tajo/diff/3a05bbf3
Branch: refs/heads/master
Commit: 3a05bbf3d0cbe83e5302dcbeeeb53b63940917b2
Parents: 17d9cd7
Author: Hyunsik Choi <hy...@apache.org>
Authored: Sun Dec 8 21:24:55 2013 +0900
Committer: Hyunsik Choi <hy...@apache.org>
Committed: Sun Dec 8 21:24:55 2013 +0900
----------------------------------------------------------------------
CHANGES.txt | 2 +
.../apache/tajo/engine/function/math/Sign.java | 50 ++++++++++++++++++++
.../java/org/apache/tajo/master/TajoMaster.java | 20 ++++++++
.../tajo/engine/function/TestMathFunctions.java | 28 ++++++++++-
4 files changed, 98 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/3a05bbf3/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 0959159..534b17d 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -4,6 +4,8 @@ Release 0.8.0 - unreleased
NEW FEATURES
+ TAJO-397: Implement sign function. (DaeMyung Kang via hyunsik)
+
TAJO-343: Implement locate function. (KyoungBok Lee via hyunsik)
TAJO-364: Implement mod/div function. (DaeMyung Kang via jaehwa)
http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/3a05bbf3/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/function/math/Sign.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/function/math/Sign.java b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/function/math/Sign.java
new file mode 100644
index 0000000..0f9d466
--- /dev/null
+++ b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/function/math/Sign.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 sign(value FLOAT8)
+ */
+public class Sign extends GeneralFunction {
+ public Sign() {
+ 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.signum(valueDatum.asFloat8()));
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/3a05bbf3/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 9243aa4..37a5e75 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
@@ -615,6 +615,26 @@ public class TajoMaster extends CompositeService {
CatalogUtil.newSimpleDataType(Type.TEXT),
CatalogUtil.newSimpleDataTypeArray(Type.TEXT, Type.INT4, Type.TEXT)));
+ sqlFuncs.add(
+ new FunctionDesc("sign", Sign.class, FunctionType.GENERAL,
+ CatalogUtil.newSimpleDataType(Type.FLOAT8),
+ CatalogUtil.newSimpleDataTypeArray(Type.INT4)));
+
+ sqlFuncs.add(
+ new FunctionDesc("sign", Sign.class, FunctionType.GENERAL,
+ CatalogUtil.newSimpleDataType(Type.FLOAT8),
+ CatalogUtil.newSimpleDataTypeArray(Type.INT8)));
+
+ sqlFuncs.add(
+ new FunctionDesc("sign", Sign.class, FunctionType.GENERAL,
+ CatalogUtil.newSimpleDataType(Type.FLOAT8),
+ CatalogUtil.newSimpleDataTypeArray(Type.FLOAT4)));
+
+ sqlFuncs.add(
+ new FunctionDesc("sign", Sign.class, FunctionType.GENERAL,
+ CatalogUtil.newSimpleDataType(Type.FLOAT8),
+ CatalogUtil.newSimpleDataTypeArray(Type.FLOAT8)));
+
return sqlFuncs;
}
http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/3a05bbf3/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 9004415..2cd4ea1 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
@@ -24,8 +24,7 @@ import org.junit.Test;
import java.io.IOException;
-import static org.apache.tajo.common.TajoDataTypes.Type.FLOAT8;
-import static org.apache.tajo.common.TajoDataTypes.Type.INT8;
+import static org.apache.tajo.common.TajoDataTypes.Type.*;
public class TestMathFunctions extends ExprTestBase {
@Test
@@ -229,4 +228,29 @@ public class TestMathFunctions extends ExprTestBase {
testEval(schema, "table1", "9,2,3", "select div(col1 + col2, col3) from table1",
new String[]{"3"});
}
+
+ @Test
+ public void testSign() throws IOException {
+ testSimpleEval("select sign(2) as col1 ", new String[]{"1.0"});
+ testSimpleEval("select sign(2.345) as col1 ", new String[]{"1.0"});
+ testSimpleEval("select sign(0.3) as col1 ", new String[]{"1.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 sign(col1 + col2 + col3) from table1",
+ new String[]{"1.0"});
+
+
+ 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 sign(col1 + col2 + col3) from table1",
+ new String[]{"1.0"});
+ }
}