NIFI-1596: ExecuteSQL Error Creating Schema

This commit is contained in:
Matt Burgess 2016-03-07 09:10:05 -05:00
parent 19e53962ca
commit a7e6820fd9
2 changed files with 20 additions and 1 deletions

View File

@ -130,7 +130,7 @@ public class JdbcCommon {
String tableName = "NiFi_ExecuteSQL_Record"; String tableName = "NiFi_ExecuteSQL_Record";
if(nrOfColumns > 0) { if(nrOfColumns > 0) {
String tableNameFromMeta = meta.getTableName(1); String tableNameFromMeta = meta.getTableName(1);
if (!StringUtils.isBlank(tableName)) { if (!StringUtils.isBlank(tableNameFromMeta)) {
tableName = tableNameFromMeta; tableName = tableNameFromMeta;
} }
} }

View File

@ -123,6 +123,25 @@ public class TestJdbcCommon {
} }
@Test
public void testCreateSchemaNoTableName() throws ClassNotFoundException, SQLException {
final ResultSet resultSet = mock(ResultSet.class);
final ResultSetMetaData resultSetMetaData = mock(ResultSetMetaData.class);
when(resultSet.getMetaData()).thenReturn(resultSetMetaData);
when(resultSetMetaData.getColumnCount()).thenReturn(1);
when(resultSetMetaData.getTableName(1)).thenReturn("");
when(resultSetMetaData.getColumnType(1)).thenReturn(Types.INTEGER);
when(resultSetMetaData.getColumnName(1)).thenReturn("ID");
final Schema schema = JdbcCommon.createSchema(resultSet);
assertNotNull(schema);
// records name, should be result set first column table name
assertEquals("NiFi_ExecuteSQL_Record", schema.getName());
}
@Test @Test
public void testConvertToBytes() throws ClassNotFoundException, SQLException, IOException { public void testConvertToBytes() throws ClassNotFoundException, SQLException, IOException {
// remove previous test database, if any // remove previous test database, if any