hadoop-hive-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From na...@apache.org
Subject svn commit: r810290 - in /hadoop/hive/trunk: CHANGES.txt service/src/java/org/apache/hadoop/hive/service/HiveServer.java service/src/test/org/apache/hadoop/hive/service/TestHiveServer.java
Date Tue, 01 Sep 2009 22:34:15 GMT
Author: namit
Date: Tue Sep  1 22:34:15 2009
New Revision: 810290

URL: http://svn.apache.org/viewvc?rev=810290&view=rev
Log:
HIVE-755. Driver NullPointerException when calling getResults without first compiling
(Eric Hwang via namit)


Modified:
    hadoop/hive/trunk/CHANGES.txt
    hadoop/hive/trunk/service/src/java/org/apache/hadoop/hive/service/HiveServer.java
    hadoop/hive/trunk/service/src/test/org/apache/hadoop/hive/service/TestHiveServer.java

Modified: hadoop/hive/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/CHANGES.txt?rev=810290&r1=810289&r2=810290&view=diff
==============================================================================
--- hadoop/hive/trunk/CHANGES.txt (original)
+++ hadoop/hive/trunk/CHANGES.txt Tue Sep  1 22:34:15 2009
@@ -79,6 +79,9 @@
     HIVE-778. add describe for div
     (Ning Zhang via namit)
 
+    HIVE-755. Driver NullPointerException when calling getResults without first compiling
+    (Eric Hwang via namit)
+
 Release 0.4.0 -  Unreleased
 
   INCOMPATIBLE CHANGES

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=810290&r1=810289&r2=810290&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 Tue
Sep  1 22:34:15 2009
@@ -72,6 +72,11 @@
      * Stores state per connection
      */
     private SessionState session;
+    
+    /**
+     * Flag that indicates whether the last executed command was a Hive query
+     */
+    private boolean isHiveQuery;
 
     public static final Log LOG = LogFactory.getLog(HiveServer.class.getName());
 
@@ -81,6 +86,7 @@
     public HiveServerHandler() throws MetaException {
       super(HiveServer.class.getName());
 
+      isHiveQuery = false;
       SessionState session = new SessionState(new HiveConf(SessionState.class));
       SessionState.start(session);
       session.in = null;
@@ -107,8 +113,10 @@
         CommandProcessor proc = CommandProcessorFactory.get(tokens[0]);
         if(proc != null) {
           if (proc instanceof Driver) {
+        	  isHiveQuery = true;
             ret = driver.run(cmd);
           } else {
+        	  isHiveQuery = false;
             ret = proc.run(cmd_1);
           }
         }
@@ -164,6 +172,10 @@
      * Return the Hive schema of the query result
      */
     public Schema getSchema() throws HiveServerException, TException {
+      if (!isHiveQuery)
+        // Return empty schema if the last command was not a Hive query
+        return new Schema();	
+    	
       try {
         Schema schema = driver.getSchema();
         if (schema == null) {
@@ -183,6 +195,10 @@
      * Return the Thrift schema of the query result
      */
     public Schema getThriftSchema() throws HiveServerException, TException {
+      if (!isHiveQuery)
+        // Return empty schema if the last command was not a Hive query
+        return new Schema();
+    	
       try {
         Schema schema = driver.getThriftSchema();
         if (schema == null) {
@@ -205,8 +221,12 @@
      * @return the next row in a query result set. null if there is no more row to fetch.
      */
     public String fetchOne() throws HiveServerException, TException {
-      driver.setMaxRows(1);
+      if (!isHiveQuery)
+        // Return no results if the last command was not a Hive query
+        return "";
+      
       Vector<String> result = new Vector<String>();
+      driver.setMaxRows(1);
       try {
         if (driver.getResults(result)) {
           return result.get(0);
@@ -234,7 +254,11 @@
       if (numRows < 0) {
         throw new HiveServerException("Invalid argument for number of rows: " + numRows);
       } 
-      Vector<String> result = new Vector<String>();
+      if (!isHiveQuery)
+      	// Return no results if the last command was not a Hive query
+        return new Vector<String>();
+      
+      Vector<String> result = new Vector<String>();      
       driver.setMaxRows(numRows);
       try {
         driver.getResults(result);
@@ -253,6 +277,10 @@
      * to the client. Decide whether the buffering should be done in the client.
      */
     public List<String> fetchAll() throws HiveServerException, TException {
+      if (!isHiveQuery)
+        // Return no results if the last command was not a Hive query
+        return new Vector<String>();
+      
       Vector<String> rows = new Vector<String>();
       Vector<String> result = new Vector<String>();
       try {

Modified: hadoop/hive/trunk/service/src/test/org/apache/hadoop/hive/service/TestHiveServer.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/service/src/test/org/apache/hadoop/hive/service/TestHiveServer.java?rev=810290&r1=810289&r2=810290&view=diff
==============================================================================
--- hadoop/hive/trunk/service/src/test/org/apache/hadoop/hive/service/TestHiveServer.java
(original)
+++ hadoop/hive/trunk/service/src/test/org/apache/hadoop/hive/service/TestHiveServer.java
Tue Sep  1 22:34:15 2009
@@ -115,6 +115,53 @@
     transport.close();
   }
 
+  public void testNonHiveCommand() throws Exception {
+    try {
+      client.execute("drop table " + tableName);
+    } catch (Exception ex) {
+    }
+
+    client.execute("create table " + tableName + " (num int)");
+    client.execute("load data local inpath '" + dataFilePath.toString() + "' into table "
+ tableName);
+    
+    // Command not part of HiveQL -  verify no results
+    client.execute("SET hive.mapred.mode = nonstrict");
+    
+    Schema schema = client.getSchema();
+    assertEquals(schema.getFieldSchemasSize(), 0);
+    assertEquals(schema.getPropertiesSize(), 0);
+    
+    Schema thriftschema = client.getThriftSchema();
+    assertEquals(thriftschema.getFieldSchemasSize(), 0);
+    assertEquals(thriftschema.getPropertiesSize(), 0);
+    
+    assertEquals(client.fetchOne(), "");
+    assertEquals(client.fetchN(10).size(), 0);
+    assertEquals(client.fetchAll().size(), 0);
+    
+    // Execute Hive query and fetch
+    client.execute("select * from " + tableName + " limit 10");
+    String row = client.fetchOne();
+    
+    // Re-execute command not part of HiveQL - verify still no results
+    client.execute("SET hive.mapred.mode = nonstrict");
+    
+    schema = client.getSchema();
+    assertEquals(schema.getFieldSchemasSize(), 0);
+    assertEquals(schema.getPropertiesSize(), 0);
+    
+    thriftschema = client.getThriftSchema();
+    assertEquals(thriftschema.getFieldSchemasSize(), 0);
+    assertEquals(thriftschema.getPropertiesSize(), 0);
+    
+    assertEquals(client.fetchOne(), "");
+    assertEquals(client.fetchN(10).size(), 0);
+    assertEquals(client.fetchAll().size(), 0);
+
+    // Cleanup
+    client.execute("drop table " + tableName);
+  }
+  
   /**
    * Test metastore call
    */



Mime
View raw message