mirror of https://github.com/apache/nifi.git
parent
892c74dff2
commit
2fb3b01ebe
|
@ -258,7 +258,8 @@ public class JdbcCommon {
|
|||
* Some missing Avro types - Decimal, Date types. May need some additional work.
|
||||
*/
|
||||
for (int i = 1; i <= nrOfColumns; i++) {
|
||||
String columnName = convertNames ? normalizeNameForAvro(meta.getColumnName(i)) : meta.getColumnName(i);
|
||||
String nameOrLabel = StringUtils.isNotEmpty(meta.getColumnName(i)) ? meta.getColumnName(i) : meta.getColumnLabel(i);
|
||||
String columnName = convertNames ? normalizeNameForAvro(nameOrLabel) : nameOrLabel;
|
||||
switch (meta.getColumnType(i)) {
|
||||
case CHAR:
|
||||
case LONGNVARCHAR:
|
||||
|
|
|
@ -150,6 +150,31 @@ public class TestJdbcCommon {
|
|||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateSchemaOnlyColumnLabel() throws ClassNotFoundException, SQLException {
|
||||
|
||||
final ResultSet resultSet = mock(ResultSet.class);
|
||||
final ResultSetMetaData resultSetMetaData = mock(ResultSetMetaData.class);
|
||||
when(resultSet.getMetaData()).thenReturn(resultSetMetaData);
|
||||
when(resultSetMetaData.getColumnCount()).thenReturn(2);
|
||||
when(resultSetMetaData.getTableName(1)).thenReturn("TEST");
|
||||
when(resultSetMetaData.getColumnType(1)).thenReturn(Types.INTEGER);
|
||||
when(resultSetMetaData.getColumnName(1)).thenReturn("");
|
||||
when(resultSetMetaData.getColumnLabel(1)).thenReturn("ID");
|
||||
when(resultSetMetaData.getColumnType(2)).thenReturn(Types.VARCHAR);
|
||||
when(resultSetMetaData.getColumnName(2)).thenReturn("VCHARC");
|
||||
when(resultSetMetaData.getColumnLabel(2)).thenReturn("NOT_VCHARC");
|
||||
|
||||
final Schema schema = JdbcCommon.createSchema(resultSet);
|
||||
assertNotNull(schema);
|
||||
|
||||
assertNotNull(schema.getField("ID"));
|
||||
assertNotNull(schema.getField("VCHARC"));
|
||||
|
||||
// records name, should be result set first column table name
|
||||
assertEquals("TEST", schema.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertToBytes() throws ClassNotFoundException, SQLException, IOException {
|
||||
final Statement st = con.createStatement();
|
||||
|
|
Loading…
Reference in New Issue