SOLR-9246: If the JDBCStream sees an unknown column type it will now throw a detailed exception

This commit is contained in:
Dennis Gove 2016-06-29 14:27:56 -04:00
parent 7a8be18278
commit 1ae0d8d6e1
3 changed files with 22 additions and 0 deletions

View File

@ -96,6 +96,8 @@ Bug Fixes
* SOLR-8777: Duplicate Solr process can cripple a running process. (Jessica Cheng Mallet, Scott Blum, shalin)
* SOLR-9246: If the JDBCStream sees an unknown column type it will now throw a detailed exception. (Dennis Gove)
Optimizations
----------------------

View File

@ -225,6 +225,7 @@ public class JDBCStream extends TupleStream implements Expressible {
final int columnNumber = columnIdx + 1; // cause it starts at 1
final String columnName = metadata.getColumnName(columnNumber);
String className = metadata.getColumnClassName(columnNumber);
String typeName = metadata.getColumnTypeName(columnNumber);
if(directSupportedTypes.contains(className)){
valueSelectors[columnIdx] = new ResultSetValueSelector() {
@ -274,6 +275,9 @@ public class JDBCStream extends TupleStream implements Expressible {
}
};
}
else{
throw new SQLException(String.format(Locale.ROOT, "Unable to determine the valueSelector for column '%s' (col #%d) of java class '%s' and type '%s'", columnName, columnNumber, className, typeName));
}
}
return valueSelectors;

View File

@ -84,6 +84,7 @@ public class JDBCStreamTest extends SolrCloudTestCase {
statement.executeUpdate("create table COUNTRIES(CODE varchar(3) not null primary key, COUNTRY_NAME varchar(50), DELETED char(1) default 'N')");
statement.executeUpdate("create table PEOPLE(ID int not null primary key, NAME varchar(50), COUNTRY_CODE char(2), DELETED char(1) default 'N')");
statement.executeUpdate("create table PEOPLE_SPORTS(ID int not null primary key, PERSON_ID int, SPORT_NAME varchar(50), DELETED char(1) default 'N')");
statement.executeUpdate("create table UNSUPPORTED_COLUMNS(ID int not null primary key, UNSP binary)");
}
@ -109,6 +110,7 @@ public class JDBCStreamTest extends SolrCloudTestCase {
statement.executeUpdate("delete from COUNTRIES WHERE 1=1");
statement.executeUpdate("delete from PEOPLE WHERE 1=1");
statement.executeUpdate("delete from PEOPLE_SPORTS WHERE 1=1");
statement.executeUpdate("delete from UNSUPPORTED_COLUMNS WHERE 1=1");
}
}
@ -497,6 +499,20 @@ public class JDBCStreamTest extends SolrCloudTestCase {
}
@Test(expected=IOException.class)
public void testUnsupportedColumns() throws Exception {
// No need to load table with any data
TupleStream stream;
// Simple 1
stream = new JDBCStream("jdbc:hsqldb:mem:.", "select ID,UNSP from UNSUPPORTED_COLUMNS",
new FieldComparator("CODE", ComparatorOrder.ASCENDING));
getTuples(stream);
}
protected List<Tuple> getTuples(TupleStream tupleStream) throws IOException {
tupleStream.open();
List<Tuple> tuples = new ArrayList<Tuple>();