hive-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amareshw...@apache.org
Subject svn commit: r1487329 - in /hive/branches/HIVE-4115/ql/src/java/org/apache/hadoop/hive/ql/cube/parse: AggregateResolver.java AliasReplacer.java CubeQueryContext.java GroupbyResolver.java
Date Wed, 29 May 2013 06:49:30 GMT
Author: amareshwari
Date: Wed May 29 06:49:30 2013
New Revision: 1487329

URL: http://svn.apache.org/r1487329
Log:
Fix AliasReplacer

Modified:
    hive/branches/HIVE-4115/ql/src/java/org/apache/hadoop/hive/ql/cube/parse/AggregateResolver.java
    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/GroupbyResolver.java

Modified: hive/branches/HIVE-4115/ql/src/java/org/apache/hadoop/hive/ql/cube/parse/AggregateResolver.java
URL: http://svn.apache.org/viewvc/hive/branches/HIVE-4115/ql/src/java/org/apache/hadoop/hive/ql/cube/parse/AggregateResolver.java?rev=1487329&r1=1487328&r2=1487329&view=diff
==============================================================================
--- hive/branches/HIVE-4115/ql/src/java/org/apache/hadoop/hive/ql/cube/parse/AggregateResolver.java
(original)
+++ hive/branches/HIVE-4115/ql/src/java/org/apache/hadoop/hive/ql/cube/parse/AggregateResolver.java
Wed May 29 06:49:30 2013
@@ -163,7 +163,7 @@ public class AggregateResolver implement
     String exprTokens[] = StringUtils.split(exprTree, ",");
     for (int i = 0; i < exprTokens.length; i++) {
       String token = exprTokens[i].trim();
-      String tokenAlias = cubeql.getAlias(token);
+      String tokenAlias = cubeql.getAlias(token.toLowerCase());
       boolean hasAlias = false;
       if (StringUtils.isNotBlank(tokenAlias)) {
         token = token.substring(0, exprTree.lastIndexOf(tokenAlias)).trim();

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=1487329&r1=1487328&r2=1487329&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
Wed May 29 06:49:30 2013
@@ -1,5 +1,8 @@
 package org.apache.hadoop.hive.ql.cube.parse;
 
+import static org.apache.hadoop.hive.ql.parse.HiveParser.Identifier;
+import static org.apache.hadoop.hive.ql.parse.HiveParser.TOK_SELEXPR;
+
 import java.util.Map;
 
 import org.antlr.runtime.CommonToken;
@@ -71,6 +74,8 @@ public class AliasReplacer implements Co
     // Update the aggregate expression set
     updateAggregates(selectAST, cubeql);
     updateAggregates(havingAST, cubeql);
+    // Update alias map as well
+    updateAliasMap(selectAST, cubeql);
   }
 
   private void replaceAliases(ASTNode node, int nodePos,
@@ -142,4 +147,22 @@ public class AliasReplacer implements Co
     }
   }
 
+  private void updateAliasMap(ASTNode root, CubeQueryContext cubeql) {
+    if (root == null) {
+      return;
+    }
+
+    if (root.getToken().getType() == TOK_SELEXPR) {
+        ASTNode alias = HQLParser.findNodeByPath(root, Identifier);
+        if (alias != null) {
+          cubeql.addExprToAlias(HQLParser.getString(root).trim().toLowerCase(),
+              alias.getText());
+        }
+    } else {
+      for (int i = 0; i < root.getChildCount(); i++) {
+        updateAliasMap((ASTNode)root.getChild(i), 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=1487329&r1=1487328&r2=1487329&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
Wed May 29 06:49:30 2013
@@ -1081,4 +1081,10 @@ public class CubeQueryContext {
   public CubeMetastoreClient getMetastoreClient() {
     return client;
   }
+
+  public void addExprToAlias(String expr, String alias) {
+    if (exprToAlias != null) {
+      exprToAlias.put(expr.trim().toLowerCase(), alias);
+    }
+  }
 }

Modified: hive/branches/HIVE-4115/ql/src/java/org/apache/hadoop/hive/ql/cube/parse/GroupbyResolver.java
URL: http://svn.apache.org/viewvc/hive/branches/HIVE-4115/ql/src/java/org/apache/hadoop/hive/ql/cube/parse/GroupbyResolver.java?rev=1487329&r1=1487328&r2=1487329&view=diff
==============================================================================
--- hive/branches/HIVE-4115/ql/src/java/org/apache/hadoop/hive/ql/cube/parse/GroupbyResolver.java
(original)
+++ hive/branches/HIVE-4115/ql/src/java/org/apache/hadoop/hive/ql/cube/parse/GroupbyResolver.java
Wed May 29 06:49:30 2013
@@ -3,6 +3,7 @@ package org.apache.hadoop.hive.ql.cube.p
 import java.util.ArrayList;
 import java.util.List;
 
+import org.apache.commons.lang.StringUtils;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.hive.ql.parse.SemanticException;
 
@@ -18,13 +19,13 @@ public class GroupbyResolver implements 
     String groupByTree = cubeql.getGroupByTree();
     String selectTree = cubeql.getSelectTree();
     List<String> selectExprs = new ArrayList<String>();
-    String[] sel = selectTree.split(",");
+    String[] sel = StringUtils.split(selectTree, ",");
     for (String s : sel) {
       selectExprs.add(s.trim().toLowerCase());
     }
     List<String> groupByExprs = new ArrayList<String>();
     if (groupByTree != null) {
-      String[] gby = groupByTree.split(",");
+      String[] gby = StringUtils.split(groupByTree, ",");
       for (String g : gby) {
         groupByExprs.add(g.trim().toLowerCase());
       }



Mime
View raw message