You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tajo.apache.org by bl...@apache.org on 2014/03/28 07:32:12 UTC

git commit: TAJO-377: Implement concat function (Seungun Choe via jaehwa)

Repository: tajo
Updated Branches:
  refs/heads/master fc92ed5c6 -> 4e6d3cbab


TAJO-377: Implement concat function (Seungun Choe via jaehwa)


Project: http://git-wip-us.apache.org/repos/asf/tajo/repo
Commit: http://git-wip-us.apache.org/repos/asf/tajo/commit/4e6d3cba
Tree: http://git-wip-us.apache.org/repos/asf/tajo/tree/4e6d3cba
Diff: http://git-wip-us.apache.org/repos/asf/tajo/diff/4e6d3cba

Branch: refs/heads/master
Commit: 4e6d3cbab8fe714d70969d7f0e13d6c1a938547c
Parents: fc92ed5
Author: blrunner <jh...@gruter.com>
Authored: Fri Mar 28 15:32:00 2014 +0900
Committer: blrunner <jh...@gruter.com>
Committed: Fri Mar 28 15:32:00 2014 +0900

----------------------------------------------------------------------
 CHANGES.txt                                     |  2 +
 .../tajo/engine/function/string/Concat.java     | 73 ++++++++++++++++++++
 .../TestStringOperatorsAndFunctions.java        |  6 ++
 3 files changed, 81 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tajo/blob/4e6d3cba/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 3af7f5b..6a73cf1 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -4,6 +4,8 @@ Release 0.8.0 - unreleased
 
   NEW FEATURES
 
+    TAJO-377: Implement concat function (Seungun Choe via jaehwa)
+
     TAJO-30: Parquet Integration. (David Chen via hyunsik)
 
     TAJO-353: Add Database support to Tajo. (hyunsik)

http://git-wip-us.apache.org/repos/asf/tajo/blob/4e6d3cba/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/function/string/Concat.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/function/string/Concat.java b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/function/string/Concat.java
new file mode 100644
index 0000000..56b07eb
--- /dev/null
+++ b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/function/string/Concat.java
@@ -0,0 +1,73 @@
+/**
+ * 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 com.google.gson.annotations.Expose;
+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.engine.function.annotation.Description;
+import org.apache.tajo.engine.function.annotation.ParamTypes;
+import org.apache.tajo.storage.Tuple;
+
+
+/**
+ * Function definition
+ *
+ * text concat(str "any" [, str "any" [, ...] ])
+ */
+@Description(
+    functionName = "concat",
+    description = "Concatenate all arguments.",
+    detail = "Concatenate all arguments. NULL arguments are ignored.",
+    example = "> SELECT concat('abcde', '2');\n"
+        + "abcde2",
+    returnType = TajoDataTypes.Type.TEXT,
+    paramTypes = {@ParamTypes(paramTypes = {TajoDataTypes.Type.TEXT, TajoDataTypes.Type.TEXT})
+        }
+)
+public class Concat extends GeneralFunction {
+  @Expose private boolean hasMoreCharacters;
+
+  public Concat() {
+    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();
+
+    StringBuilder result = new StringBuilder(datum.asChars());
+
+    for(int i = 1 ; i < params.size() ; i++) {
+      Datum tmpDatum = params.get(i);
+      if(tmpDatum instanceof NullDatum)
+        continue;
+      result.append(tmpDatum.asChars());
+    }
+    return DatumFactory.createText(result.toString());
+  }
+}

http://git-wip-us.apache.org/repos/asf/tajo/blob/4e6d3cba/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 71d7b85..339f8ba 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
@@ -596,4 +596,10 @@ public class TestStringOperatorsAndFunctions extends ExprTestBase {
     testEval(schema, "table1", "cr|", "select find_in_set(col1, col2) is null from table1",
         new String[]{"t"}, '|', true);
   }
+
+  @Test
+  public void testConcat() throws IOException {
+    testSimpleEval("select concat('333', '22') ", new String[]{"33322"});
+    testSimpleEval("select concat('한글', '22') ", new String[]{"한글22"});
+  }
 }