Search in sources :

Example 6 with StreamExpressionNamedParameter

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

the class RollupStream method toExpression.

private StreamExpression toExpression(StreamFactory factory, boolean includeStreams) throws IOException {
    // function name
    StreamExpression expression = new StreamExpression(factory.getFunctionName(this.getClass()));
    // stream
    if (includeStreams) {
        expression.addParameter(tupleStream.toExpression(factory));
    } else {
        expression.addParameter("<stream>");
    }
    // over
    StringBuilder overBuilder = new StringBuilder();
    for (Bucket bucket : buckets) {
        if (overBuilder.length() > 0) {
            overBuilder.append(",");
        }
        overBuilder.append(bucket.toString());
    }
    expression.addParameter(new StreamExpressionNamedParameter("over", overBuilder.toString()));
    // metrics
    for (Metric metric : metrics) {
        expression.addParameter(metric.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) Bucket(org.apache.solr.client.solrj.io.stream.metrics.Bucket) Metric(org.apache.solr.client.solrj.io.stream.metrics.Metric)

Example 7 with StreamExpressionNamedParameter

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

the class ScoreNodesStream method toExpression.

private StreamExpression toExpression(StreamFactory factory, boolean includeStreams) throws IOException {
    // function name
    StreamExpression expression = new StreamExpression(factory.getFunctionName(this.getClass()));
    // nodeFreqField
    expression.addParameter(new StreamExpressionNamedParameter("termFreq", termFreq));
    if (includeStreams) {
        // stream
        if (stream instanceof Expressible) {
            expression.addParameter(((Expressible) stream).toExpression(factory));
        } else {
            throw new IOException("This ScoreNodesStream 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 8 with StreamExpressionNamedParameter

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

the class ModelStream method toExpression.

private StreamExpression toExpression(StreamFactory factory, boolean includeStreams) throws IOException {
    // function name
    StreamExpression expression = new StreamExpression(factory.getFunctionName(this.getClass()));
    // collection
    expression.addParameter(collection);
    // zkHost
    expression.addParameter(new StreamExpressionNamedParameter("zkHost", zkHost));
    expression.addParameter(new StreamExpressionNamedParameter(ID, modelID));
    expression.addParameter(new StreamExpressionNamedParameter("cacheMillis", Long.toString(cacheMillis)));
    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 9 with StreamExpressionNamedParameter

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

the class OuterHashJoinStream method toExpression.

@Override
public StreamExpression toExpression(StreamFactory factory) throws IOException {
    // function name
    StreamExpression expression = new StreamExpression(factory.getFunctionName(this.getClass()));
    // streams
    if (hashStream instanceof Expressible && fullStream instanceof Expressible) {
        expression.addParameter(((Expressible) fullStream).toExpression(factory));
        expression.addParameter(new StreamExpressionNamedParameter("hashed", ((Expressible) hashStream).toExpression(factory)));
    } else {
        throw new IOException("This OuterHashJoinStream contains a non-expressible TupleStream - it cannot be converted to an expression");
    }
    // on
    StringBuilder sb = new StringBuilder();
    for (int idx = 0; idx < leftHashOn.size(); ++idx) {
        if (sb.length() > 0) {
            sb.append(",");
        }
        // we know that left and right hashOns are the same size
        String left = leftHashOn.get(idx);
        String right = rightHashOn.get(idx);
        if (left.equals(right)) {
            sb.append(left);
        } else {
            sb.append(left);
            sb.append("=");
            sb.append(right);
        }
    }
    expression.addParameter(new StreamExpressionNamedParameter("on", sb.toString()));
    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 10 with StreamExpressionNamedParameter

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

the class GatherNodesStream method toExpression.

private StreamExpression toExpression(StreamFactory factory, boolean includeStreams) throws IOException {
    StreamExpression expression = new StreamExpression(factory.getFunctionName(this.getClass()));
    // collection
    expression.addParameter(collection);
    if (includeStreams && !(tupleStream instanceof NodeStream)) {
        if (tupleStream instanceof Expressible) {
            expression.addParameter(((Expressible) tupleStream).toExpression(factory));
        } else {
            throw new IOException("This GatherNodesStream contains a non-expressible TupleStream - it cannot be converted to an expression");
        }
    } else {
        expression.addParameter("<stream>");
    }
    Set<Map.Entry<String, String>> entries = queryParams.entrySet();
    // parameters
    for (Map.Entry param : entries) {
        String value = param.getValue().toString();
        // 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));
    }
    if (metrics != null) {
        for (Metric metric : metrics) {
            expression.addParameter(metric.toExpression(factory));
        }
    }
    expression.addParameter(new StreamExpressionNamedParameter("zkHost", zkHost));
    expression.addParameter(new StreamExpressionNamedParameter("gather", zkHost));
    if (maxDocFreq > -1) {
        expression.addParameter(new StreamExpressionNamedParameter("maxDocFreq", Integer.toString(maxDocFreq)));
    }
    if (tupleStream instanceof NodeStream) {
        NodeStream nodeStream = (NodeStream) tupleStream;
        expression.addParameter(new StreamExpressionNamedParameter("walk", nodeStream.toString() + "->" + traverseTo));
    } else {
        expression.addParameter(new StreamExpressionNamedParameter("walk", traverseFrom + "->" + traverseTo));
    }
    expression.addParameter(new StreamExpressionNamedParameter("trackTraversal", Boolean.toString(trackTraversal)));
    StringBuilder buf = new StringBuilder();
    for (Traversal.Scatter sc : scatter) {
        if (buf.length() > 0) {
            buf.append(",");
        }
        buf.append(sc.toString());
    }
    expression.addParameter(new StreamExpressionNamedParameter("scatter", buf.toString()));
    return expression;
}
Also used : Expressible(org.apache.solr.client.solrj.io.stream.expr.Expressible) StreamExpressionNamedParameter(org.apache.solr.client.solrj.io.stream.expr.StreamExpressionNamedParameter) IOException(java.io.IOException) StreamExpression(org.apache.solr.client.solrj.io.stream.expr.StreamExpression) HashMap(java.util.HashMap) Map(java.util.Map)

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