hadoop-hive-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zs...@apache.org
Subject svn commit: r907120 - in /hadoop/hive/trunk: ./ cli/src/java/org/apache/hadoop/hive/cli/ hwi/src/java/org/apache/hadoop/hive/hwi/ ql/src/java/org/apache/hadoop/hive/ql/ ql/src/java/org/apache/hadoop/hive/ql/processors/ ql/src/test/org/apache/hadoop/hiv...
Date Fri, 05 Feb 2010 22:49:34 GMT
Author: zshao
Date: Fri Feb  5 22:49:34 2010
New Revision: 907120

URL: http://svn.apache.org/viewvc?rev=907120&view=rev
Log:
HIVE-862. CommandProcessor should return DriverResponse. (Bill Graham via zshao)

Added:
    hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/processors/CommandProcessorResponse.java
Modified:
    hadoop/hive/trunk/CHANGES.txt
    hadoop/hive/trunk/cli/src/java/org/apache/hadoop/hive/cli/CliDriver.java
    hadoop/hive/trunk/hwi/src/java/org/apache/hadoop/hive/hwi/HWISessionItem.java
    hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/Driver.java
    hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/processors/AddResourceProcessor.java
    hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/processors/CommandProcessor.java
    hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/processors/DeleteResourceProcessor.java
    hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/processors/DfsProcessor.java
    hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/processors/SetProcessor.java
    hadoop/hive/trunk/ql/src/test/org/apache/hadoop/hive/ql/QTestUtil.java
    hadoop/hive/trunk/ql/src/test/org/apache/hadoop/hive/ql/history/TestHiveHistory.java
    hadoop/hive/trunk/service/src/java/org/apache/hadoop/hive/service/HiveServer.java

Modified: hadoop/hive/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/CHANGES.txt?rev=907120&r1=907119&r2=907120&view=diff
==============================================================================
--- hadoop/hive/trunk/CHANGES.txt (original)
+++ hadoop/hive/trunk/CHANGES.txt Fri Feb  5 22:49:34 2010
@@ -61,6 +61,9 @@
     HIVE-1120. In ivy offline mode, don't delete downloaded jars.
     (John Sichi via zshao)
 
+    HIVE-862. CommandProcessor should return DriverResponse.
+    (Bill Graham via zshao)
+
   OPTIMIZATIONS
 
   BUG FIXES

Modified: hadoop/hive/trunk/cli/src/java/org/apache/hadoop/hive/cli/CliDriver.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/cli/src/java/org/apache/hadoop/hive/cli/CliDriver.java?rev=907120&r1=907119&r2=907120&view=diff
==============================================================================
--- hadoop/hive/trunk/cli/src/java/org/apache/hadoop/hive/cli/CliDriver.java (original)
+++ hadoop/hive/trunk/cli/src/java/org/apache/hadoop/hive/cli/CliDriver.java Fri Feb  5 22:49:34
2010
@@ -137,7 +137,7 @@
           PrintStream out = ss.out;
           long start = System.currentTimeMillis();
 
-          ret = qp.run(cmd);
+          ret = qp.run(cmd).getResponseCode();
           if (ret != 0) {
             qp.close();
             return ret;
@@ -173,7 +173,7 @@
           }
 
         } else {
-          ret = proc.run(cmd_1);
+          ret = proc.run(cmd_1).getResponseCode();
         }
       }
     }

Modified: hadoop/hive/trunk/hwi/src/java/org/apache/hadoop/hive/hwi/HWISessionItem.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/hwi/src/java/org/apache/hadoop/hive/hwi/HWISessionItem.java?rev=907120&r1=907119&r2=907120&view=diff
==============================================================================
--- hadoop/hive/trunk/hwi/src/java/org/apache/hadoop/hive/hwi/HWISessionItem.java (original)
+++ hadoop/hive/trunk/hwi/src/java/org/apache/hadoop/hive/hwi/HWISessionItem.java Fri Feb
 5 22:49:34 2010
@@ -330,7 +330,7 @@
       if (proc != null) {
         if (proc instanceof Driver) {
           Driver qp = (Driver) proc;
-          queryRet.add(new Integer(qp.run(cmd)));
+          queryRet.add(new Integer(qp.run(cmd).getResponseCode()));
           ArrayList<String> res = new ArrayList<String>();
           try {
             while (qp.getResults(res)) {
@@ -355,7 +355,7 @@
           }
           qp.close();
         } else {
-          queryRet.add(new Integer(proc.run(cmd_1)));
+          queryRet.add(new Integer(proc.run(cmd_1).getResponseCode()));
         }
       } else {
         // processor was null

Modified: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/Driver.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/Driver.java?rev=907120&r1=907119&r2=907120&view=diff
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/Driver.java (original)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/Driver.java Fri Feb  5 22:49:34
2010
@@ -18,14 +18,8 @@
 
 package org.apache.hadoop.hive.ql;
 
-import java.beans.XMLDecoder;
-import java.beans.XMLEncoder;
 import java.io.DataInput;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
 import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
 import java.io.Serializable;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
@@ -76,6 +70,7 @@
 import org.apache.hadoop.hive.ql.plan.TableDesc;
 import org.apache.hadoop.hive.ql.plan.PlanUtils.ExpressionTypes;
 import org.apache.hadoop.hive.ql.processors.CommandProcessor;
+import org.apache.hadoop.hive.ql.processors.CommandProcessorResponse;
 import org.apache.hadoop.hive.ql.session.SessionState;
 import org.apache.hadoop.hive.ql.session.SessionState.LogHelper;
 import org.apache.hadoop.hive.serde2.ByteStream;
@@ -98,7 +93,7 @@
   private Context ctx;
   private QueryPlan plan;
   private Schema schema;
-  
+
   private String errorMessage;
   private String SQLState;
 
@@ -155,17 +150,17 @@
     return cs;
   }
 
-  
+
   public Schema getSchema() {
     return schema;
   }
-  
+
   /**
    * Get a Schema with fields represented with native Hive types
    */
   public static Schema getSchema(BaseSemanticAnalyzer sem, HiveConf conf) {
     Schema schema = null;
-    
+
     // If we have a plan, prefer its logical result schema if it's
     // available; otherwise, try digging out a fetch task; failing that,
     // give up.
@@ -198,7 +193,7 @@
           lst = MetaStoreUtils.getFieldsFromDeserializer(
               tableName, td.getDeserializer());
         } catch (Exception e) {
-          LOG.warn("Error getting schema: " + 
+          LOG.warn("Error getting schema: " +
               org.apache.hadoop.util.StringUtils.stringifyException(e));
         }
         if (lst != null) {
@@ -325,10 +320,10 @@
       if (sem.getFetchTask() != null) {
         sem.getFetchTask().initialize(conf, plan, null);
       }
-      
+
       // get the output schema
       schema = getSchema(sem, conf);
-      
+
       return (0);
     } catch (SemanticException e) {
       errorMessage = "FAILED: Error in semantic analysis: " + e.getMessage();
@@ -358,59 +353,21 @@
     return plan;
   }
 
-  public int run(String command) {
-    DriverResponse response = runCommand(command);
-    return response.getResponseCode();
-  }
-
-  public DriverResponse runCommand(String command) {
+  public CommandProcessorResponse run(String command) {
     errorMessage = null;
     SQLState = null;
 
     int ret = compile(command);
     if (ret != 0) {
-      return new DriverResponse(ret, errorMessage, SQLState);
+      return new CommandProcessorResponse(ret, errorMessage, SQLState);
     }
 
     ret = execute();
     if (ret != 0) {
-      return new DriverResponse(ret, errorMessage, SQLState);
+      return new CommandProcessorResponse(ret, errorMessage, SQLState);
     }
 
-    return new DriverResponse(ret);
-  }
-
-  /**
-   * Encapsulates the basic response info returned by the Driver. Typically
-   * <code>errorMessage</code> and <code>SQLState</code> will only
be set if the
-   * <code>responseCode</code> is not 0.
-   */
-  public class DriverResponse {
-    private final int responseCode;
-    private final String errorMessage;
-    private final String SQLState;
-
-    public DriverResponse(int responseCode) {
-      this(responseCode, null, null);
-    }
-
-    public DriverResponse(int responseCode, String errorMessage, String SQLState) {
-      this.responseCode = responseCode;
-      this.errorMessage = errorMessage;
-      this.SQLState = SQLState;
-    }
-
-    public int getResponseCode() {
-      return responseCode;
-    }
-
-    public String getErrorMessage() {
-      return errorMessage;
-    }
-
-    public String getSQLState() {
-      return SQLState;
-    }
+    return new CommandProcessorResponse(ret);
   }
 
   private List<PreExecute> getPreExecHooks() throws Exception {
@@ -603,7 +560,7 @@
       }
     }
     console.printInfo("OK");
-    
+
     return (0);
   }
 

Modified: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/processors/AddResourceProcessor.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/processors/AddResourceProcessor.java?rev=907120&r1=907119&r2=907120&view=diff
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/processors/AddResourceProcessor.java
(original)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/processors/AddResourceProcessor.java
Fri Feb  5 22:49:34 2010
@@ -33,7 +33,7 @@
   public void init() {
   }
 
-  public int run(String command) {
+  public CommandProcessorResponse run(String command) {
     SessionState ss = SessionState.get();
     String[] tokens = command.split("\\s+");
     SessionState.ResourceType t;
@@ -42,12 +42,12 @@
       console.printError("Usage: add ["
           + StringUtils.join(SessionState.ResourceType.values(), "|")
           + "] <value> [<value>]*");
-      return 1;
+      return new CommandProcessorResponse(1);
     }
     for (int i = 1; i < tokens.length; i++) {
       ss.add_resource(t, tokens[i]);
     }
-    return 0;
+    return new CommandProcessorResponse(0);
   }
 
 }

Modified: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/processors/CommandProcessor.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/processors/CommandProcessor.java?rev=907120&r1=907119&r2=907120&view=diff
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/processors/CommandProcessor.java
(original)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/processors/CommandProcessor.java
Fri Feb  5 22:49:34 2010
@@ -21,5 +21,5 @@
 public interface CommandProcessor {
   public void init();
 
-  public int run(String command);
+  public CommandProcessorResponse run(String command);
 }

Added: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/processors/CommandProcessorResponse.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/processors/CommandProcessorResponse.java?rev=907120&view=auto
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/processors/CommandProcessorResponse.java
(added)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/processors/CommandProcessorResponse.java
Fri Feb  5 22:49:34 2010
@@ -0,0 +1,45 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.hive.ql.processors;
+
+/**
+ * Encapsulates the basic response info returned by classes the implement the
+ * <code>CommandProcessor</code> interfaace. Typically <code>errorMessage</code>
+ * and <code>SQLState</code> will only be set if the <code>responseCode</code>
+ * is not 0.
+ */
+public class CommandProcessorResponse {
+  private int responseCode;
+  private String errorMessage;
+  private String SQLState;
+
+  public CommandProcessorResponse(int responseCode) {
+    this(responseCode, null, null);
+  }
+
+  public CommandProcessorResponse(int responseCode, String errorMessage, String SQLState)
{
+    this.responseCode = responseCode;
+    this.errorMessage = errorMessage;
+    this.SQLState = SQLState;
+  }
+
+  public int getResponseCode() { return responseCode; }
+  public String getErrorMessage() { return errorMessage; }
+  public String getSQLState() { return SQLState; }
+}

Modified: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/processors/DeleteResourceProcessor.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/processors/DeleteResourceProcessor.java?rev=907120&r1=907119&r2=907120&view=diff
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/processors/DeleteResourceProcessor.java
(original)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/processors/DeleteResourceProcessor.java
Fri Feb  5 22:49:34 2010
@@ -33,7 +33,7 @@
   public void init() {
   }
 
-  public int run(String command) {
+  public CommandProcessorResponse run(String command) {
     SessionState ss = SessionState.get();
     String[] tokens = command.split("\\s+");
 
@@ -43,7 +43,7 @@
       console.printError("Usage: delete ["
           + StringUtils.join(SessionState.ResourceType.values(), "|")
           + "] <value> [<value>]*");
-      return 1;
+      return new CommandProcessorResponse(1);
     }
 
     if (tokens.length >= 2) {
@@ -54,6 +54,6 @@
       ss.delete_resource(t);
     }
 
-    return 0;
+    return new CommandProcessorResponse(0);
   }
 }

Modified: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/processors/DfsProcessor.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/processors/DfsProcessor.java?rev=907120&r1=907119&r2=907120&view=diff
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/processors/DfsProcessor.java (original)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/processors/DfsProcessor.java Fri
Feb  5 22:49:34 2010
@@ -41,7 +41,7 @@
   public void init() {
   }
 
-  public int run(String command) {
+  public CommandProcessorResponse run(String command) {
     String[] tokens = command.split("\\s+");
 
     try {
@@ -58,13 +58,13 @@
       }
 
       System.setOut(oldOut);
-      return (ret);
+      return new CommandProcessorResponse(ret);
 
     } catch (Exception e) {
       console.printError("Exception raised from DFSShell.run "
           + e.getLocalizedMessage(), org.apache.hadoop.util.StringUtils
           .stringifyException(e));
-      return 1;
+      return new CommandProcessorResponse(1);
     }
   }
 

Modified: hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/processors/SetProcessor.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/processors/SetProcessor.java?rev=907120&r1=907119&r2=907120&view=diff
==============================================================================
--- hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/processors/SetProcessor.java (original)
+++ hadoop/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/processors/SetProcessor.java Fri
Feb  5 22:49:34 2010
@@ -61,18 +61,18 @@
   public void init() {
   }
 
-  public int run(String command) {
+  public CommandProcessorResponse run(String command) {
     SessionState ss = SessionState.get();
 
     String nwcmd = command.trim();
     if (nwcmd.equals("")) {
       dumpOptions(ss.getConf().getChangedProperties());
-      return 0;
+      return new CommandProcessorResponse(0);
     }
 
     if (nwcmd.equals("-v")) {
       dumpOptions(ss.getConf().getAllProperties());
-      return 0;
+      return new CommandProcessorResponse(0);
     }
 
     String[] part = new String[2];
@@ -81,7 +81,7 @@
     if (eqIndex == -1) {
       // no equality sign - print the property out
       dumpOption(ss.getConf().getAllProperties(), nwcmd);
-      return (0);
+      return new CommandProcessorResponse(0);
     } else if (eqIndex == nwcmd.length() - 1) {
       part[0] = nwcmd.substring(0, nwcmd.length() - 1);
       part[1] = "";
@@ -99,8 +99,8 @@
       }
     } catch (IllegalArgumentException err) {
       ss.err.println(err.getMessage());
-      return 1;
+      return new CommandProcessorResponse(1);
     }
-    return 0;
+    return new CommandProcessorResponse(0);
   }
 }

Modified: hadoop/hive/trunk/ql/src/test/org/apache/hadoop/hive/ql/QTestUtil.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/test/org/apache/hadoop/hive/ql/QTestUtil.java?rev=907120&r1=907119&r2=907120&view=diff
==============================================================================
--- hadoop/hive/trunk/ql/src/test/org/apache/hadoop/hive/ql/QTestUtil.java (original)
+++ hadoop/hive/trunk/ql/src/test/org/apache/hadoop/hive/ql/QTestUtil.java Fri Feb  5 22:49:34
2010
@@ -250,7 +250,7 @@
 
   private void runLoadCmd(String loadCmd) throws Exception {
     int ecode = 0;
-    ecode = drv.run(loadCmd);
+    ecode = drv.run(loadCmd).getResponseCode();
     if (ecode != 0) {
       throw new Exception("load command: " + loadCmd
           + " failed with exit code= " + ecode);
@@ -261,7 +261,7 @@
 
   private void runCreateTableCmd(String createTableCmd) throws Exception {
     int ecode = 0;
-    ecode = drv.run(createTableCmd);
+    ecode = drv.run(createTableCmd).getResponseCode();
     if (ecode != 0) {
       throw new Exception("create table command: " + createTableCmd
           + " failed with exit code= " + ecode);
@@ -485,7 +485,7 @@
   }
 
   public int execute(String tname) {
-    return drv.run(qMap.get(tname));
+    return drv.run(qMap.get(tname)).getResponseCode();
   }
 
   public int executeClient(String tname) {

Modified: hadoop/hive/trunk/ql/src/test/org/apache/hadoop/hive/ql/history/TestHiveHistory.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/ql/src/test/org/apache/hadoop/hive/ql/history/TestHiveHistory.java?rev=907120&r1=907119&r2=907120&view=diff
==============================================================================
--- hadoop/hive/trunk/ql/src/test/org/apache/hadoop/hive/ql/history/TestHiveHistory.java (original)
+++ hadoop/hive/trunk/ql/src/test/org/apache/hadoop/hive/ql/history/TestHiveHistory.java Fri
Feb  5 22:49:34 2010
@@ -130,7 +130,7 @@
 
       String cmd = "select a.key from src a";
       Driver d = new Driver();
-      int ret = d.run(cmd);
+      int ret = d.run(cmd).getResponseCode();
       if (ret != 0) {
         fail("Failed");
       }

Modified: hadoop/hive/trunk/service/src/java/org/apache/hadoop/hive/service/HiveServer.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/service/src/java/org/apache/hadoop/hive/service/HiveServer.java?rev=907120&r1=907119&r2=907120&view=diff
==============================================================================
--- hadoop/hive/trunk/service/src/java/org/apache/hadoop/hive/service/HiveServer.java (original)
+++ hadoop/hive/trunk/service/src/java/org/apache/hadoop/hive/service/HiveServer.java Fri
Feb  5 22:49:34 2010
@@ -32,6 +32,7 @@
 import org.apache.hadoop.hive.ql.plan.api.QueryPlan;
 import org.apache.hadoop.hive.ql.processors.CommandProcessor;
 import org.apache.hadoop.hive.ql.processors.CommandProcessorFactory;
+import org.apache.hadoop.hive.ql.processors.CommandProcessorResponse;
 import org.apache.hadoop.hive.ql.session.SessionState;
 import org.apache.hadoop.mapred.ClusterStatus;
 import org.apache.hadoop.mapred.JobTracker;
@@ -88,7 +89,7 @@
 
     /**
      * Executes a query.
-     * 
+     *
      * @param cmd
      *          HiveQL query to execute
      */
@@ -106,17 +107,19 @@
 
       try {
         CommandProcessor proc = CommandProcessorFactory.get(tokens[0]);
+        CommandProcessorResponse response = null;
         if (proc != null) {
           if (proc instanceof Driver) {
             isHiveQuery = true;
-            Driver.DriverResponse response = driver.runCommand(cmd);
-            ret = response.getResponseCode();
-            SQLState = response.getSQLState();
-            errorMessage = response.getErrorMessage();
+            response = driver.run(cmd);
           } else {
             isHiveQuery = false;
-            ret = proc.run(cmd_1);
+            response = proc.run(cmd_1);
           }
+
+          ret = response.getResponseCode();
+          SQLState = response.getSQLState();
+          errorMessage = response.getErrorMessage();
         }
       } catch (Exception e) {
         HiveServerException ex = new HiveServerException();
@@ -219,7 +222,7 @@
 
     /**
      * Fetches the next row in a query result set.
-     * 
+     *
      * @return the next row in a query result set. null if there is no more row
      *         to fetch.
      */
@@ -248,7 +251,7 @@
 
     /**
      * Fetches numRows rows.
-     * 
+     *
      * @param numRows
      *          Number of rows to fetch.
      * @return A list of rows. The size of the list is numRows if there are at
@@ -284,10 +287,10 @@
 
     /**
      * Fetches all the rows in a result set.
-     * 
+     *
      * @return All the rows in a result set of a query executed using execute
      *         method.
-     * 
+     *
      *         TODO: Currently the server buffers all the rows before returning
      *         them to the client. Decide whether the buffering should be done
      *         in the client.



Mime
View raw message