This is an automated email from the ASF dual-hosted git repository. mthomsen pushed a commit to branch support/nifi-1.x in repository https://gitbox.apache.org/repos/asf/nifi.git
The following commit(s) were added to refs/heads/support/nifi-1.x by this push: new e872c26178 NIFI-11647: Support UUID type in DataTypeUtils.getSQLTypeValue e872c26178 is described below commit e872c2617824514aee0d1fc33d3de952e398d901 Author: Matt Burgess <mattyb...@apache.org> AuthorDate: Wed Jun 7 16:07:37 2023 -0400 NIFI-11647: Support UUID type in DataTypeUtils.getSQLTypeValue This closes #7355 Signed-off-by: Mike Thomsen <mthom...@apache.org> --- .../serialization/record/util/DataTypeUtils.java | 1 + .../processors/standard/PutDatabaseRecordTest.java | 42 ++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/nifi-commons/nifi-record/src/main/java/org/apache/nifi/serialization/record/util/DataTypeUtils.java b/nifi-commons/nifi-record/src/main/java/org/apache/nifi/serialization/record/util/DataTypeUtils.java index 53eb8a68f9..8752d85b19 100644 --- a/nifi-commons/nifi-record/src/main/java/org/apache/nifi/serialization/record/util/DataTypeUtils.java +++ b/nifi-commons/nifi-record/src/main/java/org/apache/nifi/serialization/record/util/DataTypeUtils.java @@ -2150,6 +2150,7 @@ public class DataTypeUtils { case SHORT: return Types.SMALLINT; case STRING: + case UUID: return Types.VARCHAR; case ENUM: return Types.OTHER; diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/PutDatabaseRecordTest.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/PutDatabaseRecordTest.java index 182e86eaf5..8de18420b1 100644 --- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/PutDatabaseRecordTest.java +++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/PutDatabaseRecordTest.java @@ -93,6 +93,8 @@ public class PutDatabaseRecordTest { private static final String createPersonsSchema2 = "CREATE TABLE SCHEMA2.PERSONS (id2 integer primary key, name varchar(100)," + " code integer CONSTRAINT CODE_RANGE CHECK (code >= 0 AND code < 1000), dt date)"; + private static final String createUUIDSchema = "CREATE TABLE UUID_TEST (id integer primary key, name VARCHAR(100))"; + private final static String DB_LOCATION = "target/db_pdr"; TestRunner runner; @@ -1802,6 +1804,46 @@ public class PutDatabaseRecordTest { conn.close(); } + @Test + void testInsertUUIDColumn() throws InitializationException, ProcessException, SQLException { + // Manually create and drop the tables and schemas + final Connection conn = dbcp.getConnection(); + final Statement stmt = conn.createStatement(); + stmt.execute(createUUIDSchema); + + final MockRecordParser parser = new MockRecordParser(); + runner.addControllerService("parser", parser); + runner.enableControllerService(parser); + + parser.addSchemaField("id", RecordFieldType.INT); + parser.addSchemaField("name", RecordFieldType.UUID); + + parser.addRecord(1, "425085a0-03ef-11ee-be56-0242ac120002"); + parser.addRecord(2, "56a000e4-03ef-11ee-be56-0242ac120002"); + + runner.setProperty(PutDatabaseRecord.RECORD_READER_FACTORY, "parser"); + runner.setProperty(PutDatabaseRecord.STATEMENT_TYPE, PutDatabaseRecord.INSERT_TYPE); + runner.setProperty(PutDatabaseRecord.TABLE_NAME, "UUID_TEST"); + + runner.enqueue(new byte[0]); + runner.run(); + + runner.assertTransferCount(PutDatabaseRecord.REL_SUCCESS, 1); + ResultSet rs = stmt.executeQuery("SELECT * FROM UUID_TEST"); + assertTrue(rs.next()); + assertEquals(1, rs.getInt(1)); + assertEquals("425085a0-03ef-11ee-be56-0242ac120002", rs.getString(2)); + assertTrue(rs.next()); + assertEquals(2, rs.getInt(1)); + assertEquals("56a000e4-03ef-11ee-be56-0242ac120002", rs.getString(2)); + assertFalse(rs.next()); + + // Drop the schemas here so as not to interfere with other tests + stmt.execute("drop table UUID_TEST"); + stmt.close(); + conn.close(); + } + private void recreateTable() throws ProcessException { try (final Connection conn = dbcp.getConnection(); final Statement stmt = conn.createStatement()) {