Search in sources :

Example 36 with StreamExpression

use of org.apache.solr.client.solrj.io.stream.expr.StreamExpression in project lucene-solr by apache.

the class CellStream method toExpression.

private StreamExpression toExpression(StreamFactory factory, boolean includeStreams) throws IOException {
    // function name
    StreamExpression expression = new StreamExpression(factory.getFunctionName(this.getClass()));
    expression.addParameter(name);
    if (includeStreams) {
        expression.addParameter(((Expressible) stream).toExpression(factory));
    }
    return expression;
}
Also used : StreamExpression(org.apache.solr.client.solrj.io.stream.expr.StreamExpression)

Example 37 with StreamExpression

use of org.apache.solr.client.solrj.io.stream.expr.StreamExpression in project lucene-solr by apache.

the class CloudSolrStream method toExpression.

@Override
public StreamExpression toExpression(StreamFactory factory) throws IOException {
    // functionName(collectionName, param1, param2, ..., paramN, sort="comp", [aliases="field=alias,..."])
    // function name
    StreamExpression expression = new StreamExpression(factory.getFunctionName(getClass()));
    // collection
    expression.addParameter(collection);
    // parameters
    ModifiableSolrParams mParams = new ModifiableSolrParams(SolrParams.toMultiMap(params.toNamedList()));
    for (Entry<String, String[]> param : mParams.getMap().entrySet()) {
        String value = String.join(",", param.getValue());
        // SOLR-8409: This is a special case where the params contain a " character
        // Do note that in any other BASE streams with parameters where a " might come into play
        // that this same replacement needs to take place.
        value = value.replace("\"", "\\\"");
        expression.addParameter(new StreamExpressionNamedParameter(param.getKey(), value));
    }
    // zkHost
    expression.addParameter(new StreamExpressionNamedParameter("zkHost", zkHost));
    // aliases
    if (null != fieldMappings && 0 != fieldMappings.size()) {
        StringBuilder sb = new StringBuilder();
        for (Entry<String, String> mapping : fieldMappings.entrySet()) {
            if (sb.length() > 0) {
                sb.append(",");
            }
            sb.append(mapping.getKey());
            sb.append("=");
            sb.append(mapping.getValue());
        }
        expression.addParameter(new StreamExpressionNamedParameter("aliases", sb.toString()));
    }
    return expression;
}
Also used : StreamExpression(org.apache.solr.client.solrj.io.stream.expr.StreamExpression) StreamExpressionNamedParameter(org.apache.solr.client.solrj.io.stream.expr.StreamExpressionNamedParameter) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Example 38 with StreamExpression

use of org.apache.solr.client.solrj.io.stream.expr.StreamExpression in project lucene-solr by apache.

the class UpdateStream method toExpression.

private StreamExpression toExpression(StreamFactory factory, boolean includeStreams) throws IOException {
    StreamExpression expression = new StreamExpression(factory.getFunctionName(this.getClass()));
    expression.addParameter(collection);
    expression.addParameter(new StreamExpressionNamedParameter("zkHost", zkHost));
    expression.addParameter(new StreamExpressionNamedParameter("batchSize", Integer.toString(updateBatchSize)));
    if (includeStreams) {
        if (tupleSource instanceof Expressible) {
            expression.addParameter(((Expressible) tupleSource).toExpression(factory));
        } else {
            throw new IOException("This ParallelStream contains a non-expressible TupleStream - it cannot be converted to an expression");
        }
    } else {
        expression.addParameter("<stream>");
    }
    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 39 with StreamExpression

use of org.apache.solr.client.solrj.io.stream.expr.StreamExpression in project lucene-solr by apache.

the class StreamExpressionToExplanationTest method testUpdateStream.

@Test
public void testUpdateStream() throws Exception {
    StreamExpression expression = StreamExpressionParser.parse("update(" + "collection2, " + "batchSize=5, " + "search(" + "collection1, " + "q=*:*, " + "fl=\"id,a_s,a_i,a_f\", " + "sort=\"a_f asc, a_i asc\"))");
    UpdateStream updateStream = new UpdateStream(expression, factory);
    Explanation explanation = updateStream.toExplanation(factory);
    Assert.assertEquals("solr (collection2)", explanation.getFunctionName());
    Assert.assertEquals("Solr/Lucene", explanation.getImplementingClass());
    StreamExplanation updateExplanation = (StreamExplanation) explanation;
    Assert.assertEquals(1, updateExplanation.getChildren().size());
    Assert.assertEquals("update", updateExplanation.getChildren().get(0).getFunctionName());
    Assert.assertEquals(UpdateStream.class.getName(), updateExplanation.getChildren().get(0).getImplementingClass());
}
Also used : StreamExplanation(org.apache.solr.client.solrj.io.stream.expr.StreamExplanation) StreamExpression(org.apache.solr.client.solrj.io.stream.expr.StreamExpression) StreamExplanation(org.apache.solr.client.solrj.io.stream.expr.StreamExplanation) Explanation(org.apache.solr.client.solrj.io.stream.expr.Explanation) Test(org.junit.Test)

Example 40 with StreamExpression

use of org.apache.solr.client.solrj.io.stream.expr.StreamExpression in project lucene-solr by apache.

the class GroupOperation method toExpression.

public StreamExpressionParameter toExpression(StreamFactory factory) throws IOException {
    StreamExpression expression = new StreamExpression(factory.getFunctionName(this.getClass()));
    // n
    expression.addParameter(new StreamExpressionNamedParameter("n", Integer.toString(size)));
    // sort
    expression.addParameter(new StreamExpressionNamedParameter(SORT, streamComparator.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)

Aggregations

StreamExpression (org.apache.solr.client.solrj.io.stream.expr.StreamExpression)82 Test (org.junit.Test)40 StreamExpressionNamedParameter (org.apache.solr.client.solrj.io.stream.expr.StreamExpressionNamedParameter)37 SolrClientCache (org.apache.solr.client.solrj.io.SolrClientCache)36 Tuple (org.apache.solr.client.solrj.io.Tuple)36 StreamFactory (org.apache.solr.client.solrj.io.stream.expr.StreamFactory)36 UpdateRequest (org.apache.solr.client.solrj.request.UpdateRequest)36 IOException (java.io.IOException)22 Expressible (org.apache.solr.client.solrj.io.stream.expr.Expressible)15 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)14 HashMap (java.util.HashMap)7 Map (java.util.Map)5 JettySolrRunner (org.apache.solr.client.solrj.embedded.JettySolrRunner)4 FieldComparator (org.apache.solr.client.solrj.io.comp.FieldComparator)4 Metric (org.apache.solr.client.solrj.io.stream.metrics.Metric)4 MeanMetric (org.apache.solr.client.solrj.io.stream.metrics.MeanMetric)3 MinMetric (org.apache.solr.client.solrj.io.stream.metrics.MinMetric)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Explanation (org.apache.solr.client.solrj.io.stream.expr.Explanation)2