hive-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amareshw...@apache.org
Subject svn commit: r1482207 - in /hive/branches/HIVE-4115/ql/src: java/org/apache/hadoop/hive/ql/cube/processors/CubeDriver.java test/org/apache/hadoop/hive/ql/cube/processors/TestCubeDriver.java
Date Tue, 14 May 2013 05:50:59 GMT
Author: amareshwari
Date: Tue May 14 05:50:58 2013
New Revision: 1482207

URL: http://svn.apache.org/r1482207
Log:
Add support for cube explain query

Modified:
    hive/branches/HIVE-4115/ql/src/java/org/apache/hadoop/hive/ql/cube/processors/CubeDriver.java
    hive/branches/HIVE-4115/ql/src/test/org/apache/hadoop/hive/ql/cube/processors/TestCubeDriver.java

Modified: hive/branches/HIVE-4115/ql/src/java/org/apache/hadoop/hive/ql/cube/processors/CubeDriver.java
URL: http://svn.apache.org/viewvc/hive/branches/HIVE-4115/ql/src/java/org/apache/hadoop/hive/ql/cube/processors/CubeDriver.java?rev=1482207&r1=1482206&r2=1482207&view=diff
==============================================================================
--- hive/branches/HIVE-4115/ql/src/java/org/apache/hadoop/hive/ql/cube/processors/CubeDriver.java
(original)
+++ hive/branches/HIVE-4115/ql/src/java/org/apache/hadoop/hive/ql/cube/processors/CubeDriver.java
Tue May 14 05:50:58 2013
@@ -11,6 +11,7 @@ import org.apache.hadoop.hive.ql.ErrorMs
 import org.apache.hadoop.hive.ql.cube.parse.CubeQueryContext;
 import org.apache.hadoop.hive.ql.cube.parse.CubeQueryRewriter;
 import org.apache.hadoop.hive.ql.parse.ASTNode;
+import org.apache.hadoop.hive.ql.parse.HiveParser;
 import org.apache.hadoop.hive.ql.parse.ParseDriver;
 import org.apache.hadoop.hive.ql.parse.ParseException;
 import org.apache.hadoop.hive.ql.parse.ParseUtils;
@@ -57,13 +58,22 @@ public class CubeDriver extends Driver {
     ParseDriver pd = new ParseDriver();
     ASTNode tree = pd.parse(query, ctx);
     tree = ParseUtils.findRootNonNullToken(tree);
+    boolean explain = false;
+    if (tree.getToken().getType() == (HiveParser.TOK_EXPLAIN)) {
+      tree = (ASTNode) tree.getChild(0);
+      explain = true;
+    }
     // compile the cube query and rewrite it to HQL query
     CubeQueryRewriter rewriter = new CubeQueryRewriter(getConf());
     // 1. rewrite query to get summary tables and joins
     CubeQueryContext phase1Query = rewriter.rewritePhase1(tree);
     CubeQueryContext finalQuery = rewriter.rewritePhase2(phase1Query,
         getSupportedStorages(getConf()));
-    return finalQuery.toHQL();
+    String hql = finalQuery.toHQL();
+    if (explain) {
+      hql = "EXPLAIN " + hql;
+    }
+    return hql;
   }
 
   private List<String> getSupportedStorages(HiveConf conf) {

Modified: hive/branches/HIVE-4115/ql/src/test/org/apache/hadoop/hive/ql/cube/processors/TestCubeDriver.java
URL: http://svn.apache.org/viewvc/hive/branches/HIVE-4115/ql/src/test/org/apache/hadoop/hive/ql/cube/processors/TestCubeDriver.java?rev=1482207&r1=1482206&r2=1482207&view=diff
==============================================================================
--- hive/branches/HIVE-4115/ql/src/test/org/apache/hadoop/hive/ql/cube/processors/TestCubeDriver.java
(original)
+++ hive/branches/HIVE-4115/ql/src/test/org/apache/hadoop/hive/ql/cube/processors/TestCubeDriver.java
Tue May 14 05:50:58 2013
@@ -91,6 +91,14 @@ public class TestCubeDriver {
   }
 
   @Test
+  public void testCubeExplain() throws Exception {
+    String hqlQuery = driver.compileCubeQuery("explain select SUM(msr2) from " +
+        "testCube where time_range_in('" + getDateUptoHours(twodaysBack)
+        + "','" + getDateUptoHours(now) + "')");
+    System.out.println("cube hql:" + hqlQuery);
+  }
+
+  @Test
   public void testCubeWhereQuery() throws Exception {
     System.out.println("Test from:" + getDateUptoHours(twodaysBack) + " to:" +
         getDateUptoHours(now));
@@ -509,7 +517,7 @@ public class TestCubeDriver {
         + "','" + getDateUptoHours(now) + "')");
     System.out.println("cube hql:" + hqlQuery);
     hqlQuery = driver.compileCubeQuery("select dim1, dim2, COUNT(msr1)," +
-    		" SUM(msr2), msr3 from testCube" +
+        " SUM(msr2), msr3 from testCube" +
         " where time_range_in('" + getDateUptoHours(twodaysBack)
         + "','" + getDateUptoHours(now) + "')");
     System.out.println("cube hql:" + hqlQuery);



Mime
View raw message