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/8f988c3b Tree: http://git-wip-us.apache.org/repos/asf/nifi/tree/8f988c3b Diff: http://git-wip-us.apache.org/repos/asf/nifi/diff/8f988c3b Branch: refs/heads/HDF-3.1-maint Commit: 8f988c3b8a11f643e74580d08716d88090f6d143 Parents: 8a97e3e Author: Matthew Burgess <[email protected]> Authored: Thu Apr 5 12:28:38 2018 -0400 Committer: Matt Gilman <[email protected]> Committed: Fri Apr 13 08:20:56 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/8f988c3b/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/8f988c3b/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();
