-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NIFI-2829 Date and Time Format Support for PutSQL #1524
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -351,6 +351,77 @@ public void testUsingTimestampValuesWithFormatAttribute() throws InitializationE | |
} | ||
} | ||
|
||
@Test | ||
public void testUsingDateTimeValuesWithFormatAttribute() throws InitializationException, ProcessException, SQLException, IOException, ParseException { | ||
final TestRunner runner = TestRunners.newTestRunner(PutSQL.class); | ||
try (final Connection conn = service.getConnection()) { | ||
try (final Statement stmt = conn.createStatement()) { | ||
stmt.executeUpdate("CREATE TABLE TIMESTAMPTEST3 (id integer primary key, ts1 TIME, ts2 DATE)"); | ||
} | ||
} | ||
|
||
runner.addControllerService("dbcp", service); | ||
runner.enableControllerService(service); | ||
runner.setProperty(PutSQL.CONNECTION_POOL, "dbcp"); | ||
|
||
final String dateStr = "2002-02-02"; | ||
final String timeStr = "12:02:02"; | ||
|
||
Map<String, String> attributes = new HashMap<>(); | ||
attributes.put("sql.args.1.type", String.valueOf(Types.TIME)); | ||
attributes.put("sql.args.1.value", timeStr); | ||
attributes.put("sql.args.1.format", "ISO_LOCAL_TIME"); | ||
attributes.put("sql.args.2.type", String.valueOf(Types.DATE)); | ||
attributes.put("sql.args.2.value", dateStr); | ||
attributes.put("sql.args.2.format", "ISO_LOCAL_DATE"); | ||
|
||
runner.enqueue("INSERT INTO TIMESTAMPTEST3 (ID, ts1, ts2) VALUES (1, ?, ?)".getBytes(), attributes); | ||
|
||
attributes = new HashMap<>(); | ||
attributes.put("sql.args.1.type", String.valueOf(Types.TIME)); | ||
attributes.put("sql.args.1.value", "68522000"); | ||
attributes.put("sql.args.2.type", String.valueOf(Types.DATE)); | ||
attributes.put("sql.args.2.value", "1012633200000"); | ||
|
||
runner.enqueue("INSERT INTO TIMESTAMPTEST3 (ID, ts1, ts2) VALUES (2, ?, ?)".getBytes(), attributes); | ||
|
||
attributes = new HashMap<>(); | ||
attributes.put("sql.args.1.type", String.valueOf(Types.TIME)); | ||
attributes.put("sql.args.1.value", "120202000"); | ||
attributes.put("sql.args.1.format", "HHmmssSSS"); | ||
attributes.put("sql.args.2.type", String.valueOf(Types.DATE)); | ||
attributes.put("sql.args.2.value", "20020202"); | ||
attributes.put("sql.args.2.format", "yyyyMMdd"); | ||
|
||
runner.enqueue("INSERT INTO TIMESTAMPTEST3 (ID, ts1, ts2) VALUES (3, ?, ?)".getBytes(), attributes); | ||
|
||
runner.run(); | ||
|
||
runner.assertAllFlowFilesTransferred(PutSQL.REL_SUCCESS, 3); | ||
|
||
try (final Connection conn = service.getConnection()) { | ||
try (final Statement stmt = conn.createStatement()) { | ||
final ResultSet rs = stmt.executeQuery("SELECT * FROM TIMESTAMPTEST3 ORDER BY ID"); | ||
assertTrue(rs.next()); | ||
assertEquals(1, rs.getInt(1)); | ||
assertEquals(68522000L, rs.getTime(2).getTime()); | ||
assertEquals(1012633200000L, rs.getDate(3).getTime()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same goes for this guy. Are the second and third flow files supposed to put in UTC-based dates/times? Or will they be local as well? If the latter then the same change of constants will be needed for the asserts below. |
||
|
||
assertTrue(rs.next()); | ||
assertEquals(2, rs.getInt(1)); | ||
assertEquals(68522000L, rs.getTime(2).getTime()); | ||
assertEquals(1012633200000L, rs.getDate(3).getTime()); | ||
|
||
assertTrue(rs.next()); | ||
assertEquals(3, rs.getInt(1)); | ||
assertEquals(68522000L, rs.getTime(2).getTime()); | ||
assertEquals(1012633200000L, rs.getDate(3).getTime()); | ||
|
||
assertFalse(rs.next()); | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
public void testBitType() throws SQLException, InitializationException { | ||
final TestRunner runner = TestRunners.newTestRunner(PutSQL.class); | ||
|
@@ -468,6 +539,91 @@ public void testBitType() throws SQLException, InitializationException { | |
|
||
} | ||
|
||
@Test | ||
public void testUsingTimeValuesEpochAndString() throws InitializationException, ProcessException, SQLException, IOException, ParseException { | ||
final TestRunner runner = TestRunners.newTestRunner(PutSQL.class); | ||
try (final Connection conn = service.getConnection()) { | ||
try (final Statement stmt = conn.createStatement()) { | ||
stmt.executeUpdate("CREATE TABLE TIMETESTS (id integer primary key, ts1 time, ts2 time)"); | ||
} | ||
} | ||
|
||
runner.addControllerService("dbcp", service); | ||
runner.enableControllerService(service); | ||
runner.setProperty(PutSQL.CONNECTION_POOL, "dbcp"); | ||
|
||
final String arg2TS = "00:01:01"; | ||
final String art3TS = "12:02:02"; | ||
final String timeFormatString = "HH:mm:ss"; | ||
SimpleDateFormat dateFormat = new SimpleDateFormat(timeFormatString); | ||
java.util.Date parsedDate = dateFormat.parse(arg2TS); | ||
|
||
final Map<String, String> attributes = new HashMap<>(); | ||
attributes.put("sql.args.1.type", String.valueOf(Types.TIME)); | ||
attributes.put("sql.args.1.value", Long.toString(parsedDate.getTime())); | ||
|
||
attributes.put("sql.args.2.type", String.valueOf(Types.TIME)); | ||
attributes.put("sql.args.2.value", art3TS); | ||
attributes.put("sql.args.2.format", timeFormatString); | ||
|
||
runner.enqueue("INSERT INTO TIMETESTS (ID, ts1, ts2) VALUES (1, ?, ?)".getBytes(), attributes); | ||
runner.run(); | ||
|
||
runner.assertAllFlowFilesTransferred(PutSQL.REL_SUCCESS, 1); | ||
|
||
try (final Connection conn = service.getConnection()) { | ||
try (final Statement stmt = conn.createStatement()) { | ||
final ResultSet rs = stmt.executeQuery("SELECT * FROM TIMETESTS"); | ||
assertTrue(rs.next()); | ||
assertEquals(1, rs.getInt(1)); | ||
assertEquals(arg2TS, rs.getString(2)); | ||
assertEquals(art3TS, rs.getString(3)); | ||
assertFalse(rs.next()); | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
public void testUsingDateValuesEpochAndString() throws InitializationException, ProcessException, SQLException, IOException, ParseException { | ||
final TestRunner runner = TestRunners.newTestRunner(PutSQL.class); | ||
try (final Connection conn = service.getConnection()) { | ||
try (final Statement stmt = conn.createStatement()) { | ||
stmt.executeUpdate("CREATE TABLE DATETESTS (id integer primary key, ts1 date, ts2 date)"); | ||
} | ||
} | ||
|
||
runner.addControllerService("dbcp", service); | ||
runner.enableControllerService(service); | ||
runner.setProperty(PutSQL.CONNECTION_POOL, "dbcp"); | ||
|
||
final String arg2TS = "2001-01-01"; | ||
final String art3TS = "2002-02-02"; | ||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); | ||
java.util.Date parsedDate = dateFormat.parse(arg2TS); | ||
|
||
final Map<String, String> attributes = new HashMap<>(); | ||
attributes.put("sql.args.1.type", String.valueOf(Types.DATE)); | ||
attributes.put("sql.args.1.value", Long.toString(parsedDate.getTime())); | ||
attributes.put("sql.args.2.type", String.valueOf(Types.DATE)); | ||
attributes.put("sql.args.2.value", art3TS); | ||
|
||
runner.enqueue("INSERT INTO DATETESTS (ID, ts1, ts2) VALUES (1, ?, ?)".getBytes(), attributes); | ||
runner.run(); | ||
|
||
runner.assertAllFlowFilesTransferred(PutSQL.REL_SUCCESS, 1); | ||
|
||
try (final Connection conn = service.getConnection()) { | ||
try (final Statement stmt = conn.createStatement()) { | ||
final ResultSet rs = stmt.executeQuery("SELECT * FROM DATETESTS"); | ||
assertTrue(rs.next()); | ||
assertEquals(1, rs.getInt(1)); | ||
assertEquals(arg2TS, rs.getString(2)); | ||
assertEquals(art3TS, rs.getString(3)); | ||
assertFalse(rs.next()); | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
public void testBinaryColumnTypes() throws InitializationException, ProcessException, SQLException, IOException, ParseException { | ||
final TestRunner runner = TestRunners.newTestRunner(PutSQL.class); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assert is failing for me, presumably because the format was ISO_LOCAL_TIME and I am at -0500 UTC. Perhaps change the constant to something that takes timezone into account?