hive-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amareshw...@apache.org
Subject svn commit: r1481773 - in /hive/branches/HIVE-4115/ql/src/java/org/apache/hadoop/hive/ql/cube/parse: AliasReplacer.java CubeQueryContext.java HQLParser.java
Date Mon, 13 May 2013 10:16:02 GMT
Author: amareshwari
Date: Mon May 13 10:16:02 2013
New Revision: 1481773

URL: http://svn.apache.org/r1481773
Log:
Fix aggregate expressions in alias replacer

Modified:
    hive/branches/HIVE-4115/ql/src/java/org/apache/hadoop/hive/ql/cube/parse/AliasReplacer.java
    hive/branches/HIVE-4115/ql/src/java/org/apache/hadoop/hive/ql/cube/parse/CubeQueryContext.java
    hive/branches/HIVE-4115/ql/src/java/org/apache/hadoop/hive/ql/cube/parse/HQLParser.java

Modified: hive/branches/HIVE-4115/ql/src/java/org/apache/hadoop/hive/ql/cube/parse/AliasReplacer.java
URL: http://svn.apache.org/viewvc/hive/branches/HIVE-4115/ql/src/java/org/apache/hadoop/hive/ql/cube/parse/AliasReplacer.java?rev=1481773&r1=1481772&r2=1481773&view=diff
==============================================================================
--- hive/branches/HIVE-4115/ql/src/java/org/apache/hadoop/hive/ql/cube/parse/AliasReplacer.java
(original)
+++ hive/branches/HIVE-4115/ql/src/java/org/apache/hadoop/hive/ql/cube/parse/AliasReplacer.java
Mon May 13 10:16:02 2013
@@ -67,6 +67,12 @@ public class AliasReplacer implements Co
     if (StringUtils.isNotBlank(rewritWhere)) {
       cubeql.setWhereTree(rewritWhere);
     }
+
+    // Update the aggregate expression set
+    System.out.println("AggrSet Before:" + cubeql.aggregateExprs.toString());
+    updateAggregates(selectAST, cubeql);
+    updateAggregates(havingAST, cubeql);
+    System.out.println("AggrSet After:" + cubeql.aggregateExprs.toString());
   }
 
   private void replaceAliases(ASTNode node, int nodePos, Map<String, String> colToTableAlias)
{
@@ -118,4 +124,19 @@ public class AliasReplacer implements Co
     }
   }
 
+  private void updateAggregates(ASTNode root, CubeQueryContext cubeql) {
+    if (root == null) {
+      return;
+    }
+
+    if (HQLParser.isAggregateAST(root)) {
+      cubeql.addAggregateExpr(HQLParser.getString(root).trim().toLowerCase());
+    } else {
+      for (int i = 0; i < root.getChildCount(); i++) {
+        ASTNode child = (ASTNode) root.getChild(i);
+        updateAggregates(child, cubeql);
+      }
+    }
+  }
+
 }

Modified: hive/branches/HIVE-4115/ql/src/java/org/apache/hadoop/hive/ql/cube/parse/CubeQueryContext.java
URL: http://svn.apache.org/viewvc/hive/branches/HIVE-4115/ql/src/java/org/apache/hadoop/hive/ql/cube/parse/CubeQueryContext.java?rev=1481773&r1=1481772&r2=1481773&view=diff
==============================================================================
--- hive/branches/HIVE-4115/ql/src/java/org/apache/hadoop/hive/ql/cube/parse/CubeQueryContext.java
(original)
+++ hive/branches/HIVE-4115/ql/src/java/org/apache/hadoop/hive/ql/cube/parse/CubeQueryContext.java
Mon May 13 10:16:02 2013
@@ -1020,7 +1020,7 @@ public class CubeQueryContext {
   }
 
   public boolean isAggregateExpr(String expr) {
-    return aggregateExprs.contains(expr);
+    return aggregateExprs.contains(expr == null ? expr : expr.toLowerCase());
   }
 
   public boolean hasAggregates() {

Modified: hive/branches/HIVE-4115/ql/src/java/org/apache/hadoop/hive/ql/cube/parse/HQLParser.java
URL: http://svn.apache.org/viewvc/hive/branches/HIVE-4115/ql/src/java/org/apache/hadoop/hive/ql/cube/parse/HQLParser.java?rev=1481773&r1=1481772&r2=1481773&view=diff
==============================================================================
--- hive/branches/HIVE-4115/ql/src/java/org/apache/hadoop/hive/ql/cube/parse/HQLParser.java
(original)
+++ hive/branches/HIVE-4115/ql/src/java/org/apache/hadoop/hive/ql/cube/parse/HQLParser.java
Mon May 13 10:16:02 2013
@@ -31,7 +31,9 @@ import java.util.Queue;
 import java.util.Set;
 
 import org.antlr.runtime.tree.Tree;
+import org.apache.hadoop.hive.ql.exec.FunctionRegistry;
 import org.apache.hadoop.hive.ql.parse.ASTNode;
+import org.apache.hadoop.hive.ql.parse.BaseSemanticAnalyzer;
 import org.apache.hadoop.hive.ql.parse.HiveParser;
 import org.apache.hadoop.hive.ql.parse.ParseDriver;
 import org.apache.hadoop.hive.ql.parse.ParseException;
@@ -315,4 +317,22 @@ public class HQLParser {
 
     return colname;
   }
+
+  public static boolean isAggregateAST(ASTNode node) {
+    int exprTokenType = node.getToken().getType();
+    if (exprTokenType == HiveParser.TOK_FUNCTION
+        || exprTokenType == HiveParser.TOK_FUNCTIONDI
+        || exprTokenType == HiveParser.TOK_FUNCTIONSTAR) {
+      assert (node.getChildCount() != 0);
+      if (node.getChild(0).getType() == HiveParser.Identifier) {
+        String functionName = BaseSemanticAnalyzer.unescapeIdentifier(
+            node.getChild(0).getText());
+        if (FunctionRegistry.getGenericUDAFResolver(functionName) != null) {
+          return true;
+        }
+      }
+    }
+
+    return false;
+  }
 }
\ No newline at end of file



Mime
View raw message