use of org.apache.solr.client.solrj.io.stream.expr.StreamExpressionNamedParameter in project lucene-solr by apache.
the class FeaturesSelectionStream method toExpression.
@Override
public StreamExpressionParameter toExpression(StreamFactory factory) throws IOException {
// functionName(collectionName, param1, param2, ..., paramN, sort="comp", [aliases="field=alias,..."])
// function name
StreamExpression expression = new StreamExpression(factory.getFunctionName(this.getClass()));
// collection
expression.addParameter(collection);
// parameters
for (Map.Entry<String, String> param : params.entrySet()) {
expression.addParameter(new StreamExpressionNamedParameter(param.getKey(), param.getValue()));
}
expression.addParameter(new StreamExpressionNamedParameter("field", field));
expression.addParameter(new StreamExpressionNamedParameter("outcome", outcome));
expression.addParameter(new StreamExpressionNamedParameter("featureSet", featureSet));
expression.addParameter(new StreamExpressionNamedParameter("positiveLabel", String.valueOf(positiveLabel)));
expression.addParameter(new StreamExpressionNamedParameter("numTerms", String.valueOf(numTerms)));
// zkHost
expression.addParameter(new StreamExpressionNamedParameter("zkHost", zkHost));
return expression;
}
use of org.apache.solr.client.solrj.io.stream.expr.StreamExpressionNamedParameter in project lucene-solr by apache.
the class FetchStream method toExpression.
private StreamExpression toExpression(StreamFactory factory, boolean includeStreams) throws IOException {
// function name
StreamExpression expression = new StreamExpression(factory.getFunctionName(this.getClass()));
expression.addParameter(collection);
expression.addParameter(new StreamExpressionNamedParameter("on", leftKey + "=" + rightKey));
expression.addParameter(new StreamExpressionNamedParameter("fl", fieldList));
expression.addParameter(new StreamExpressionNamedParameter("batchSize", Integer.toString(batchSize)));
// stream
if (includeStreams) {
if (stream instanceof Expressible) {
expression.addParameter(((Expressible) stream).toExpression(factory));
} else {
throw new IOException("The FetchStream contains a non-expressible TupleStream - it cannot be converted to an expression");
}
}
return expression;
}
use of org.apache.solr.client.solrj.io.stream.expr.StreamExpressionNamedParameter in project lucene-solr by apache.
the class MergeStream method toExpression.
private StreamExpression toExpression(StreamFactory factory, boolean includeStreams) throws IOException {
// function name
StreamExpression expression = new StreamExpression(factory.getFunctionName(this.getClass()));
// streams
for (PushBackStream stream : streams) {
if (includeStreams) {
expression.addParameter(stream.toExpression(factory));
} else {
expression.addParameter("<stream>");
}
}
// on
expression.addParameter(new StreamExpressionNamedParameter("on", comp.toExpression(factory)));
return expression;
}
use of org.apache.solr.client.solrj.io.stream.expr.StreamExpressionNamedParameter in project lucene-solr by apache.
the class StreamHandler method handleRequestBody.
public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception {
SolrParams params = req.getParams();
params = adjustParams(params);
req.setParams(params);
if (params.get("action") != null) {
handleAdmin(req, rsp, params);
return;
}
TupleStream tupleStream;
try {
StreamExpression streamExpression = StreamExpressionParser.parse(params.get("expr"));
if (this.streamFactory.isEvaluator(streamExpression)) {
StreamExpression tupleExpression = new StreamExpression("tuple");
tupleExpression.addParameter(new StreamExpressionNamedParameter("return-value", streamExpression));
tupleStream = this.streamFactory.constructStream(tupleExpression);
} else {
tupleStream = this.streamFactory.constructStream(streamExpression);
}
} catch (Exception e) {
//Catch exceptions that occur while the stream is being created. This will include streaming expression parse rules.
SolrException.log(logger, e);
rsp.add("result-set", new DummyErrorStream(e));
return;
}
int worker = params.getInt("workerID", 0);
int numWorkers = params.getInt("numWorkers", 1);
StreamContext context = new StreamContext();
context.put("shards", getCollectionShards(params));
context.workerID = worker;
context.numWorkers = numWorkers;
context.setSolrClientCache(clientCache);
context.setModelCache(modelCache);
context.put("core", this.coreName);
context.put("solr-core", req.getCore());
tupleStream.setStreamContext(context);
// if asking for explanation then go get it
if (params.getBool("explain", false)) {
rsp.add("explanation", tupleStream.toExplanation(this.streamFactory));
}
if (tupleStream instanceof DaemonStream) {
DaemonStream daemonStream = (DaemonStream) tupleStream;
if (daemons.containsKey(daemonStream.getId())) {
daemons.remove(daemonStream.getId()).close();
}
daemonStream.setDaemons(daemons);
//This will start the deamonStream
daemonStream.open();
daemons.put(daemonStream.getId(), daemonStream);
rsp.add("result-set", new DaemonResponseStream("Deamon:" + daemonStream.getId() + " started on " + coreName));
} else {
rsp.add("result-set", new TimerStream(new ExceptionStream(tupleStream)));
}
}
use of org.apache.solr.client.solrj.io.stream.expr.StreamExpressionNamedParameter in project lucene-solr by apache.
the class StreamExpressionParserTest method testParsing.
@Test
public void testParsing() throws Exception {
StreamExpression actual, expected;
actual = StreamExpressionParser.parse("aliases(a_i=alias.a_i)");
expected = new StreamExpression("aliases").withParameter(new StreamExpressionNamedParameter("a_i", "alias.a_i"));
assertEquals(expected, actual);
actual = StreamExpressionParser.parse("search(a,b)");
expected = new StreamExpression("search").withParameter("a").withParameter("b");
assertEquals(expected, actual);
actual = StreamExpressionParser.parse("search(collection1, q=*:*, sort=\"fieldA desc, fieldB asc, fieldC asc\")");
expected = new StreamExpression("search").withParameter(new StreamExpressionValue("collection1")).withParameter(new StreamExpressionNamedParameter("q").withParameter("*:*")).withParameter(new StreamExpressionNamedParameter("sort").withParameter("fieldA desc, fieldB asc, fieldC asc"));
assertEquals(expected, actual);
actual = StreamExpressionParser.parse("unique(search(collection1, q=*:*, sort=\"fieldA desc, fieldB asc, fieldC asc\"))");
expected = new StreamExpression("unique").withParameter(new StreamExpression("search").withParameter(new StreamExpressionValue("collection1")).withParameter(new StreamExpressionNamedParameter("q").withParameter("*:*")).withParameter(new StreamExpressionNamedParameter("sort").withParameter("fieldA desc, fieldB asc, fieldC asc")));
assertEquals(expected, actual);
actual = StreamExpressionParser.parse("unique(search(collection1, q=*:*, sort=\"fieldA desc, fieldB asc, fieldC asc\"), alt=search(collection1, foo=bar))");
expected = new StreamExpression("unique").withParameter(new StreamExpression("search").withParameter(new StreamExpressionValue("collection1")).withParameter(new StreamExpressionNamedParameter("q").withParameter("*:*")).withParameter(new StreamExpressionNamedParameter("sort").withParameter("fieldA desc, fieldB asc, fieldC asc"))).withParameter(new StreamExpressionNamedParameter("alt").withParameter(new StreamExpression("search").withParameter("collection1").withParameter(new StreamExpressionNamedParameter("foo").withParameter("bar"))));
assertEquals(expected, actual);
actual = StreamExpressionParser.parse("innerJoin(" + "left=search(collection1, q=*:*, fl=\"fieldA,fieldB,fieldC\", sort=\"fieldA asc, fieldB asc\")," + "right=search(collection2, q=*:*, fl=\"fieldA,fieldD\", sort=fieldA asc)," + "on(equals(fieldA), notEquals(fieldC,fieldD))" + ")");
expected = new StreamExpression("innerJoin").withParameter(new StreamExpressionNamedParameter("left").withParameter(new StreamExpression("search").withParameter("collection1").withParameter(new StreamExpressionNamedParameter("q", "*:*")).withParameter(new StreamExpressionNamedParameter("fl", "fieldA,fieldB,fieldC")).withParameter(new StreamExpressionNamedParameter("sort", "fieldA asc, fieldB asc")))).withParameter(new StreamExpressionNamedParameter("right").withParameter(new StreamExpression("search").withParameter("collection2").withParameter(new StreamExpressionNamedParameter("q", "*:*")).withParameter(new StreamExpressionNamedParameter("fl", "fieldA,fieldD")).withParameter(new StreamExpressionNamedParameter("sort", "fieldA asc")))).withParameter(new StreamExpression("on").withParameter(new StreamExpression("equals").withParameter("fieldA")).withParameter(new StreamExpression("notEquals").withParameter("fieldC").withParameter("fieldD")));
assertEquals(expected, actual);
}
Aggregations