You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by th...@apache.org on 2014/10/10 20:57:49 UTC

svn commit: r1630957 - in /hive/trunk/ql/src: java/org/apache/hadoop/hive/ql/exec/ java/org/apache/hadoop/hive/ql/parse/ java/org/apache/hadoop/hive/ql/plan/ test/queries/clientpositive/ test/results/clientpositive/

Author: thejas
Date: Fri Oct 10 18:57:49 2014
New Revision: 1630957

URL: http://svn.apache.org/r1630957
Log:
HIVE-8094 : add LIKE keyword support for SHOW FUNCTIONS (peter liu via Thejas Nair)

Modified:
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/DDLTask.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/HiveParser.g
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/plan/ShowFunctionsDesc.java
    hive/trunk/ql/src/test/queries/clientpositive/show_functions.q
    hive/trunk/ql/src/test/results/clientpositive/show_functions.q.out

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/DDLTask.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/DDLTask.java?rev=1630957&r1=1630956&r2=1630957&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/DDLTask.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/DDLTask.java Fri Oct 10 18:57:49 2014
@@ -2278,7 +2278,12 @@ public class DDLTask extends Task<DDLWor
     Set<String> funcs = null;
     if (showFuncs.getPattern() != null) {
       LOG.info("pattern: " + showFuncs.getPattern());
-      funcs = FunctionRegistry.getFunctionNames(showFuncs.getPattern());
+      if (showFuncs.getIsLikePattern()) {
+         funcs = FunctionRegistry.getFunctionNamesByLikePattern(showFuncs.getPattern());
+      } else {
+         console.printInfo("SHOW FUNCTIONS is deprecated, please use SHOW FUNCTIONS LIKE instead.");
+         funcs = FunctionRegistry.getFunctionNames(showFuncs.getPattern());
+      }
       LOG.info("results : " + funcs.size());
     } else {
       funcs = FunctionRegistry.getFunctionNames();

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java?rev=1630957&r1=1630956&r2=1630957&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java Fri Oct 10 18:57:49 2014
@@ -732,6 +732,34 @@ public final class FunctionRegistry {
   }
 
   /**
+   * Returns a set of registered function names which matchs the given pattern.
+   * This is used for the CLI command "SHOW FUNCTIONS LIKE 'regular expression';"
+   *
+   * @param funcPatternStr
+   *          regular expression of the interested function names
+   * @return set of strings contains function names
+   */
+  public static Set<String> getFunctionNamesByLikePattern(String funcPatternStr) {
+    Set<String> funcNames = new TreeSet<String>();
+    Set<String> allFuncs = getFunctionNames(true);
+    String[] subpatterns = funcPatternStr.trim().split("\\|");
+    for (String subpattern : subpatterns) {
+      subpattern = "(?i)" + subpattern.replaceAll("\\*", ".*");
+      try {
+        Pattern patternObj = Pattern.compile(subpattern);
+        for (String funcName : allFuncs) {
+          if (patternObj.matcher(funcName).matches()) {
+            funcNames.add(funcName);
+          }
+        }
+      } catch (PatternSyntaxException e) {
+        continue;
+      }
+    }
+    return funcNames;
+  }
+
+  /**
    * Returns the set of synonyms of the supplied function.
    *
    * @param funcName

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java?rev=1630957&r1=1630956&r2=1630957&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java Fri Oct 10 18:57:49 2014
@@ -2240,6 +2240,10 @@ public class DDLSemanticAnalyzer extends
     if (ast.getChildCount() == 1) {
       String funcNames = stripQuotes(ast.getChild(0).getText());
       showFuncsDesc = new ShowFunctionsDesc(ctx.getResFile(), funcNames);
+    } else if (ast.getChildCount() == 2) {
+      assert (ast.getChild(0).getType() == HiveParser.KW_LIKE);
+      String funcNames = stripQuotes(ast.getChild(1).getText());
+      showFuncsDesc = new ShowFunctionsDesc(ctx.getResFile(), funcNames, true);
     } else {
       showFuncsDesc = new ShowFunctionsDesc(ctx.getResFile());
     }

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/HiveParser.g
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/HiveParser.g?rev=1630957&r1=1630956&r2=1630957&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/HiveParser.g (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/HiveParser.g Fri Oct 10 18:57:49 2014
@@ -1334,7 +1334,7 @@ showStatement
     | KW_SHOW KW_TABLES ((KW_FROM|KW_IN) db_name=identifier)? (KW_LIKE showStmtIdentifier|showStmtIdentifier)?  -> ^(TOK_SHOWTABLES (TOK_FROM $db_name)? showStmtIdentifier?)
     | KW_SHOW KW_COLUMNS (KW_FROM|KW_IN) tableName ((KW_FROM|KW_IN) db_name=identifier)?
     -> ^(TOK_SHOWCOLUMNS tableName $db_name?)
-    | KW_SHOW KW_FUNCTIONS showFunctionIdentifier?  -> ^(TOK_SHOWFUNCTIONS showFunctionIdentifier?)
+    | KW_SHOW KW_FUNCTIONS (KW_LIKE showFunctionIdentifier|showFunctionIdentifier)?  -> ^(TOK_SHOWFUNCTIONS KW_LIKE? showFunctionIdentifier?)
     | KW_SHOW KW_PARTITIONS tabName=tableName partitionSpec? -> ^(TOK_SHOWPARTITIONS $tabName partitionSpec?) 
     | KW_SHOW KW_CREATE KW_TABLE tabName=tableName -> ^(TOK_SHOW_CREATETABLE $tabName)
     | KW_SHOW KW_TABLE KW_EXTENDED ((KW_FROM|KW_IN) db_name=identifier)? KW_LIKE showStmtIdentifier partitionSpec?

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/plan/ShowFunctionsDesc.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/plan/ShowFunctionsDesc.java?rev=1630957&r1=1630956&r2=1630957&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/plan/ShowFunctionsDesc.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/plan/ShowFunctionsDesc.java Fri Oct 10 18:57:49 2014
@@ -32,6 +32,10 @@ public class ShowFunctionsDesc extends D
   String pattern;
   String resFile;
   /**
+   * whether like keyword is specified
+   */
+  private boolean isLikePattern = false;
+  /**
    * table name for the result of show tables.
    */
   private static final String table = "show";
@@ -69,6 +73,18 @@ public class ShowFunctionsDesc extends D
   }
 
   /**
+   * @param pattern
+   *          names of tables to show
+   * @param like
+   *          is like keyword used
+   */
+  public ShowFunctionsDesc(Path resFile, String pattern, boolean isLikePattern) {
+    this(resFile, pattern);
+    this.isLikePattern = isLikePattern;
+  }
+
+
+  /**
    * @return the pattern
    */
   @Explain(displayName = "pattern")
@@ -99,4 +115,11 @@ public class ShowFunctionsDesc extends D
   public void setResFile(String resFile) {
     this.resFile = resFile;
   }
+
+  /**
+   * @return isLikePattern
+   */
+  public boolean getIsLikePattern() {
+    return isLikePattern;
+  }
 }

Modified: hive/trunk/ql/src/test/queries/clientpositive/show_functions.q
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/queries/clientpositive/show_functions.q?rev=1630957&r1=1630956&r2=1630957&view=diff
==============================================================================
--- hive/trunk/ql/src/test/queries/clientpositive/show_functions.q (original)
+++ hive/trunk/ql/src/test/queries/clientpositive/show_functions.q Fri Oct 10 18:57:49 2014
@@ -9,3 +9,23 @@ SHOW FUNCTIONS 'log.*';
 SHOW FUNCTIONS '.*date.*';
 
 SHOW FUNCTIONS '***';
+
+SHOW FUNCTIONS LIKE 'When';
+
+SHOW FUNCTIONS LIKE 'max|min';
+
+SHOW FUNCTIONS LIKE 'xpath*|m*';
+
+SHOW FUNCTIONS LIKE 'nomatch';
+
+SHOW FUNCTIONS LIKE "log";
+
+SHOW FUNCTIONS LIKE 'log';
+
+SHOW FUNCTIONS LIKE `log`;
+
+SHOW FUNCTIONS LIKE 'log*';
+
+SHOW FUNCTIONS LIKE "log*";
+
+SHOW FUNCTIONS LIKE `log*`;

Modified: hive/trunk/ql/src/test/results/clientpositive/show_functions.q.out
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/results/clientpositive/show_functions.q.out?rev=1630957&r1=1630956&r2=1630957&view=diff
==============================================================================
--- hive/trunk/ql/src/test/results/clientpositive/show_functions.q.out (original)
+++ hive/trunk/ql/src/test/results/clientpositive/show_functions.q.out Fri Oct 10 18:57:49 2014
@@ -280,3 +280,75 @@ PREHOOK: query: SHOW FUNCTIONS '***'
 PREHOOK: type: SHOWFUNCTIONS
 POSTHOOK: query: SHOW FUNCTIONS '***'
 POSTHOOK: type: SHOWFUNCTIONS
+PREHOOK: query: SHOW FUNCTIONS LIKE 'When'
+PREHOOK: type: SHOWFUNCTIONS
+POSTHOOK: query: SHOW FUNCTIONS LIKE 'When'
+POSTHOOK: type: SHOWFUNCTIONS
+when
+PREHOOK: query: SHOW FUNCTIONS LIKE 'max|min'
+PREHOOK: type: SHOWFUNCTIONS
+POSTHOOK: query: SHOW FUNCTIONS LIKE 'max|min'
+POSTHOOK: type: SHOWFUNCTIONS
+max
+min
+PREHOOK: query: SHOW FUNCTIONS LIKE 'xpath*|m*'
+PREHOOK: type: SHOWFUNCTIONS
+POSTHOOK: query: SHOW FUNCTIONS LIKE 'xpath*|m*'
+POSTHOOK: type: SHOWFUNCTIONS
+map
+map_keys
+map_values
+matchpath
+max
+min
+minute
+month
+xpath
+xpath_boolean
+xpath_double
+xpath_float
+xpath_int
+xpath_long
+xpath_number
+xpath_short
+xpath_string
+PREHOOK: query: SHOW FUNCTIONS LIKE 'nomatch'
+PREHOOK: type: SHOWFUNCTIONS
+POSTHOOK: query: SHOW FUNCTIONS LIKE 'nomatch'
+POSTHOOK: type: SHOWFUNCTIONS
+PREHOOK: query: SHOW FUNCTIONS LIKE "log"
+PREHOOK: type: SHOWFUNCTIONS
+POSTHOOK: query: SHOW FUNCTIONS LIKE "log"
+POSTHOOK: type: SHOWFUNCTIONS
+log
+PREHOOK: query: SHOW FUNCTIONS LIKE 'log'
+PREHOOK: type: SHOWFUNCTIONS
+POSTHOOK: query: SHOW FUNCTIONS LIKE 'log'
+POSTHOOK: type: SHOWFUNCTIONS
+log
+PREHOOK: query: SHOW FUNCTIONS LIKE `log`
+PREHOOK: type: SHOWFUNCTIONS
+POSTHOOK: query: SHOW FUNCTIONS LIKE `log`
+POSTHOOK: type: SHOWFUNCTIONS
+log
+PREHOOK: query: SHOW FUNCTIONS LIKE 'log*'
+PREHOOK: type: SHOWFUNCTIONS
+POSTHOOK: query: SHOW FUNCTIONS LIKE 'log*'
+POSTHOOK: type: SHOWFUNCTIONS
+log
+log10
+log2
+PREHOOK: query: SHOW FUNCTIONS LIKE "log*"
+PREHOOK: type: SHOWFUNCTIONS
+POSTHOOK: query: SHOW FUNCTIONS LIKE "log*"
+POSTHOOK: type: SHOWFUNCTIONS
+log
+log10
+log2
+PREHOOK: query: SHOW FUNCTIONS LIKE `log*`
+PREHOOK: type: SHOWFUNCTIONS
+POSTHOOK: query: SHOW FUNCTIONS LIKE `log*`
+POSTHOOK: type: SHOWFUNCTIONS
+log
+log10
+log2