Search in sources :

Example 11 with StreamExpressionNamedParameter

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

the class ShortestPathStream method toExpression.

@Override
public StreamExpressionParameter toExpression(StreamFactory factory) throws IOException {
    StreamExpression expression = new StreamExpression(factory.getFunctionName(this.getClass()));
    // collection
    expression.addParameter(collection);
    // parameters
    ModifiableSolrParams mParams = new ModifiableSolrParams(queryParams);
    for (Map.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().toString(), value));
    }
    expression.addParameter(new StreamExpressionNamedParameter("zkHost", zkHost));
    expression.addParameter(new StreamExpressionNamedParameter("maxDepth", Integer.toString(maxDepth)));
    expression.addParameter(new StreamExpressionNamedParameter("threads", Integer.toString(threads)));
    expression.addParameter(new StreamExpressionNamedParameter("partitionSize", Integer.toString(joinBatchSize)));
    expression.addParameter(new StreamExpressionNamedParameter("from", fromNode));
    expression.addParameter(new StreamExpressionNamedParameter("to", toNode));
    expression.addParameter(new StreamExpressionNamedParameter("edge", fromField + "=" + toField));
    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) Map(java.util.Map) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Example 12 with StreamExpressionNamedParameter

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

the class ConcatOperation method toExpression.

@Override
public StreamExpressionParameter toExpression(StreamFactory factory) throws IOException {
    StreamExpression expression = new StreamExpression(factory.getFunctionName(this.getClass()));
    StringBuilder sb = new StringBuilder();
    for (String field : fields) {
        if (sb.length() > 0) {
            sb.append(",");
        }
        sb.append(field);
    }
    expression.addParameter(new StreamExpressionNamedParameter("fields", sb.toString()));
    expression.addParameter(new StreamExpressionNamedParameter("delim", delim));
    expression.addParameter(new StreamExpressionNamedParameter("as", as));
    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 13 with StreamExpressionNamedParameter

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

the class ReplaceWithValueOperation method toExpression.

@Override
public StreamExpressionParameter toExpression(StreamFactory factory) throws IOException {
    // function name
    StreamExpression expression = new StreamExpression(factory.getFunctionName(this.getClass()));
    if (wasBuiltWithFieldName) {
        expression.addParameter(fieldName);
    }
    expression.addParameter(null == original ? "null" : original.toString());
    expression.addParameter(new StreamExpressionNamedParameter("withValue", null == replacement ? "null" : replacement.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)

Example 14 with StreamExpressionNamedParameter

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

the class ComplementStream method toExpression.

private StreamExpression toExpression(StreamFactory factory, boolean includeStreams) throws IOException {
    // function name
    StreamExpression expression = new StreamExpression(factory.getFunctionName(this.getClass()));
    if (includeStreams) {
        // streams
        if (streamA instanceof Expressible) {
            expression.addParameter(((Expressible) streamA).toExpression(factory));
        } else {
            throw new IOException("This IntersectionStream contains a non-expressible TupleStream - it cannot be converted to an expression");
        }
        if (originalStreamB instanceof Expressible) {
            expression.addParameter(((Expressible) originalStreamB).toExpression(factory));
        } else {
            throw new IOException("This IntersectStream contains a non-expressible TupleStream - it cannot be converted to an expression");
        }
    } else {
        expression.addParameter("<stream>");
        expression.addParameter("<stream>");
    }
    // on
    expression.addParameter(new StreamExpressionNamedParameter("on", eq.toExpression(factory)));
    return expression;
}
Also used : StreamExpression(org.apache.solr.client.solrj.io.stream.expr.StreamExpression) Expressible(org.apache.solr.client.solrj.io.stream.expr.Expressible) StreamExpressionNamedParameter(org.apache.solr.client.solrj.io.stream.expr.StreamExpressionNamedParameter) IOException(java.io.IOException)

Example 15 with StreamExpressionNamedParameter

use of org.apache.solr.client.solrj.io.stream.expr.StreamExpressionNamedParameter 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)

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