Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

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

Dennis Gove1ae0d8d6e139
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index e7b8dd1f118..7fdba2c419e 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -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
----------------------
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/JDBCStream.java b/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/JDBCStream.java
index d1a301e1276..f57beac8aa4 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/JDBCStream.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/JDBCStream.java
@@ -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;
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/JDBCStreamTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/JDBCStreamTest.java
index 0315cfec0e1..980d0e772b8 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/JDBCStreamTest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/JDBCStreamTest.java
@@ -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>();