Эх сурвалжийг харах

Revert "Resolving Hive 0.5 -> Hive 0.6 API incompatibilities. Check whether DriverContext should be null in initialization of FetchTask."

This reverts commit d3abcbafd9db3688a7bb5671d035260ef265b78c.
vinithra 15 жил өмнө
parent
commit
a507c88186

+ 27 - 18
apps/beeswax/java/src/com/cloudera/beeswax/BeeswaxServiceImpl.java

@@ -42,6 +42,7 @@ import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Properties;
 import java.util.UUID;
+import java.util.Vector;
 import javax.net.ssl.HttpsURLConnection;
 import javax.net.ssl.SSLContext;
 
@@ -55,8 +56,10 @@ import org.apache.hadoop.hive.ql.exec.FetchTask;
 import org.apache.hadoop.hive.ql.exec.Utilities;
 import org.apache.hadoop.hive.ql.metadata.Hive;
 import org.apache.hadoop.hive.ql.metadata.HiveException;
-import org.apache.hadoop.hive.ql.plan.FetchWork;
-import org.apache.hadoop.hive.ql.plan.TableDesc;
+import org.apache.hadoop.hive.ql.parse.BaseSemanticAnalyzer;
+import org.apache.hadoop.hive.ql.parse.ExplainSemanticAnalyzer;
+import org.apache.hadoop.hive.ql.plan.fetchWork;
+import org.apache.hadoop.hive.ql.plan.tableDesc;
 import org.apache.hadoop.hive.ql.processors.CommandProcessor;
 import org.apache.hadoop.hive.ql.processors.CommandProcessorFactory;
 import org.apache.hadoop.hive.ql.QueryPlan;
@@ -212,9 +215,9 @@ public class BeeswaxServiceImpl implements BeeswaxService.Iface {
         CommandProcessor p = CommandProcessorFactory.get(tokens[0]);
         int res;
         if (p instanceof Driver) {
-          res = p.run(cmd).getResponseCode();
+          res = p.run(cmd);
         } else {
-          res = p.run(cmd1).getResponseCode();
+          res = p.run(cmd1);
         }
         if (res != 0) {
           throwException(new RuntimeException(getErrorStreamAsString()));
@@ -320,7 +323,7 @@ public class BeeswaxServiceImpl implements BeeswaxService.Iface {
     }
 
     private void materializeResults(Results r, boolean startOver) throws IOException {
-      if (driver.getPlan().getFetchTask() == null) {
+      if (driver.getPlan().getPlan().getFetchTask() == null) {
         // This query is never going to return anything.
         r.has_more = false;
         r.setData(Collections.<String>emptyList());
@@ -330,12 +333,11 @@ public class BeeswaxServiceImpl implements BeeswaxService.Iface {
 
       if (startOver) {
         // This is totally inappropriately reaching into internals.
-        driver.getPlan().getFetchTask().initialize(hiveConf,
-            driver.getPlan(), null);
+        driver.getPlan().getPlan().getFetchTask().initialize(hiveConf,
+            driver.getPlan());
         startRow = 0;
       }
-
-      ArrayList<String> v = new ArrayList<String>();
+      Vector<String> v = new Vector<String>();
       r.setData(v);
       r.has_more = driver.getResults(v);
       r.start_row = startRow;
@@ -363,8 +365,8 @@ public class BeeswaxServiceImpl implements BeeswaxService.Iface {
         LOG.error("Error getting schema for query: " + query.query, ex);
       }
 
-      FetchWork work = getFetchWork();
-      TableDesc desc = work.getTblDesc();
+      fetchWork work = getFetchWork();
+      tableDesc desc = work.getTblDesc();
       String tabledir = null;
       String tablename = null;
       String sep = null;
@@ -381,15 +383,19 @@ public class BeeswaxServiceImpl implements BeeswaxService.Iface {
     }
 
     /**
-     * Get the FetchWork. Only SELECTs have them.
+     * Get the fetchWork. Only SELECTs have them.
      */
-    synchronized private FetchWork getFetchWork() {
+    synchronized private fetchWork getFetchWork() {
       QueryPlan plan = driver.getPlan();
       FetchTask fetchTask = null;
       if (plan != null) {
-        fetchTask = plan.getFetchTask();
-        if (fetchTask != null) {
-          fetchTask.initialize(hiveConf, plan, null);
+        BaseSemanticAnalyzer sem = plan.getPlan();
+        if (sem.getFetchTask() != null) {
+          if (!sem.getFetchTaskInit()) {
+            sem.setFetchTaskInit(true);
+            sem.getFetchTask().initialize(hiveConf, plan);
+          }
+          fetchTask = (FetchTask) sem.getFetchTask();
         }
       }
 
@@ -397,7 +403,7 @@ public class BeeswaxServiceImpl implements BeeswaxService.Iface {
         return null;
       }
 
-      FetchWork work = fetchTask.getWork();
+      fetchWork work = (fetchWork) fetchTask.getWork();
       return work;
     }
 
@@ -406,13 +412,16 @@ public class BeeswaxServiceImpl implements BeeswaxService.Iface {
       // By manipulating the query, this will make errors harder to find.
       query.query = "EXPLAIN " + query.query;
       checkedCompile();
+      if (!(driver.getPlan().getPlan() instanceof ExplainSemanticAnalyzer)) {
+        throwException(new RuntimeException("Expected explain plan."));
+      }
 
       int ret;
       if (0 != (ret = driver.execute())) {
         throwException(new RuntimeException("Failed to execute: EXPLAIN " + ret));
       }
       StringBuilder sb = new StringBuilder();
-      ArrayList<String> v = new ArrayList<String>();
+      Vector<String> v = new Vector<String>();
       try {
         while (driver.getResults(v)) {
           for (String s : v) {