tajo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jihoon...@apache.org
Subject [5/9] git commit: TAJO-956: CONCAT should be support multiple params and null param. (Hyoungjun Kim via hyunsik)
Date Mon, 21 Jul 2014 01:02:12 GMT
 TAJO-956: CONCAT should be support multiple params and null param. (Hyoungjun Kim via hyunsik)

 Closes #81


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

Branch: refs/heads/index_support
Commit: 06935b392ce40264ae41e6486e5737f8c5c0593b
Parents: 4d0b445
Author: Hyunsik Choi <hyunsik@apache.org>
Authored: Sun Jul 20 21:33:38 2014 +0900
Committer: Hyunsik Choi <hyunsik@apache.org>
Committed: Sun Jul 20 21:33:38 2014 +0900

----------------------------------------------------------------------
 CHANGES                                         |  3 +++
 .../tajo/engine/function/string/Concat.java     | 16 ++++---------
 .../tajo/engine/function/string/Concat_ws.java  | 25 +++++++++++---------
 .../TestStringOperatorsAndFunctions.java        |  6 +++++
 4 files changed, 28 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tajo/blob/06935b39/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index a67ded8..502dd25 100644
--- a/CHANGES
+++ b/CHANGES
@@ -29,6 +29,9 @@ Release 0.9.0 - unreleased
 
   IMPROVEMENT
 
+    TAJO-956: CONCAT should be support multiple params and null param.
+    (Hyoungjun Kim via hyunsik)
+
     TAJO-953: RawFile should release a DirectBuffer immediately. (jinho)
 
     TAJO-933: Fork some classes of Parquet as builtin third-party classes.

http://git-wip-us.apache.org/repos/asf/tajo/blob/06935b39/tajo-core/src/main/java/org/apache/tajo/engine/function/string/Concat.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/function/string/Concat.java b/tajo-core/src/main/java/org/apache/tajo/engine/function/string/Concat.java
index 56b07eb..50b1440 100644
--- a/tajo-core/src/main/java/org/apache/tajo/engine/function/string/Concat.java
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/function/string/Concat.java
@@ -18,7 +18,6 @@
 
 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;
@@ -42,12 +41,10 @@ import org.apache.tajo.storage.Tuple;
     example = "> SELECT concat('abcde', '2');\n"
         + "abcde2",
     returnType = TajoDataTypes.Type.TEXT,
-    paramTypes = {@ParamTypes(paramTypes = {TajoDataTypes.Type.TEXT, TajoDataTypes.Type.TEXT})
-        }
+    paramTypes = {@ParamTypes(paramTypes = {TajoDataTypes.Type.TEXT, TajoDataTypes.Type.TEXT_ARRAY})
+    }
 )
 public class Concat extends GeneralFunction {
-  @Expose private boolean hasMoreCharacters;
-
   public Concat() {
     super(new Column[] {
         new Column("text", TajoDataTypes.Type.TEXT),
@@ -56,13 +53,10 @@ public class Concat extends GeneralFunction {
 
   @Override
   public Datum eval(Tuple params) {
-    Datum datum = params.get(0);
-
-    if(datum instanceof NullDatum) return NullDatum.get();
-
-    StringBuilder result = new StringBuilder(datum.asChars());
+    StringBuilder result = new StringBuilder();
 
-    for(int i = 1 ; i < params.size() ; i++) {
+    int paramSize = params.size();
+    for(int i = 0 ; i < paramSize; i++) {
       Datum tmpDatum = params.get(i);
       if(tmpDatum instanceof NullDatum)
         continue;

http://git-wip-us.apache.org/repos/asf/tajo/blob/06935b39/tajo-core/src/main/java/org/apache/tajo/engine/function/string/Concat_ws.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/function/string/Concat_ws.java
b/tajo-core/src/main/java/org/apache/tajo/engine/function/string/Concat_ws.java
index dd48151..d8e2113 100644
--- a/tajo-core/src/main/java/org/apache/tajo/engine/function/string/Concat_ws.java
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/function/string/Concat_ws.java
@@ -24,6 +24,7 @@ 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.datum.TextDatum;
 import org.apache.tajo.engine.function.GeneralFunction;
 import org.apache.tajo.engine.function.annotation.Description;
 import org.apache.tajo.engine.function.annotation.ParamTypes;
@@ -32,7 +33,7 @@ import org.apache.tajo.storage.Tuple;
 /**
  * Function definition
  *
- * text concat(str "any" [, str "any" [, ...] ])
+ * text concat_ws(sep text, str "any" [, str "any" [, ...] ])
  */
 @Description(
     functionName = "concat_ws",
@@ -41,7 +42,7 @@ import org.apache.tajo.storage.Tuple;
     example = "> concat_ws(',', 'abcde', 2);\n"
         + "abcde,2",
     returnType = TajoDataTypes.Type.TEXT,
-    paramTypes = {@ParamTypes(paramTypes = {TajoDataTypes.Type.TEXT, TajoDataTypes.Type.TEXT,
TajoDataTypes.Type.TEXT})}
+    paramTypes = {@ParamTypes(paramTypes = {TajoDataTypes.Type.TEXT, TajoDataTypes.Type.TEXT,
TajoDataTypes.Type.TEXT_ARRAY})}
 )
 public class Concat_ws extends GeneralFunction {
   @Expose private boolean hasMoreCharacters;
@@ -57,21 +58,23 @@ public class Concat_ws extends GeneralFunction {
   @Override
   public Datum eval(Tuple params) {
     Datum sepDatum = params.get(0);
-    Datum datum = params.get(1);
 
-
-    if(datum instanceof NullDatum) return NullDatum.get();
     if(sepDatum instanceof NullDatum) return NullDatum.get();
 
-    StringBuilder result = new StringBuilder(datum.asChars());
+    String seperator = ((TextDatum)sepDatum).asChars();
 
+    String opSperator = "";
+    StringBuilder result = new StringBuilder();
 
-    for(int i = 2 ; i < params.size() ; i++) {
-      Datum tmpDatum = params.get(i);
-      if(tmpDatum instanceof NullDatum)
+    int paramSize = params.size();
+    for(int i = 1; i < paramSize; i++) {
+      Datum datum = params.get(i);
+      if(datum instanceof NullDatum) {
         continue;
-      result.append(sepDatum.asChars());
-      result.append(tmpDatum.asChars());
+      } else {
+        result.append(opSperator).append(datum.asChars());
+      }
+      opSperator = seperator;
     }
     return DatumFactory.createText(result.toString());
   }

http://git-wip-us.apache.org/repos/asf/tajo/blob/06935b39/tajo-core/src/test/java/org/apache/tajo/engine/function/TestStringOperatorsAndFunctions.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/java/org/apache/tajo/engine/function/TestStringOperatorsAndFunctions.java
b/tajo-core/src/test/java/org/apache/tajo/engine/function/TestStringOperatorsAndFunctions.java
index fa13011..7f402a1 100644
--- a/tajo-core/src/test/java/org/apache/tajo/engine/function/TestStringOperatorsAndFunctions.java
+++ b/tajo-core/src/test/java/org/apache/tajo/engine/function/TestStringOperatorsAndFunctions.java
@@ -600,11 +600,17 @@ public class TestStringOperatorsAndFunctions extends ExprTestBase {
   public void testConcat() throws IOException {
     testSimpleEval("select concat('333', '22') ", new String[]{"33322"});
     testSimpleEval("select concat('한글', '22') ", new String[]{"한글22"});
+    testSimpleEval("select concat(null, '22') ", new String[]{"22"});
+    testSimpleEval("select concat('22',null) ", new String[]{"22"});
+    testSimpleEval("select concat('22',null, '33', null, '44') ", new String[]{"223344"});
   }
 
   @Test
   public void testConcat_ws() throws IOException {
     testSimpleEval("select concat_ws(',', '333', '22') ", new String[]{"333,22"});
     testSimpleEval("select concat_ws(',', '한글', '22') ", new String[]{"한글,22"});
+    testSimpleEval("select concat_ws(',', '22', null) ", new String[]{"22"});
+    testSimpleEval("select concat_ws(',', '22', '33', '33') ", new String[]{"22,33,33"});
+    testSimpleEval("select concat_ws(',', null, '22') ", new String[]{"22"});
   }
 }


Mime
View raw message