tajo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jihoon...@apache.org
Subject [16/18] git commit: TAJO-358: Implement initcap(string) function. (Seungun Choe via hyunsik)
Date Tue, 03 Dec 2013 11:51:11 GMT
TAJO-358: Implement initcap(string) function. (Seungun Choe 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/3e2a2636
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tajo/tree/3e2a2636
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tajo/diff/3e2a2636

Branch: refs/heads/DAG-execplan
Commit: 3e2a2636e902137740d5e6e3510af565d8d33106
Parents: 0b0de13
Author: Hyunsik Choi <hyunsik@apache.org>
Authored: Tue Dec 3 18:41:41 2013 +0900
Committer: Hyunsik Choi <hyunsik@apache.org>
Committed: Tue Dec 3 18:41:41 2013 +0900

----------------------------------------------------------------------
 CHANGES.txt                                     |  5 +-
 .../tajo/engine/function/string/InitCap.java    | 49 ++++++++++++++++++++
 .../java/org/apache/tajo/master/TajoMaster.java |  5 ++
 .../TestStringOperatorsAndFunctions.java        |  6 +++
 4 files changed, 64 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/3e2a2636/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 8c53d9b..8dd57d6 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -4,9 +4,12 @@ Release 0.8.0 - unreleased
 
   NEW FEATURES
 
+    TAJO-358: Implement initcap(string) function. (Seungun Choe via hyunsik)
+
     TAJO-355: Implement repeat(text,int) function. (DaeMyung Kang via jaehwa)
 
-    TAJO-339: Implement sin( x ) - returns the sine of x (x is in radians). (Jae Young Lee
via jaehwa)
+    TAJO-339: Implement sin( x ) - returns the sine of x (x is in radians). 
+    (Jae Young Lee via jaehwa)
 
     TAJO-348: Implement octet_length(text). (DaeMyung Kang via jaehwa)
 

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/3e2a2636/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/function/string/InitCap.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/function/string/InitCap.java
b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/function/string/InitCap.java
new file mode 100644
index 0000000..e2158fb
--- /dev/null
+++ b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/function/string/InitCap.java
@@ -0,0 +1,49 @@
+/**
+ * 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.commons.lang.WordUtils;
+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
+ *
+ * text initcap(string text)
+ */
+public class InitCap extends GeneralFunction {
+  public InitCap() {
+    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.createText(WordUtils.capitalizeFully(datum.asChars()));
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/3e2a2636/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 58c3ef1..37ace1f 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
@@ -493,6 +493,11 @@ public class TajoMaster extends CompositeService {
             CatalogUtil.newSimpleDataType(Type.FLOAT8),
             CatalogUtil.newSimpleDataTypeArray(Type.FLOAT4)));
 
+    sqlFuncs.add(
+        new FunctionDesc("initcap", InitCap.class, FunctionType.GENERAL,
+            CatalogUtil.newSimpleDataType(Type.TEXT),
+            CatalogUtil.newSimpleDataTypeArray(Type.TEXT)));
+
     return sqlFuncs;
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/3e2a2636/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 24c658e..b65fd34 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
@@ -397,4 +397,10 @@ public class TestStringOperatorsAndFunctions extends ExprTestBase {
     testEval(schema, "table1", "ABCDEF,HIJKLMN,3.14", "select strposb(lower(col1) || lower(col2),
'fh') from table1",
         new String[]{"6"});
   }
+
+  @Test
+  public void testInitcap() throws IOException {
+    testSimpleEval("select initcap('hi bro') ", new String[]{"Hi Bro"});
+    testSimpleEval("select initcap('HI BRO') ", new String[]{"Hi Bro"});
+  }
 }


Mime
View raw message