tajo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hyun...@apache.org
Subject [1/2] TAJO-211: Implement regexp_replace function. (hyunsik)
Date Mon, 30 Sep 2013 03:34:04 GMT
Updated Branches:
  refs/heads/master 135b27a6a -> 406337d9d


http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/406337d9/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/function/string/RegexpReplace.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/function/string/RegexpReplace.java
b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/function/string/RegexpReplace.java
new file mode 100644
index 0000000..1877ba4
--- /dev/null
+++ b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/function/string/RegexpReplace.java
@@ -0,0 +1,104 @@
+/**
+ * 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.engine.function.GeneralFunction;
+import org.apache.tajo.common.TajoDataTypes;
+import org.apache.tajo.datum.*;
+import org.apache.tajo.storage.Tuple;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import static org.apache.tajo.engine.eval.FunctionEval.ParamType;
+
+/**
+ * This function is defined as:
+ * <pre>
+ * regexp_replace(string text, pattern text, replacement text [, flags text])
+ * </pre>
+ *
+ * flags is not supported yet.
+ */
+public class RegexpReplace extends GeneralFunction {
+  @Expose protected boolean isPatternConstant;
+
+  // transient variables
+  protected String pattern;
+  private boolean isAlwaysNull = false;
+  private BooleanDatum result;
+  protected Pattern compiled;
+
+  public RegexpReplace() {
+    super(new Column[] {
+        new Column("text", TajoDataTypes.Type.TEXT),
+        new Column("pattern", TajoDataTypes.Type.TEXT),
+        new Column("replacement", TajoDataTypes.Type.INT4),
+        new Column("flags", TajoDataTypes.Type.INT4), // it is not supported yet.
+    });
+  }
+
+  public void init(ParamType [] paramTypes) {
+    if (paramTypes[0] == ParamType.NULL || paramTypes[1] == ParamType.NULL || paramTypes[2]
== ParamType.NULL) {
+      isAlwaysNull = true;
+    } else if (paramTypes[1] == ParamType.CONSTANT) {
+      isPatternConstant = true;
+    }
+  }
+
+  @Override
+  public Datum eval(Tuple params) {
+    Datum thisValue = params.get(0);
+    Datum thisPattern = params.get(1);
+    Datum thisReplacement = params.get(2);
+    boolean nullResult = isAlwaysNull
+        || thisValue instanceof NullDatum
+        || thisReplacement instanceof NullDatum
+        || thisPattern instanceof NullDatum;
+
+    Pattern thisCompiled;
+    if (!nullResult) {
+      if (compiled != null) {
+        thisCompiled = compiled;
+      } else {
+        thisCompiled = Pattern.compile(thisPattern.asChars());
+
+        // if a regular expression pattern is a constant,
+        // it will be reused in every call
+        if (isPatternConstant) {
+          compiled = thisCompiled;
+        }
+      }
+
+      Matcher matcher = thisCompiled.matcher(thisValue.asChars());
+      String replacement = thisReplacement.asChars();
+      StringBuffer sb = new StringBuffer();
+      while (matcher.find()) {
+        matcher.appendReplacement(sb, replacement);
+      }
+      matcher.appendTail(sb);
+
+      return DatumFactory.createText(sb.toString());
+    } else {
+      return NullDatum.get();
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/406337d9/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/function/string/SplitPart.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/function/string/SplitPart.java
b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/function/string/SplitPart.java
index 7a37c33..505d531 100644
--- a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/function/string/SplitPart.java
+++ b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/function/string/SplitPart.java
@@ -20,12 +20,11 @@ package org.apache.tajo.engine.function.string;
 
 import org.apache.commons.lang.StringUtils;
 import org.apache.tajo.catalog.Column;
-import org.apache.tajo.catalog.function.GeneralFunction;
+import org.apache.tajo.engine.function.GeneralFunction;
 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.storage.Tuple;
 
 /**
@@ -33,7 +32,7 @@ import org.apache.tajo.storage.Tuple;
  *
  * text split_part(string text, delimiter text, field int)
  */
-public class SplitPart extends GeneralFunction<TextDatum> {
+public class SplitPart extends GeneralFunction {
   public SplitPart() {
     super(new Column[] {
         new Column("text", TajoDataTypes.Type.TEXT),

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/406337d9/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/json/CoreGsonHelper.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/json/CoreGsonHelper.java
b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/json/CoreGsonHelper.java
index a3b8ac6..784c539 100644
--- a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/json/CoreGsonHelper.java
+++ b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/json/CoreGsonHelper.java
@@ -24,9 +24,9 @@ import org.apache.hadoop.fs.Path;
 import org.apache.tajo.json.GsonObject;
 import org.apache.tajo.catalog.TableDesc;
 import org.apache.tajo.catalog.TableMeta;
-import org.apache.tajo.catalog.function.AggFunction;
+import org.apache.tajo.engine.function.AggFunction;
 import org.apache.tajo.catalog.function.Function;
-import org.apache.tajo.catalog.function.GeneralFunction;
+import org.apache.tajo.engine.function.GeneralFunction;
 import org.apache.tajo.catalog.json.FunctionAdapter;
 import org.apache.tajo.catalog.json.TableDescAdapter;
 import org.apache.tajo.catalog.json.TableMetaAdapter;

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/406337d9/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/LogicalPlan.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/LogicalPlan.java
b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/LogicalPlan.java
index 286b3b2..ebe8de5 100644
--- a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/LogicalPlan.java
+++ b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/LogicalPlan.java
@@ -715,7 +715,7 @@ public class LogicalPlan {
           groupbyNode.setTargets(getCurrentTargets());
           boolean distinct = false;
           for (Target target : groupbyNode.getTargets()) {
-            for (AggFuncCallEval aggrFunc : EvalTreeUtil.findDistinctAggFunction(target.getEvalTree()))
{
+            for (AggregationFunctionCallEval aggrFunc : EvalTreeUtil.findDistinctAggFunction(target.getEvalTree()))
{
               if (aggrFunc.isDistinct()) {
                 distinct = true;
                 break;
@@ -728,7 +728,7 @@ public class LogicalPlan {
           // if a having condition is given,
           if (hasHaving()) {
             EvalNode havingCondition = planner.createEvalTree(LogicalPlan.this, this, getHaving().getQual());
-            List<AggFuncCallEval> aggrFunctions = EvalTreeUtil.findDistinctAggFunction(havingCondition);
+            List<AggregationFunctionCallEval> aggrFunctions = EvalTreeUtil.findDistinctAggFunction(havingCondition);
 
             if (aggrFunctions.size() == 0) {
               groupbyNode.setHavingCondition(havingCondition);

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/406337d9/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/LogicalPlanner.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/LogicalPlanner.java
b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/LogicalPlanner.java
index d6b644b..eeac939 100644
--- a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/LogicalPlanner.java
+++ b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/LogicalPlanner.java
@@ -26,8 +26,8 @@ import org.apache.hadoop.fs.Path;
 import org.apache.tajo.algebra.*;
 import org.apache.tajo.algebra.CreateTable.ColumnDefinition;
 import org.apache.tajo.catalog.*;
-import org.apache.tajo.catalog.function.AggFunction;
-import org.apache.tajo.catalog.function.GeneralFunction;
+import org.apache.tajo.engine.function.AggFunction;
+import org.apache.tajo.engine.function.GeneralFunction;
 import org.apache.tajo.catalog.proto.CatalogProtos;
 import org.apache.tajo.common.TajoDataTypes;
 import org.apache.tajo.common.TajoDataTypes.DataType;
@@ -1008,7 +1008,7 @@ public class LogicalPlanner extends BaseAlgebraVisitor<LogicalPlanner.PlanContex
         try {
           block.setHasGrouping();
 
-          return new AggFuncCallEval(countRows, (AggFunction) countRows.newInstance(),
+          return new AggregationFunctionCallEval(countRows, (AggFunction) countRows.newInstance(),
               new EvalNode[] {});
         } catch (InternalException e) {
           throw new UndefinedFunctionException(CatalogUtil.
@@ -1039,7 +1039,7 @@ public class LogicalPlanner extends BaseAlgebraVisitor<LogicalPlanner.PlanContex
           block.setHasGrouping();
         }
         try {
-          return new AggFuncCallEval(funcDesc, (AggFunction) funcDesc.newInstance(), givenArgs);
+          return new AggregationFunctionCallEval(funcDesc, (AggFunction) funcDesc.newInstance(),
givenArgs);
         } catch (InternalException e) {
           e.printStackTrace();
         }
@@ -1068,12 +1068,12 @@ public class LogicalPlanner extends BaseAlgebraVisitor<LogicalPlanner.PlanContex
 
           FunctionType functionType = funcDesc.getFuncType();
           if (functionType == FunctionType.GENERAL || functionType == FunctionType.UDF) {
-            return new FuncCallEval(funcDesc, (GeneralFunction) funcDesc.newInstance(), givenArgs);
+            return new GeneralFunctionEval(funcDesc, (GeneralFunction) funcDesc.newInstance(),
givenArgs);
           } else if (functionType == FunctionType.AGGREGATION || functionType == FunctionType.UDA)
{
             if (!block.hasGroupbyNode()) {
               block.setHasGrouping();
             }
-            return new AggFuncCallEval(funcDesc, (AggFunction) funcDesc.newInstance(), givenArgs);
+            return new AggregationFunctionCallEval(funcDesc, (AggFunction) funcDesc.newInstance(),
givenArgs);
           } else if (functionType == FunctionType.DISTINCT_AGGREGATION || functionType ==
FunctionType.DISTINCT_UDA) {
             throw new PlanningException("Unsupported function: " + funcDesc.toString());
           }

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/406337d9/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/PlannerUtil.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/PlannerUtil.java
b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/PlannerUtil.java
index 8f44166..4449993 100644
--- a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/PlannerUtil.java
+++ b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/PlannerUtil.java
@@ -133,14 +133,14 @@ public class PlannerUtil {
       second = secondTargets[i];
       first = firstTargets[i];
 
-      List<AggFuncCallEval> secondStepFunctions = EvalTreeUtil.findDistinctAggFunction(second.getEvalTree());
-      List<AggFuncCallEval> firstStepFunctions = EvalTreeUtil.findDistinctAggFunction(first.getEvalTree());
+      List<AggregationFunctionCallEval> secondStepFunctions = EvalTreeUtil.findDistinctAggFunction(second.getEvalTree());
+      List<AggregationFunctionCallEval> firstStepFunctions = EvalTreeUtil.findDistinctAggFunction(first.getEvalTree());
 
       if (firstStepFunctions.size() == 0) {
         firstStepTargets.add(first);
         targetId++;
       } else {
-        for (AggFuncCallEval func : firstStepFunctions) {
+        for (AggregationFunctionCallEval func : firstStepFunctions) {
           Target newTarget;
 
           if (func.isDistinct()) {
@@ -149,8 +149,8 @@ public class PlannerUtil {
             String targetName = "column_" + (targetId++);
             newTarget.setAlias(targetName);
 
-            AggFuncCallEval secondFunc = null;
-            for (AggFuncCallEval sf : secondStepFunctions) {
+            AggregationFunctionCallEval secondFunc = null;
+            for (AggregationFunctionCallEval sf : secondStepFunctions) {
               if (func.equals(sf)) {
                 secondFunc = sf;
                 break;
@@ -165,8 +165,8 @@ public class PlannerUtil {
             String targetName = "column_" + (targetId++);
             newTarget.setAlias(targetName);
 
-            AggFuncCallEval secondFunc = null;
-            for (AggFuncCallEval sf : secondStepFunctions) {
+            AggregationFunctionCallEval secondFunc = null;
+            for (AggregationFunctionCallEval sf : secondStepFunctions) {
               if (func.equals(sf)) {
                 secondFunc = sf;
                 break;

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/406337d9/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/master/GlobalPlanner.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/master/GlobalPlanner.java
b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/master/GlobalPlanner.java
index 7ce929c..c1802b7 100644
--- a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/master/GlobalPlanner.java
+++ b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/master/GlobalPlanner.java
@@ -27,7 +27,7 @@ import org.apache.tajo.DataChannel;
 import org.apache.tajo.algebra.JoinType;
 import org.apache.tajo.catalog.*;
 import org.apache.tajo.conf.TajoConf;
-import org.apache.tajo.engine.eval.AggFuncCallEval;
+import org.apache.tajo.engine.eval.AggregationFunctionCallEval;
 import org.apache.tajo.engine.eval.EvalTreeUtil;
 import org.apache.tajo.engine.planner.*;
 import org.apache.tajo.engine.planner.global.MasterPlan;
@@ -207,8 +207,8 @@ public class GlobalPlanner {
       LinkedHashSet<Column> columnsForDistinct = new LinkedHashSet<Column>();
 
       for (Target target : groupByNode.getTargets()) {
-        List<AggFuncCallEval> functions = EvalTreeUtil.findDistinctAggFunction(target.getEvalTree());
-        for (AggFuncCallEval function : functions) {
+        List<AggregationFunctionCallEval> functions = EvalTreeUtil.findDistinctAggFunction(target.getEvalTree());
+        for (AggregationFunctionCallEval function : functions) {
           if (function.isDistinct()) {
             columnsForDistinct.addAll(EvalTreeUtil.findDistinctRefColumns(function));
           }

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/406337d9/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 ccb5ddb..0141379 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
@@ -44,6 +44,7 @@ import org.apache.tajo.conf.TajoConf.ConfVars;
 import org.apache.tajo.engine.function.Country;
 import org.apache.tajo.engine.function.InCountry;
 import org.apache.tajo.engine.function.builtin.*;
+import org.apache.tajo.engine.function.string.RegexpReplace;
 import org.apache.tajo.engine.function.string.SplitPart;
 import org.apache.tajo.master.querymaster.QueryJobManager;
 import org.apache.tajo.master.rm.WorkerResourceManager;
@@ -66,16 +67,21 @@ public class TajoMaster extends CompositeService {
   public static final int SHUTDOWN_HOOK_PRIORITY = 30;
 
   /** rw-r--r-- */
+  @SuppressWarnings("OctalInteger")
   final public static FsPermission TAJO_ROOT_DIR_PERMISSION = FsPermission.createImmutable((short)
0644);
   /** rw-r--r-- */
+  @SuppressWarnings("OctalInteger")
   final public static FsPermission SYSTEM_DIR_PERMISSION = FsPermission.createImmutable((short)
0644);
   /** rw-r--r-- */
   final public static FsPermission SYSTEM_RESOURCE_DIR_PERMISSION = FsPermission.createImmutable((short)
0644);
   /** rw-r--r-- */
+  @SuppressWarnings("OctalInteger")
   final public static FsPermission WAREHOUSE_DIR_PERMISSION = FsPermission.createImmutable((short)
0644);
   /** rw-r--r-- */
+  @SuppressWarnings("OctalInteger")
   final public static FsPermission STAGING_ROOTDIR_PERMISSION = FsPermission.createImmutable((short)
0644);
   /** rw-r--r-- */
+  @SuppressWarnings("OctalInteger")
   final public static FsPermission SYSTEM_CONF_FILE_PERMISSION = FsPermission.createImmutable((short)
0644);
 
 
@@ -308,6 +314,10 @@ public class TajoMaster extends CompositeService {
         new FunctionDesc("split_part", SplitPart.class, FunctionType.GENERAL,
             CatalogUtil.newDataTypesWithoutLen(Type.TEXT),
             CatalogUtil.newDataTypesWithoutLen(Type.TEXT, Type.TEXT, Type.INT4)));
+    sqlFuncs.add(
+        new FunctionDesc("regexp_replace", RegexpReplace.class, FunctionType.GENERAL,
+            CatalogUtil.newDataTypesWithoutLen(Type.TEXT),
+            CatalogUtil.newDataTypesWithoutLen(Type.TEXT, Type.TEXT, Type.TEXT)));
 
     return sqlFuncs;
   }

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/406337d9/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/eval/TestEvalTree.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/eval/TestEvalTree.java
b/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/eval/TestEvalTree.java
index 7d14e4c..b407f33 100644
--- a/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/eval/TestEvalTree.java
+++ b/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/eval/TestEvalTree.java
@@ -22,7 +22,7 @@ import org.apache.hadoop.fs.Path;
 import org.apache.tajo.TajoTestingCluster;
 import org.apache.tajo.algebra.Expr;
 import org.apache.tajo.catalog.*;
-import org.apache.tajo.catalog.function.GeneralFunction;
+import org.apache.tajo.engine.function.GeneralFunction;
 import org.apache.tajo.catalog.proto.CatalogProtos.FunctionType;
 import org.apache.tajo.catalog.proto.CatalogProtos.StoreType;
 import org.apache.tajo.common.TajoDataTypes.DataType;

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/406337d9/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/eval/TestEvalTreeUtil.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/eval/TestEvalTreeUtil.java
b/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/eval/TestEvalTreeUtil.java
index 079e653..7fcf190 100644
--- a/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/eval/TestEvalTreeUtil.java
+++ b/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/eval/TestEvalTreeUtil.java
@@ -308,11 +308,11 @@ public class TestEvalTreeUtil {
   public final void testFindDistinctAggFunctions() {
     String query = "select sum(score) + max(age) from people";
     Target [] targets = getRawTargets(query);
-    List<AggFuncCallEval> list = EvalTreeUtil.
+    List<AggregationFunctionCallEval> list = EvalTreeUtil.
         findDistinctAggFunction(targets[0].getEvalTree());
     assertEquals(2, list.size());
     Set<String> result = Sets.newHashSet("max", "sum");
-    for (AggFuncCallEval eval : list) {
+    for (AggregationFunctionCallEval eval : list) {
       assertTrue(result.contains(eval.getName()));
     }
   }

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/406337d9/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/function/TestAggFunction.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/function/TestAggFunction.java
b/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/function/TestAggFunction.java
index 5c290bf..f635468 100644
--- a/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/function/TestAggFunction.java
+++ b/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/function/TestAggFunction.java
@@ -19,7 +19,6 @@
 package org.apache.tajo.engine.function;
 
 import org.junit.Test;
-import org.apache.tajo.catalog.function.FunctionContext;
 import org.apache.tajo.datum.Datum;
 import org.apache.tajo.datum.DatumFactory;
 import org.apache.tajo.engine.function.builtin.AvgLong;

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/406337d9/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 6f080f0..7839c8a 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
@@ -49,4 +49,30 @@ public class TestStringOperatorsAndFunctions extends ExprTestBase {
     testEval(schema, "table1", "abc,2,3.14", "select col1 || col2 || col3 from table1", new
String[]{"abc23.14"});
     testEval(schema, "table1", "abc,2,3.14", "select col1 || '---' || col3 from table1",
new String[]{"abc---3.14"});
   }
+
+  @Test
+  public void testRegexReplace() {
+    testSimpleEval("select regexp_replace('abcdef','bc','--') as col1 ", new String[]{"a--def"});
+
+    // TODO - The following tests require the resolution of TAJO-215 (https://issues.apache.org/jira/browse/TAJO-215)
+    // null test
+    // testSimpleEval("select regexp_replace(null, 'bc', '--') as col1 ", new String[]{""});
+    // testSimpleEval("select regexp_replace('abcdef', null, '--') as col1 ", new String[]{""});
+    // testSimpleEval("select regexp_replace('abcdef','bc', null) as col1 ", new String[]{""});
+
+    Schema schema = new Schema();
+    schema.addColumn("col1", TEXT);
+    schema.addColumn("col2", TEXT);
+    schema.addColumn("col3", TEXT);
+
+    // find matches and replace from column values
+    testEval(schema, "table1", "------,(^--|--$),ab", "select regexp_replace(col1, col2,
col3) as str from table1",
+        new String[]{"ab--ab"});
+
+    // null test from a table
+    testEval(schema, "table1", ",(^--|--$),ab", "select regexp_replace(col1, col2, col3)
as str from table1",
+        new String[]{""});
+    testEval(schema, "table1", "------,(^--|--$),", "select regexp_replace(col1, col2, col3)
as str from table1",
+        new String[]{""});
+  }
 }

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/406337d9/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/planner/physical/TestPhysicalPlanner.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/planner/physical/TestPhysicalPlanner.java
b/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/planner/physical/TestPhysicalPlanner.java
index 5dac14a..50409a4 100644
--- a/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/planner/physical/TestPhysicalPlanner.java
+++ b/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/planner/physical/TestPhysicalPlanner.java
@@ -34,7 +34,7 @@ import org.apache.tajo.conf.TajoConf;
 import org.apache.tajo.datum.Datum;
 import org.apache.tajo.datum.DatumFactory;
 import org.apache.tajo.datum.NullDatum;
-import org.apache.tajo.engine.eval.AggFuncCallEval;
+import org.apache.tajo.engine.eval.AggregationFunctionCallEval;
 import org.apache.tajo.engine.eval.EvalNode;
 import org.apache.tajo.engine.eval.EvalTreeUtil;
 import org.apache.tajo.engine.parser.SQLAnalyzer;
@@ -566,8 +566,8 @@ public class TestPhysicalPlanner {
     GroupbyNode groupbyNode = PlannerUtil.findTopNode(rootNode, NodeType.GROUP_BY);
     for (Target target : groupbyNode.getTargets()) {
       for (EvalNode eval : EvalTreeUtil.findDistinctAggFunction(target.getEvalTree())) {
-        if (eval instanceof AggFuncCallEval) {
-          ((AggFuncCallEval) eval).setFirstPhase();
+        if (eval instanceof AggregationFunctionCallEval) {
+          ((AggregationFunctionCallEval) eval).setFirstPhase();
         }
       }
     }
@@ -601,8 +601,8 @@ public class TestPhysicalPlanner {
     GroupbyNode groupbyNode = (GroupbyNode) PlannerUtil.findTopNode(rootNode, NodeType.GROUP_BY);
     for (Target target : groupbyNode.getTargets()) {
       for (EvalNode eval : EvalTreeUtil.findDistinctAggFunction(target.getEvalTree())) {
-        if (eval instanceof AggFuncCallEval) {
-          ((AggFuncCallEval) eval).setFirstPhase();
+        if (eval instanceof AggregationFunctionCallEval) {
+          ((AggregationFunctionCallEval) eval).setFirstPhase();
         }
       }
     }

http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/406337d9/tajo-core/tajo-core-storage/src/main/java/org/apache/tajo/storage/json/StorageGsonHelper.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-storage/src/main/java/org/apache/tajo/storage/json/StorageGsonHelper.java
b/tajo-core/tajo-core-storage/src/main/java/org/apache/tajo/storage/json/StorageGsonHelper.java
index 71ed339..c95bc73 100644
--- a/tajo-core/tajo-core-storage/src/main/java/org/apache/tajo/storage/json/StorageGsonHelper.java
+++ b/tajo-core/tajo-core-storage/src/main/java/org/apache/tajo/storage/json/StorageGsonHelper.java
@@ -26,10 +26,6 @@ import com.google.gson.GsonBuilder;
 import org.apache.hadoop.fs.Path;
 import org.apache.tajo.catalog.TableDesc;
 import org.apache.tajo.catalog.TableMeta;
-import org.apache.tajo.catalog.function.AggFunction;
-import org.apache.tajo.catalog.function.Function;
-import org.apache.tajo.catalog.function.GeneralFunction;
-import org.apache.tajo.catalog.json.FunctionAdapter;
 import org.apache.tajo.catalog.json.TableDescAdapter;
 import org.apache.tajo.catalog.json.TableMetaAdapter;
 import org.apache.tajo.datum.Datum;
@@ -52,9 +48,6 @@ public class StorageGsonHelper {
     adapters.put(TableDesc.class, new TableDescAdapter());
     adapters.put(Class.class, new ClassNameSerializer());
     adapters.put(TableMeta.class, new TableMetaAdapter());
-    adapters.put(Function.class, new FunctionAdapter());
-    adapters.put(GeneralFunction.class, new FunctionAdapter());
-    adapters.put(AggFunction.class, new FunctionAdapter());
     adapters.put(Datum.class, new DatumAdapter());
     return adapters;
   }


Mime
View raw message