You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by ma...@apache.org on 2017/04/25 14:00:03 UTC
nifi git commit: NIFI-2323: Fixed Oracle timestamp handling in DB
fetch processors. This closes #1664.
Repository: nifi
Updated Branches:
refs/heads/master 995c7ce2f -> 9ed001869
NIFI-2323: Fixed Oracle timestamp handling in DB fetch processors. This closes #1664.
Project: http://git-wip-us.apache.org/repos/asf/nifi/repo
Commit: http://git-wip-us.apache.org/repos/asf/nifi/commit/9ed00186
Tree: http://git-wip-us.apache.org/repos/asf/nifi/tree/9ed00186
Diff: http://git-wip-us.apache.org/repos/asf/nifi/diff/9ed00186
Branch: refs/heads/master
Commit: 9ed001869b4887f57e108764354557391092ecab
Parents: 995c7ce
Author: Matt Burgess <ma...@apache.org>
Authored: Mon Apr 17 22:40:47 2017 -0400
Committer: Mark Payne <ma...@hotmail.com>
Committed: Tue Apr 25 09:59:43 2017 -0400
----------------------------------------------------------------------
.../AbstractDatabaseFetchProcessor.java | 42 ++++++++++----------
.../standard/QueryDatabaseTableTest.java | 2 +-
2 files changed, 22 insertions(+), 22 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/nifi/blob/9ed00186/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/AbstractDatabaseFetchProcessor.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/AbstractDatabaseFetchProcessor.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/AbstractDatabaseFetchProcessor.java
index 71b287b..1d943f4 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/AbstractDatabaseFetchProcessor.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/AbstractDatabaseFetchProcessor.java
@@ -181,7 +181,7 @@ public abstract class AbstractDatabaseFetchProcessor extends AbstractSessionFact
ServiceLoader<DatabaseAdapter> dbAdapterLoader = ServiceLoader.load(DatabaseAdapter.class);
dbAdapterLoader.forEach(it -> {
dbAdapters.put(it.getName(), it);
- dbAdapterValues.add(new AllowableValue(it.getName(),it.getName(), it.getDescription()));
+ dbAdapterValues.add(new AllowableValue(it.getName(), it.getName(), it.getDescription()));
});
DB_TYPE = new PropertyDescriptor.Builder()
@@ -351,27 +351,21 @@ public abstract class AbstractDatabaseFetchProcessor extends AbstractSessionFact
break;
case TIMESTAMP:
- // Oracle timestamp queries must use literals in java.sql.Date format
- if ("Oracle".equals(databaseType)) {
- Date rawColOracleTimestampValue = resultSet.getDate(columnIndex);
- java.sql.Date oracleTimestampValue = new java.sql.Date(rawColOracleTimestampValue.getTime());
- java.sql.Date maxOracleTimestampValue = null;
- if (maxValueString != null) {
- maxOracleTimestampValue = java.sql.Date.valueOf(maxValueString);
- }
- if (maxOracleTimestampValue == null || oracleTimestampValue.after(maxOracleTimestampValue)) {
- return oracleTimestampValue.toString();
- }
- } else {
- Timestamp colTimestampValue = resultSet.getTimestamp(columnIndex);
- java.sql.Timestamp maxTimestampValue = null;
- if (maxValueString != null) {
+ Timestamp colTimestampValue = resultSet.getTimestamp(columnIndex);
+ java.sql.Timestamp maxTimestampValue = null;
+ if (maxValueString != null) {
+ // For backwards compatibility, the type might be TIMESTAMP but the state value is in DATE format. This should be a one-time occurrence as the next maximum value
+ // should be stored as a full timestamp. Even so, check to see if the value is missing time-of-day information, and use the "date" coercion rather than the
+ // "timestamp" coercion in that case
+ try {
maxTimestampValue = java.sql.Timestamp.valueOf(maxValueString);
- }
- if (maxTimestampValue == null || colTimestampValue.after(maxTimestampValue)) {
- return colTimestampValue.toString();
+ } catch (IllegalArgumentException iae) {
+ maxTimestampValue = new java.sql.Timestamp(java.sql.Date.valueOf(maxValueString).getTime());
}
}
+ if (maxTimestampValue == null || colTimestampValue.after(maxTimestampValue)) {
+ return colTimestampValue.toString();
+ }
break;
case BIT:
@@ -411,9 +405,15 @@ public abstract class AbstractDatabaseFetchProcessor extends AbstractSessionFact
case TIME:
return "'" + value + "'";
case TIMESTAMP:
- // Timestamp literals in Oracle need to be cast with TO_DATE
if ("Oracle".equals(databaseType)) {
- return "to_date('" + value + "', 'yyyy-mm-dd HH24:MI:SS')";
+ // For backwards compatibility, the type might be TIMESTAMP but the state value is in DATE format. This should be a one-time occurrence as the next maximum value
+ // should be stored as a full timestamp. Even so, check to see if the value is missing time-of-day information, and use the "date" coercion rather than the
+ // "timestamp" coercion in that case
+ if (value.matches("\\d{4}-\\d{2}-\\d{2}")) {
+ return "date '" + value + "'";
+ } else {
+ return "timestamp '" + value + "'";
+ }
} else {
return "'" + value + "'";
}
http://git-wip-us.apache.org/repos/asf/nifi/blob/9ed00186/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/QueryDatabaseTableTest.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/QueryDatabaseTableTest.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/QueryDatabaseTableTest.java
index 6af59eb..b015371 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/QueryDatabaseTableTest.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/QueryDatabaseTableTest.java
@@ -157,7 +157,7 @@ public class QueryDatabaseTableTest {
// Test Oracle strategy
dbAdapter = new OracleDatabaseAdapter();
query = processor.getQuery(dbAdapter, "myTable", null, Arrays.asList("id", "DATE_CREATED"), stateManager.getState(Scope.CLUSTER).toMap());
- assertEquals("SELECT * FROM myTable WHERE id > 509 AND DATE_CREATED >= to_date('2016-03-07 12:34:56', 'yyyy-mm-dd HH24:MI:SS')", query);
+ assertEquals("SELECT * FROM myTable WHERE id > 509 AND DATE_CREATED >= timestamp '2016-03-07 12:34:56'", query);
}
@Test(expected = IllegalArgumentException.class)