Repository: nifi
Updated Branches:
  refs/heads/master c11954722 -> 7ff38f690


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


Project: http://git-wip-us.apache.org/repos/asf/nifi/repo
Commit: http://git-wip-us.apache.org/repos/asf/nifi/commit/7ff38f69
Tree: http://git-wip-us.apache.org/repos/asf/nifi/tree/7ff38f69
Diff: http://git-wip-us.apache.org/repos/asf/nifi/diff/7ff38f69

Branch: refs/heads/master
Commit: 7ff38f690d54cdc607383f1a4be252395b8c5c27
Parents: c119547
Author: Matthew Burgess <[email protected]>
Authored: Thu Apr 5 12:28:38 2018 -0400
Committer: Matt Gilman <[email protected]>
Committed: Thu Apr 5 16:03:42 2018 -0400

----------------------------------------------------------------------
 .../org/apache/nifi/processors/hive/PutHiveQL.java  | 16 +++++++++++++++-
 .../apache/nifi/processors/hive/TestPutHiveQL.java  |  3 ++-
 2 files changed, 17 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/nifi/blob/7ff38f69/nifi-nar-bundles/nifi-hive-bundle/nifi-hive-processors/src/main/java/org/apache/nifi/processors/hive/PutHiveQL.java
----------------------------------------------------------------------
diff --git 
a/nifi-nar-bundles/nifi-hive-bundle/nifi-hive-processors/src/main/java/org/apache/nifi/processors/hive/PutHiveQL.java
 
b/nifi-nar-bundles/nifi-hive-bundle/nifi-hive-processors/src/main/java/org/apache/nifi/processors/hive/PutHiveQL.java
index 93b07dc..c68bce8 100644
--- 
a/nifi-nar-bundles/nifi-hive-bundle/nifi-hive-processors/src/main/java/org/apache/nifi/processors/hive/PutHiveQL.java
+++ 
b/nifi-nar-bundles/nifi-hive-bundle/nifi-hive-processors/src/main/java/org/apache/nifi/processors/hive/PutHiveQL.java
@@ -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;
             }

http://git-wip-us.apache.org/repos/asf/nifi/blob/7ff38f69/nifi-nar-bundles/nifi-hive-bundle/nifi-hive-processors/src/test/java/org/apache/nifi/processors/hive/TestPutHiveQL.java
----------------------------------------------------------------------
diff --git 
a/nifi-nar-bundles/nifi-hive-bundle/nifi-hive-processors/src/test/java/org/apache/nifi/processors/hive/TestPutHiveQL.java
 
b/nifi-nar-bundles/nifi-hive-bundle/nifi-hive-processors/src/test/java/org/apache/nifi/processors/hive/TestPutHiveQL.java
index badc4d9..af737ae 100644
--- 
a/nifi-nar-bundles/nifi-hive-bundle/nifi-hive-processors/src/test/java/org/apache/nifi/processors/hive/TestPutHiveQL.java
+++ 
b/nifi-nar-bundles/nifi-hive-bundle/nifi-hive-processors/src/test/java/org/apache/nifi/processors/hive/TestPutHiveQL.java
@@ -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();

Reply via email to