You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by na...@apache.org on 2009/09/02 00:33:06 UTC
svn commit: r810289 - in /hadoop/hive/branches/branch-0.4: CHANGES.txt
service/src/java/org/apache/hadoop/hive/service/HiveServer.java
service/src/test/org/apache/hadoop/hive/service/TestHiveServer.java
Author: namit
Date: Tue Sep 1 22:33:06 2009
New Revision: 810289
URL: http://svn.apache.org/viewvc?rev=810289&view=rev
Log:
HIVE-755. Driver NullPointerException when calling getResults without first compiling
(Eric Hwang via namit)
Modified:
hadoop/hive/branches/branch-0.4/CHANGES.txt
hadoop/hive/branches/branch-0.4/service/src/java/org/apache/hadoop/hive/service/HiveServer.java
hadoop/hive/branches/branch-0.4/service/src/test/org/apache/hadoop/hive/service/TestHiveServer.java
Modified: hadoop/hive/branches/branch-0.4/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/hive/branches/branch-0.4/CHANGES.txt?rev=810289&r1=810288&r2=810289&view=diff
==============================================================================
--- hadoop/hive/branches/branch-0.4/CHANGES.txt (original)
+++ hadoop/hive/branches/branch-0.4/CHANGES.txt Tue Sep 1 22:33:06 2009
@@ -534,6 +534,9 @@
HIVE-790. Bug in union and script. (Ning Zhang via namit)
+ HIVE-755. Driver NullPointerException when calling getResults without first compiling
+ (Eric Hwang via namit)
+
Release 0.3.1 - Unreleased
INCOMPATIBLE CHANGES
Modified: hadoop/hive/branches/branch-0.4/service/src/java/org/apache/hadoop/hive/service/HiveServer.java
URL: http://svn.apache.org/viewvc/hadoop/hive/branches/branch-0.4/service/src/java/org/apache/hadoop/hive/service/HiveServer.java?rev=810289&r1=810288&r2=810289&view=diff
==============================================================================
--- hadoop/hive/branches/branch-0.4/service/src/java/org/apache/hadoop/hive/service/HiveServer.java (original)
+++ hadoop/hive/branches/branch-0.4/service/src/java/org/apache/hadoop/hive/service/HiveServer.java Tue Sep 1 22:33:06 2009
@@ -70,6 +70,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());
@@ -79,6 +84,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;
@@ -105,8 +111,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);
}
}
@@ -162,6 +170,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) {
@@ -181,6 +193,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) {
@@ -203,8 +219,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);
@@ -232,7 +252,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);
@@ -251,6 +275,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/branches/branch-0.4/service/src/test/org/apache/hadoop/hive/service/TestHiveServer.java
URL: http://svn.apache.org/viewvc/hadoop/hive/branches/branch-0.4/service/src/test/org/apache/hadoop/hive/service/TestHiveServer.java?rev=810289&r1=810288&r2=810289&view=diff
==============================================================================
--- hadoop/hive/branches/branch-0.4/service/src/test/org/apache/hadoop/hive/service/TestHiveServer.java (original)
+++ hadoop/hive/branches/branch-0.4/service/src/test/org/apache/hadoop/hive/service/TestHiveServer.java Tue Sep 1 22:33:06 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
*/