NIFI-11647: Support UUID type in DataTypeUtils.getSQLTypeValue

This closes #7355

Signed-off-by: Mike Thomsen <mthomsen@apache.org>
This commit is contained in:
Matt Burgess 2023-06-07 16:07:37 -04:00 committed by Mike Thomsen
parent 119e6702a4
commit f3e8651522
2 changed files with 43 additions and 0 deletions

View File

@ -2150,6 +2150,7 @@ public class DataTypeUtils {
case SHORT:
return Types.SMALLINT;
case STRING:
case UUID:
return Types.VARCHAR;
case ENUM:
return Types.OTHER;

View File

@ -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()) {