NIFI-5045: Fixed error code handling in PutHiveQL. This closes #2608

This commit is contained in:
Matthew Burgess 2018-04-05 12:28:38 -04:00 committed by Matt Gilman
parent c119547222
commit 7ff38f690d
No known key found for this signature in database
GPG Key ID: DF61EC19432AEE37
2 changed files with 17 additions and 2 deletions

View File

@ -146,7 +146,21 @@ public class PutHiveQL extends AbstractHiveQLProcessor {
if (e instanceof SQLNonTransientException) {
return ErrorTypes.InvalidInput;
} else if (e instanceof SQLException) {
return ErrorTypes.TemporalFailure;
// Use the SQLException's vendor code for guidance -- see Hive's ErrorMsg class for details on error codes
int errorCode = ((SQLException) e).getErrorCode();
if (errorCode >= 10000 && errorCode < 20000) {
return ErrorTypes.InvalidInput;
} else if (errorCode >= 20000 && errorCode < 30000) {
return ErrorTypes.TemporalFailure;
} else if (errorCode >= 30000 && errorCode < 40000) {
return ErrorTypes.TemporalInputFailure;
} else if (errorCode >= 40000 && errorCode < 50000) {
// These are unknown errors (to include some parse errors), but rather than generating an UnknownFailure which causes
// a ProcessException, we'll route to failure via an InvalidInput error type.
return ErrorTypes.InvalidInput;
} else {
return ErrorTypes.UnknownFailure;
}
} else {
return ErrorTypes.UnknownFailure;
}

View File

@ -773,7 +773,8 @@ public class TestPutHiveQL {
try {
if (++successful > allowedBeforeFailure) {
final Connection conn = Mockito.mock(Connection.class);
Mockito.when(conn.prepareStatement(Mockito.any(String.class))).thenThrow(new SQLException("Unit Test Generated SQLException"));
// Throw a retryable error
Mockito.when(conn.prepareStatement(Mockito.any(String.class))).thenThrow(new SQLException("Unit Test Generated SQLException", "42000", 20000));
return conn;
} else {
return service.getConnection();