mirror of https://github.com/apache/lucene.git
SOLR-11420: sql Streaming Expression should use the default collection if none is provided
This commit is contained in:
parent
633af79406
commit
71eb59e043
|
@ -73,12 +73,7 @@ public class SqlStream extends TupleStream implements Expressible {
|
||||||
|
|
||||||
// Collection Name
|
// Collection Name
|
||||||
if(null == collectionName){
|
if(null == collectionName){
|
||||||
throw new IOException(String.format(Locale.ROOT,"invalid expression %s - collectionName expected as first operand",expression));
|
collectionName = factory.getDefaultCollection();
|
||||||
}
|
|
||||||
|
|
||||||
// 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));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Named parameters - passed directly to solr as solrparams
|
// Named parameters - passed directly to solr as solrparams
|
||||||
|
|
|
@ -46,6 +46,7 @@ public class StreamFactory implements Serializable {
|
||||||
private transient HashMap<String,String> collectionZkHosts;
|
private transient HashMap<String,String> collectionZkHosts;
|
||||||
private transient HashMap<String,Class<? extends Expressible>> functionNames;
|
private transient HashMap<String,Class<? extends Expressible>> functionNames;
|
||||||
private transient String defaultZkHost;
|
private transient String defaultZkHost;
|
||||||
|
private transient String defaultCollection;
|
||||||
|
|
||||||
public StreamFactory(){
|
public StreamFactory(){
|
||||||
collectionZkHosts = new HashMap<>();
|
collectionZkHosts = new HashMap<>();
|
||||||
|
@ -54,9 +55,14 @@ public class StreamFactory implements Serializable {
|
||||||
|
|
||||||
public StreamFactory withCollectionZkHost(String collectionName, String zkHost){
|
public StreamFactory withCollectionZkHost(String collectionName, String zkHost){
|
||||||
this.collectionZkHosts.put(collectionName, zkHost);
|
this.collectionZkHosts.put(collectionName, zkHost);
|
||||||
|
this.defaultCollection = collectionName;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getDefaultCollection() {
|
||||||
|
return defaultCollection;
|
||||||
|
}
|
||||||
|
|
||||||
public StreamFactory withDefaultZkHost(String zkHost) {
|
public StreamFactory withDefaultZkHost(String zkHost) {
|
||||||
this.defaultZkHost = zkHost;
|
this.defaultZkHost = zkHost;
|
||||||
return this;
|
return this;
|
||||||
|
|
|
@ -279,6 +279,16 @@ public class StreamExpressionTest extends SolrCloudTestCase {
|
||||||
assert (tuples.size() == 5);
|
assert (tuples.size() == 5);
|
||||||
assertOrder(tuples, 0, 1, 2, 3, 4);
|
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 {
|
} finally {
|
||||||
solrClientCache.close();
|
solrClientCache.close();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue