You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tajo.apache.org by ji...@apache.org on 2013/12/03 12:51:06 UTC
[11/18] git commit: TAJO-348: Implement octet_length(text). (DaeMyung
Kang via jaehwa)
TAJO-348: Implement octet_length(text). (DaeMyung Kang 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/19c7585c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tajo/tree/19c7585c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tajo/diff/19c7585c
Branch: refs/heads/DAG-execplan
Commit: 19c7585cc775764860341fcc9404ee92d80d3b20
Parents: b3d754e
Author: blrunner <jh...@gruter.com>
Authored: Tue Dec 3 16:00:07 2013 +0900
Committer: blrunner <jh...@gruter.com>
Committed: Tue Dec 3 16:00:07 2013 +0900
----------------------------------------------------------------------
CHANGES.txt | 2 +
.../engine/function/string/OctetLength.java | 51 ++++++++++++++++++++
.../java/org/apache/tajo/master/TajoMaster.java | 5 ++
.../TestStringOperatorsAndFunctions.java | 14 ++++++
4 files changed, 72 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/19c7585c/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index b4ab394..5967f4b 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -4,6 +4,8 @@ Release 0.8.0 - unreleased
NEW FEATURES
+ TAJO-348: Implement octet_length(text). (DaeMyung Kang via jaehwa)
+
TAJO-357: Fix invalid filename TestMethFunction to TestMathFUnction.
(DaeMyung Kang via hyunsik)
http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/19c7585c/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/function/string/OctetLength.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/function/string/OctetLength.java b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/function/string/OctetLength.java
new file mode 100644
index 0000000..345244d
--- /dev/null
+++ b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/function/string/OctetLength.java
@@ -0,0 +1,51 @@
+/**
+ * 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.string;
+
+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
+ *
+ * INT4 octet_length(string text)
+ */
+public class OctetLength extends GeneralFunction {
+
+ public OctetLength() {
+ super(new Column[] {
+ new Column("text", TajoDataTypes.Type.TEXT)
+ });
+ }
+
+ @Override
+ public Datum eval(Tuple params) {
+ Datum datum = params.get(0);
+ if(datum instanceof NullDatum) {
+ return NullDatum.get();
+ }
+
+ return DatumFactory.createInt4(datum.asByteArray().length);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/19c7585c/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 0ea3c73..8139b8e 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
@@ -431,6 +431,11 @@ public class TajoMaster extends CompositeService {
CatalogUtil.newSimpleDataTypeArray(Type.TEXT)));
sqlFuncs.add(
+ new FunctionDesc("octet_length", OctetLength.class, FunctionType.GENERAL,
+ CatalogUtil.newSimpleDataType(Type.INT4),
+ CatalogUtil.newSimpleDataTypeArray(Type.TEXT)));
+
+ sqlFuncs.add(
new FunctionDesc("substr", Substr.class, FunctionType.GENERAL,
CatalogUtil.newSimpleDataType(Type.TEXT),
CatalogUtil.newSimpleDataTypeArray(Type.TEXT, Type.INT4, Type.INT4)));
http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/19c7585c/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/function/TestStringOperatorsAndFunctions.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/function/TestStringOperatorsAndFunctions.java b/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/function/TestStringOperatorsAndFunctions.java
index c62c494..bbe6939 100644
--- a/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/function/TestStringOperatorsAndFunctions.java
+++ b/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/function/TestStringOperatorsAndFunctions.java
@@ -295,6 +295,20 @@ public class TestStringOperatorsAndFunctions extends ExprTestBase {
}
@Test
+ public void testOctetLength() throws IOException {
+ testSimpleEval("select octet_length('123456') as col1 ", new String[]{"6"});
+ testSimpleEval("select octet_length('1') as col1 ", new String[]{"1"});
+ testSimpleEval("select octet_length('가') as col1 ", new String[]{"3"});
+
+ Schema schema = new Schema();
+ schema.addColumn("col1", TEXT);
+ schema.addColumn("col2", TEXT);
+ schema.addColumn("col3", TEXT);
+ testEval(schema, "table1", "ABC,DEF,3.14", "select octet_length(lower(col1) || lower(col2)) from table1",
+ new String[]{"6"});
+ }
+
+ @Test
public void testSubstr() throws IOException {
testSimpleEval("select substr('abcdef', 3, 2) as col1 ", new String[]{"cd"});
testSimpleEval("select substr('abcdef', 3) as col1 ", new String[]{"cdef"});