tajo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jihoon...@apache.org
Subject [06/14] tajo git commit: TAJO-1452: Improve function listing order (Contributed Dongjoon Hyun, Committed by hyunsik)
Date Tue, 12 May 2015 03:14:05 GMT
TAJO-1452: Improve function listing order (Contributed Dongjoon Hyun, Committed by hyunsik)

Closes #470


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

Branch: refs/heads/index_support
Commit: 1baf8dce6521fcab041c2e94b1ba5eb016611bb2
Parents: e6e1860
Author: Hyunsik Choi <hyunsik@apache.org>
Authored: Fri May 8 00:52:09 2015 -0700
Committer: Hyunsik Choi <hyunsik@apache.org>
Committed: Fri May 8 00:52:09 2015 -0700

----------------------------------------------------------------------
 CHANGES                                         |  3 ++
 .../apache/tajo/function/FunctionSignature.java | 10 ++++-
 .../org/apache/tajo/function/FunctionUtil.java  | 39 ++++++++++++++++++++
 .../cli/tsql/commands/DescFunctionCommand.java  | 18 ++-------
 .../main/java/org/apache/tajo/util/JSPUtil.java | 14 -------
 .../main/resources/webapps/admin/functions.jsp  |  3 +-
 6 files changed, 55 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tajo/blob/1baf8dce/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index 15fc494..9788307 100644
--- a/CHANGES
+++ b/CHANGES
@@ -24,6 +24,9 @@ Release 0.11.0 - unreleased
 
   IMPROVEMENT
 
+    TAJO-1452: Improve function listing order (Contributed Dongjoon Hyun, 
+    Committed by hyunsik)
+
     TAJO-1576: Sometimes DefaultTajoCliOutputFormatter.parseErrorMessage() eliminates 
     an important kind of information. 
     (Contributed by Jongyoung Park, Committed by jihoon)

http://git-wip-us.apache.org/repos/asf/tajo/blob/1baf8dce/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/function/FunctionSignature.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/function/FunctionSignature.java
b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/function/FunctionSignature.java
index fc3a056..89ee017 100644
--- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/function/FunctionSignature.java
+++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/function/FunctionSignature.java
@@ -122,14 +122,20 @@ public class FunctionSignature implements Comparable<FunctionSignature>,
ProtoOb
       return cmpVal;
     }
 
-    cmpVal = returnType.getType().compareTo(o.returnType.getType());
+    cmpVal = functionType.name().compareTo(o.functionType.name());
+
+    if (cmpVal != 0) {
+      return cmpVal;
+    }
+
+    cmpVal = returnType.getType().name().compareTo(o.returnType.getType().name());
 
     if (cmpVal != 0) {
       return cmpVal;
     }
 
     for (int i = 0; i < Math.min(paramTypes.length, o.paramTypes.length); i++) {
-      cmpVal = paramTypes[i].getType().compareTo(o.paramTypes[i].getType());
+      cmpVal = paramTypes[i].getType().name().compareTo(o.paramTypes[i].getType().name());
 
       if (cmpVal != 0) {
         return cmpVal;

http://git-wip-us.apache.org/repos/asf/tajo/blob/1baf8dce/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/function/FunctionUtil.java
----------------------------------------------------------------------
diff --git a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/function/FunctionUtil.java
b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/function/FunctionUtil.java
index ef70428..713961f 100644
--- a/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/function/FunctionUtil.java
+++ b/tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/function/FunctionUtil.java
@@ -19,13 +19,52 @@
 package org.apache.tajo.function;
 
 import org.apache.tajo.catalog.FunctionDesc;
+import org.apache.tajo.catalog.proto.CatalogProtos;
 
 import java.util.Collection;
+import java.util.Comparator;
 
 import static org.apache.tajo.common.TajoDataTypes.DataType;
 
 public class FunctionUtil {
 
+  public static class FunctionDescProtoComparator implements Comparator<CatalogProtos.FunctionDescProto>
+  {
+    @Override
+    public int compare(CatalogProtos.FunctionDescProto f1, CatalogProtos.FunctionDescProto
f2) {
+      CatalogProtos.FunctionSignatureProto s1 = f1.getSignature();
+      CatalogProtos.FunctionSignatureProto s2 = f2.getSignature();
+
+      int cmpVal = s1.getName().compareTo(s2.getName());
+
+      if (cmpVal != 0) {
+        return cmpVal;
+      }
+
+      cmpVal = s1.getType().name().compareTo(s2.getType().name());
+
+      if (cmpVal != 0) {
+        return cmpVal;
+      }
+
+      cmpVal = s1.getReturnType().getType().name().compareTo(s2.getReturnType().getType().name());
+
+      if (cmpVal != 0) {
+        return cmpVal;
+      }
+
+      for (int i = 0; i < Math.min(s1.getParameterTypesCount(), s2.getParameterTypesCount());
i++) {
+        cmpVal = s1.getParameterTypes(i).getType().name().compareTo(s2.getParameterTypes(i).getType().name());
+
+        if (cmpVal != 0) {
+          return cmpVal;
+        }
+      }
+
+      return s2.getParameterTypesCount() - s1.getParameterTypesCount();
+    }
+  }
+
   public static String buildFQFunctionSignature(String funcName, DataType returnType, DataType...
paramTypes) {
     return returnType.getType().name().toLowerCase() + " " + buildSimpleFunctionSignature(funcName,
paramTypes);
   }

http://git-wip-us.apache.org/repos/asf/tajo/blob/1baf8dce/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/DescFunctionCommand.java
----------------------------------------------------------------------
diff --git a/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/DescFunctionCommand.java
b/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/DescFunctionCommand.java
index 295d326..abdbb9c 100644
--- a/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/DescFunctionCommand.java
+++ b/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/commands/DescFunctionCommand.java
@@ -52,17 +52,7 @@ public class DescFunctionCommand extends TajoShellCommand {
     List<CatalogProtos.FunctionDescProto> functions =
         new ArrayList<CatalogProtos.FunctionDescProto>(client.getFunctions(functionName));
 
-    Collections.sort(functions, new Comparator<CatalogProtos.FunctionDescProto>() {
-      @Override
-      public int compare(CatalogProtos.FunctionDescProto f1, CatalogProtos.FunctionDescProto
f2) {
-        int nameCompared = f1.getSignature().getName().compareTo(f2.getSignature().getName());
-        if (nameCompared != 0) {
-          return nameCompared;
-        } else {
-          return f1.getSignature().getReturnType().getType().compareTo(f2.getSignature().getReturnType().getType());
-        }
-      }
-    });
+    Collections.sort(functions, new FunctionUtil.FunctionDescProtoComparator());
 
     String[] headers = new String[]{"Name", "Result type", "Argument types", "Description",
"Type"};
     float[] columnWidthRates = new float[]{0.15f, 0.15f, 0.2f, 0.4f, 0.1f};
@@ -70,12 +60,12 @@ public class DescFunctionCommand extends TajoShellCommand {
 
     for(CatalogProtos.FunctionDescProto eachFunction: functions) {
       String name = eachFunction.getSignature().getName();
-      String resultDataType = eachFunction.getSignature().getReturnType().getType().toString();
+      String resultDataType = eachFunction.getSignature().getReturnType().getType().toString().toLowerCase();
       String arguments = FunctionUtil.buildParamTypeString(
           eachFunction.getSignature().getParameterTypesList().toArray(
               new DataType[eachFunction.getSignature().getParameterTypesCount()]));
-      String functionType = eachFunction.getSignature().getType().toString();
-      String description = eachFunction.getSupplement().getShortDescription();
+      String functionType = eachFunction.getSignature().getType().toString().toLowerCase();
+      String description = eachFunction.getSupplement().getShortDescription().trim();
 
       int index = 0;
       printLeft(" " + name, columnWidths[index++]);

http://git-wip-us.apache.org/repos/asf/tajo/blob/1baf8dce/tajo-core/src/main/java/org/apache/tajo/util/JSPUtil.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/util/JSPUtil.java b/tajo-core/src/main/java/org/apache/tajo/util/JSPUtil.java
index 875d12b..aee2ced 100644
--- a/tajo-core/src/main/java/org/apache/tajo/util/JSPUtil.java
+++ b/tajo-core/src/main/java/org/apache/tajo/util/JSPUtil.java
@@ -311,20 +311,6 @@ public class JSPUtil {
     }
   }
 
-  public static void sortFunctionDesc(List<FunctionDesc> functions) {
-    Collections.sort(functions, new java.util.Comparator<FunctionDesc>() {
-      @Override
-      public int compare(FunctionDesc f1, FunctionDesc f2) {
-        int nameCompared = f1.getFunctionName().compareTo(f2.getFunctionName());
-        if(nameCompared != 0) {
-          return nameCompared;
-        } else {
-          return f1.getReturnType().getType().compareTo(f2.getReturnType().getType());
-        }
-      }
-    });
-  }
-
   static final DecimalFormat PERCENT_FORMAT = new DecimalFormat("###.#");
   public static String percentFormat(float value) {
     return PERCENT_FORMAT.format(value * 100.0f);

http://git-wip-us.apache.org/repos/asf/tajo/blob/1baf8dce/tajo-core/src/main/resources/webapps/admin/functions.jsp
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/resources/webapps/admin/functions.jsp b/tajo-core/src/main/resources/webapps/admin/functions.jsp
index c805aaa..cf3ddc5 100644
--- a/tajo-core/src/main/resources/webapps/admin/functions.jsp
+++ b/tajo-core/src/main/resources/webapps/admin/functions.jsp
@@ -24,13 +24,12 @@
 <%@ page import="org.apache.tajo.master.*" %>
 <%@ page import="org.apache.tajo.catalog.*" %>
 <%@ page import="org.apache.hadoop.http.HtmlQuoting" %>
-<%@ page import="org.apache.tajo.util.JSPUtil" %>
 <%
     TajoMaster master = (TajoMaster) StaticHttpServer.getInstance().getAttribute("tajo.info.server.object");
     CatalogService catalog = master.getCatalog();
 
     List<FunctionDesc> functions = new ArrayList<FunctionDesc>(catalog.getFunctions());
-    JSPUtil.sortFunctionDesc(functions);
+    Collections.sort(functions);
 %>
 
 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">


Mime
View raw message