Search in sources :

Example 26 with StreamExpressionNamedParameter

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;
}
Also used : StreamExpression(org.apache.solr.client.solrj.io.stream.expr.StreamExpression) StreamExpressionNamedParameter(org.apache.solr.client.solrj.io.stream.expr.StreamExpressionNamedParameter) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 27 with StreamExpressionNamedParameter

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;
}
Also used : StreamExpression(org.apache.solr.client.solrj.io.stream.expr.StreamExpression) StreamExpressionNamedParameter(org.apache.solr.client.solrj.io.stream.expr.StreamExpressionNamedParameter) Expressible(org.apache.solr.client.solrj.io.stream.expr.Expressible) IOException(java.io.IOException)

Example 28 with StreamExpressionNamedParameter

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;
}
Also used : StreamExpression(org.apache.solr.client.solrj.io.stream.expr.StreamExpression) StreamExpressionNamedParameter(org.apache.solr.client.solrj.io.stream.expr.StreamExpressionNamedParameter)

Example 29 with StreamExpressionNamedParameter

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)));
    }
}
Also used : StreamExpression(org.apache.solr.client.solrj.io.stream.expr.StreamExpression) StreamExpressionNamedParameter(org.apache.solr.client.solrj.io.stream.expr.StreamExpressionNamedParameter) SolrParams(org.apache.solr.common.params.SolrParams) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) SolrException(org.apache.solr.common.SolrException) IOException(java.io.IOException)

Example 30 with StreamExpressionNamedParameter

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);
}
Also used : StreamExpression(org.apache.solr.client.solrj.io.stream.expr.StreamExpression) StreamExpressionNamedParameter(org.apache.solr.client.solrj.io.stream.expr.StreamExpressionNamedParameter) StreamExpressionValue(org.apache.solr.client.solrj.io.stream.expr.StreamExpressionValue) Test(org.junit.Test)

Aggregations

StreamExpressionNamedParameter (org.apache.solr.client.solrj.io.stream.expr.StreamExpressionNamedParameter)38 StreamExpression (org.apache.solr.client.solrj.io.stream.expr.StreamExpression)37 IOException (java.io.IOException)17 Expressible (org.apache.solr.client.solrj.io.stream.expr.Expressible)15 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)8 HashMap (java.util.HashMap)4 Map (java.util.Map)4 Metric (org.apache.solr.client.solrj.io.stream.metrics.Metric)4 StreamExpressionValue (org.apache.solr.client.solrj.io.stream.expr.StreamExpressionValue)2 Bucket (org.apache.solr.client.solrj.io.stream.metrics.Bucket)2 LinkedHashMap (java.util.LinkedHashMap)1 FieldComparator (org.apache.solr.client.solrj.io.comp.FieldComparator)1 MultipleFieldComparator (org.apache.solr.client.solrj.io.comp.MultipleFieldComparator)1 SolrException (org.apache.solr.common.SolrException)1 SolrParams (org.apache.solr.common.params.SolrParams)1 Test (org.junit.Test)1