Skip to content

Commit

Permalink
HIVE-3001 Returning Meaningful Error Codes & Messages
Browse files Browse the repository at this point in the history
(Bhushan Mandhani via namit)



git-svn-id: https://svn.apache.org/repos/asf/hive/trunk@1338537 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
Namit Jain committed May 15, 2012
1 parent ca9feed commit 5195c7a
Show file tree
Hide file tree
Showing 272 changed files with 839 additions and 715 deletions.
Expand Up @@ -12,4 +12,4 @@ PREHOOK: type: CREATEFUNCTION
POSTHOOK: query: create temporary function row_sequence as
'org.apache.hadoop.hive.contrib.udf.UDFRowSequence'
POSTHOOK: type: CREATEFUNCTION
FAILED: Error in semantic analysis: Stateful UDF's can only be invoked in the SELECT list
FAILED: SemanticException [Error 10084]: Stateful UDF's can only be invoked in the SELECT list
Expand Up @@ -2,4 +2,4 @@ PREHOOK: query: CREATE TEMPORARY FUNCTION explode2 AS 'org.apache.hadoop.hive.co
PREHOOK: type: CREATEFUNCTION
POSTHOOK: query: CREATE TEMPORARY FUNCTION explode2 AS 'org.apache.hadoop.hive.contrib.udtf.example.GenericUDTFExplode2'
POSTHOOK: type: CREATEFUNCTION
FAILED: Error in semantic analysis: The number of aliases supplied in the AS clause does not match the number of columns output by the UDTF expected 2 aliases but got 1
FAILED: SemanticException [Error 10083]: The number of aliases supplied in the AS clause does not match the number of columns output by the UDTF expected 2 aliases but got 1
25 changes: 10 additions & 15 deletions jdbc/src/test/org/apache/hadoop/hive/jdbc/TestJdbcDriver.java
Expand Up @@ -496,35 +496,30 @@ private void doTestSelectAll(String tableName, int maxRows, int fetchSize) throw

public void testErrorMessages() throws SQLException {
String invalidSyntaxSQLState = "42000";
int parseErrorCode = 10;

// These tests inherently cause exceptions to be written to the test output
// logs. This is undesirable, since you it might appear to someone looking
// at the test output logs as if something is failing when it isn't. Not
// sure
// how to get around that.
doTestErrorCase("SELECTT * FROM " + tableName,
"cannot recognize input near 'SELECTT' '*' 'FROM'", invalidSyntaxSQLState, 11);
"cannot recognize input near 'SELECTT' '*' 'FROM'",
invalidSyntaxSQLState, 40000);
doTestErrorCase("SELECT * FROM some_table_that_does_not_exist",
"Table not found", "42000", parseErrorCode);
"Table not found", "42S02", 10001);
doTestErrorCase("drop table some_table_that_does_not_exist",
"Table not found", "42000", parseErrorCode);
"Table not found", "42S02", 10001);
doTestErrorCase("SELECT invalid_column FROM " + tableName,
"Invalid table alias or column reference", invalidSyntaxSQLState,
parseErrorCode);
"Invalid table alias or column reference", invalidSyntaxSQLState, 10004);
doTestErrorCase("SELECT invalid_function(under_col) FROM " + tableName,
"Invalid function", invalidSyntaxSQLState, parseErrorCode);
"Invalid function", invalidSyntaxSQLState, 10011);

// TODO: execute errors like this currently don't return good messages (i.e.
// 'Table already exists'). This is because the Driver class calls
// Task.executeTask() which swallows meaningful exceptions and returns a
// status
// code. This should be refactored.
// TODO: execute errors like this currently don't return good error
// codes and messages. This should be fixed.
doTestErrorCase(
"create table " + tableName + " (key int, value string)",
"Query returned non-zero code: 9, cause: FAILED: Execution Error, "
+ "return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask",
"08S01", 9);
"FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask",
"08S01", 1);
}

private void doTestErrorCase(String sql, String expectedMessage,
Expand Down
38 changes: 18 additions & 20 deletions ql/src/java/org/apache/hadoop/hive/ql/Driver.java
Expand Up @@ -82,7 +82,6 @@
import org.apache.hadoop.hive.ql.parse.ASTNode;
import org.apache.hadoop.hive.ql.parse.AbstractSemanticAnalyzerHook;
import org.apache.hadoop.hive.ql.parse.BaseSemanticAnalyzer;
import org.apache.hadoop.hive.ql.parse.ErrorMsg;
import org.apache.hadoop.hive.ql.parse.HiveSemanticAnalyzerHookContext;
import org.apache.hadoop.hive.ql.parse.HiveSemanticAnalyzerHookContextImpl;
import org.apache.hadoop.hive.ql.parse.ImportSemanticAnalyzer;
Expand Down Expand Up @@ -496,24 +495,17 @@ public int compile(String command, boolean resetTaskIds) {
//restore state after we're done executing a specific query

return 0;
} catch (SemanticException e) {
errorMessage = "FAILED: Error in semantic analysis: " + e.getMessage();
SQLState = ErrorMsg.findSQLState(e.getMessage());
console.printError(errorMessage, "\n"
+ org.apache.hadoop.util.StringUtils.stringifyException(e));
return (10);
} catch (ParseException e) {
errorMessage = "FAILED: Parse Error: " + e.getMessage();
SQLState = ErrorMsg.findSQLState(e.getMessage());
console.printError(errorMessage, "\n"
+ org.apache.hadoop.util.StringUtils.stringifyException(e));
return (11);
} catch (Exception e) {
errorMessage = "FAILED: Hive Internal Error: " + Utilities.getNameMessage(e);
SQLState = ErrorMsg.findSQLState(e.getMessage());
console.printError(errorMessage + "\n"
ErrorMsg error = ErrorMsg.getErrorMsg(e.getMessage());
errorMessage = "FAILED: " + e.getClass().getSimpleName();
if (error != ErrorMsg.GENERIC_ERROR) {
errorMessage += " [Error " + error.getErrorCode() + "]:";
}
errorMessage += " " + e.getMessage();
SQLState = error.getSQLState();
console.printError(errorMessage, "\n"
+ org.apache.hadoop.util.StringUtils.stringifyException(e));
return (12);
return error.getErrorCode();
} finally {
perfLogger.PerfLogEnd(LOG, PerfLogger.COMPILE);
restoreSession(queryState);
Expand Down Expand Up @@ -1137,8 +1129,11 @@ public int execute() throws CommandNeedRetryException {
if (backupTask != null) {
errorMessage = "FAILED: Execution Error, return code " + exitVal + " from "
+ tsk.getClass().getName();
ErrorMsg em = ErrorMsg.getErrorMsg(exitVal);
if (em != null) {
errorMessage += ". " + em.getMsg();
}
console.printError(errorMessage);

errorMessage = "ATTEMPT: Execute BackupTask: " + backupTask.getClass().getName();
console.printError(errorMessage);

Expand All @@ -1159,9 +1154,12 @@ public int execute() throws CommandNeedRetryException {
perfLogger.PerfLogEnd(LOG, PerfLogger.FAILURE_HOOK + ofh.getClass().getName());
}

// TODO: This error messaging is not very informative. Fix that.
errorMessage = "FAILED: Execution Error, return code " + exitVal + " from "
+ tsk.getClass().getName();
ErrorMsg em = ErrorMsg.getErrorMsg(exitVal);
if (em != null) {
errorMessage += ". " + em.getMsg();
}
SQLState = "08S01";
console.printError(errorMessage);
if (running.size() != 0) {
Expand All @@ -1170,7 +1168,7 @@ public int execute() throws CommandNeedRetryException {
// in case we decided to run everything in local mode, restore the
// the jobtracker setting to its initial value
ctx.restoreOriginalTracker();
return 9;
return exitVal;
}
}

Expand Down

0 comments on commit 5195c7a

Please sign in to comment.