SOLR-11420: sql Streaming Expression should use the default collection if none is provided

This commit is contained in:
Joel Bernstein 2017-09-29 10:36:26 -04:00
parent 633af79406
commit 71eb59e043
3 changed files with 17 additions and 6 deletions

View File

@ -73,12 +73,7 @@ public class SqlStream extends TupleStream implements Expressible {
// Collection Name
if(null == collectionName){
throw new IOException(String.format(Locale.ROOT,"invalid expression %s - collectionName expected as first operand",expression));
}
// Validate there are no unknown parameters - zkHost and alias are namedParameter so we don't need to count it twice
if(expression.getParameters().size() != 1 + namedParams.size()){
throw new IOException(String.format(Locale.ROOT,"invalid expression %s - unknown operands found",expression));
collectionName = factory.getDefaultCollection();
}
// Named parameters - passed directly to solr as solrparams

View File

@ -46,6 +46,7 @@ public class StreamFactory implements Serializable {
private transient HashMap<String,String> collectionZkHosts;
private transient HashMap<String,Class<? extends Expressible>> functionNames;
private transient String defaultZkHost;
private transient String defaultCollection;
public StreamFactory(){
collectionZkHosts = new HashMap<>();
@ -54,9 +55,14 @@ public class StreamFactory implements Serializable {
public StreamFactory withCollectionZkHost(String collectionName, String zkHost){
this.collectionZkHosts.put(collectionName, zkHost);
this.defaultCollection = collectionName;
return this;
}
public String getDefaultCollection() {
return defaultCollection;
}
public StreamFactory withDefaultZkHost(String zkHost) {
this.defaultZkHost = zkHost;
return this;

View File

@ -279,6 +279,16 @@ public class StreamExpressionTest extends SolrCloudTestCase {
assert (tuples.size() == 5);
assertOrder(tuples, 0, 1, 2, 3, 4);
//Test with using the default collection
solrParams = new ModifiableSolrParams();
solrParams.add("qt", "/stream");
solrParams.add("expr", "sql(stmt=\"select id from collection1 order by a_i asc\")");
solrStream = new SolrStream(shardUrls.get(0), solrParams);
solrStream.setStreamContext(streamContext);
tuples = getTuples(solrStream);
assert (tuples.size() == 5);
assertOrder(tuples, 0, 1, 2, 3, 4);
} finally {
solrClientCache.close();
}