Search in sources :

Example 1 with StreamExplanation

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

the class TestJavabinTupleStreamParser method testSimple.

public void testSimple() throws IOException {
    List<Map<String, Object>> l = new ArrayList();
    l.add(Utils.makeMap("id", 1, "f", 1.0f, "s", "Some str 1"));
    l.add(Utils.makeMap("id", 2, "f", 2.0f, "s", "Some str 2"));
    l.add(Utils.makeMap("id", 3, "f", 1.0f, "s", "Some str 3"));
    l.add(Utils.makeMap("EOF", true, "RESPONSE_TIME", 206, "sleepMillis", 1000));
    Iterator<Map<String, Object>> iterator = l.iterator();
    TupleStream tupleStream = new TupleStream() {

        @Override
        public void setStreamContext(StreamContext context) {
        }

        @Override
        public List<TupleStream> children() {
            return null;
        }

        @Override
        public void open() throws IOException {
        }

        @Override
        public void close() throws IOException {
        }

        @Override
        public Tuple read() throws IOException {
            if (iterator.hasNext())
                return new Tuple(iterator.next());
            else
                return null;
        }

        @Override
        public StreamComparator getStreamSort() {
            return null;
        }

        @Override
        public Explanation toExplanation(StreamFactory factory) throws IOException {
            return new StreamExplanation(getStreamNodeId().toString()).withFunctionName("Dummy").withImplementingClass(this.getClass().getName()).withExpressionType(Explanation.ExpressionType.STREAM_SOURCE).withExpression("--non-expressible--");
        }
    };
    byte[] bytes = serialize(tupleStream);
    JavabinTupleStreamParser parser = new JavabinTupleStreamParser(new ByteArrayInputStream(bytes), true);
    Map m = parser.next();
    assertEquals(1L, m.get("id"));
    assertEquals(1.0, (Double) m.get("f"), 0.01);
    m = parser.next();
    assertEquals(2L, m.get("id"));
    assertEquals(2.0, (Double) m.get("f"), 0.01);
    m = parser.next();
    assertEquals(3L, m.get("id"));
    assertEquals(1.0, (Double) m.get("f"), 0.01);
    m = parser.next();
    assertEquals(Boolean.TRUE, m.get("EOF"));
    parser = new JavabinTupleStreamParser(new ByteArrayInputStream(bytes), false);
    m = parser.next();
    assertEquals(1, m.get("id"));
    assertEquals(1.0, (Float) m.get("f"), 0.01);
    m = parser.next();
    assertEquals(2, m.get("id"));
    assertEquals(2.0, (Float) m.get("f"), 0.01);
    m = parser.next();
    assertEquals(3, m.get("id"));
    assertEquals(1.0, (Float) m.get("f"), 0.01);
    m = parser.next();
    assertEquals(Boolean.TRUE, m.get("EOF"));
}
Also used : StreamExplanation(org.apache.solr.client.solrj.io.stream.expr.StreamExplanation) TupleStream(org.apache.solr.client.solrj.io.stream.TupleStream) ByteArrayInputStream(java.io.ByteArrayInputStream) StreamContext(org.apache.solr.client.solrj.io.stream.StreamContext) StreamFactory(org.apache.solr.client.solrj.io.stream.expr.StreamFactory) ArrayList(java.util.ArrayList) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) Map(java.util.Map) Tuple(org.apache.solr.client.solrj.io.Tuple) JavabinTupleStreamParser(org.apache.solr.client.solrj.io.stream.JavabinTupleStreamParser)

Example 2 with StreamExplanation

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

the class KnnStream method toExplanation.

@Override
public Explanation toExplanation(StreamFactory factory) throws IOException {
    StreamExplanation explanation = new StreamExplanation(getStreamNodeId().toString());
    explanation.setFunctionName(factory.getFunctionName(this.getClass()));
    explanation.setImplementingClass(this.getClass().getName());
    explanation.setExpressionType(ExpressionType.STREAM_SOURCE);
    explanation.setExpression(toExpression(factory).toString());
    // child is a datastore so add it at this point
    StreamExplanation child = new StreamExplanation(getStreamNodeId() + "-datastore");
    child.setFunctionName(String.format(Locale.ROOT, "solr (%s)", collection));
    child.setImplementingClass("Solr/Lucene");
    child.setExpressionType(ExpressionType.DATASTORE);
    if (null != props) {
        child.setExpression(props.entrySet().stream().map(e -> String.format(Locale.ROOT, "%s=%s", e.getKey(), e.getValue())).collect(Collectors.joining(",")));
    }
    explanation.addChild(child);
    return explanation;
}
Also used : StreamExplanation(org.apache.solr.client.solrj.io.stream.expr.StreamExplanation)

Example 3 with StreamExplanation

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

the class RandomStream method toExplanation.

@Override
public Explanation toExplanation(StreamFactory factory) throws IOException {
    StreamExplanation explanation = new StreamExplanation(getStreamNodeId().toString());
    explanation.setFunctionName(factory.getFunctionName(this.getClass()));
    explanation.setImplementingClass(this.getClass().getName());
    explanation.setExpressionType(ExpressionType.STREAM_SOURCE);
    explanation.setExpression(toExpression(factory).toString());
    // child is a datastore so add it at this point
    StreamExplanation child = new StreamExplanation(getStreamNodeId() + "-datastore");
    child.setFunctionName(String.format(Locale.ROOT, "solr (%s)", collection));
    child.setImplementingClass("Solr/Lucene");
    child.setExpressionType(ExpressionType.DATASTORE);
    if (null != props) {
        child.setExpression(props.entrySet().stream().map(e -> String.format(Locale.ROOT, "%s=%s", e.getKey(), e.getValue())).collect(Collectors.joining(",")));
    }
    explanation.addChild(child);
    return explanation;
}
Also used : StreamExplanation(org.apache.solr.client.solrj.io.stream.expr.StreamExplanation)

Example 4 with StreamExplanation

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

the class TextLogitStream method toExplanation.

@Override
public Explanation toExplanation(StreamFactory factory) throws IOException {
    StreamExplanation explanation = new StreamExplanation(getStreamNodeId().toString());
    explanation.setFunctionName(factory.getFunctionName(this.getClass()));
    explanation.setImplementingClass(this.getClass().getName());
    explanation.setExpressionType(Explanation.ExpressionType.MACHINE_LEARNING_MODEL);
    explanation.setExpression(toExpression(factory).toString());
    explanation.addChild(termsStream.toExplanation(factory));
    return explanation;
}
Also used : StreamExplanation(org.apache.solr.client.solrj.io.stream.expr.StreamExplanation)

Example 5 with StreamExplanation

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

the class SqlStream method toExplanation.

@Override
public Explanation toExplanation(StreamFactory factory) throws IOException {
    StreamExplanation explanation = new StreamExplanation(getStreamNodeId().toString());
    explanation.setFunctionName(factory.getFunctionName(this.getClass()));
    explanation.setImplementingClass(this.getClass().getName());
    explanation.setExpressionType(ExpressionType.STREAM_SOURCE);
    explanation.setExpression(toExpression(factory).toString());
    // child is a datastore so add it at this point
    StreamExplanation child = new StreamExplanation(getStreamNodeId() + "-datastore");
    child.setFunctionName(String.format(Locale.ROOT, "solr (%s)", collection));
    child.setImplementingClass("Solr/Lucene");
    child.setExpressionType(ExpressionType.DATASTORE);
    if (null != params) {
        ModifiableSolrParams mParams = new ModifiableSolrParams(params);
        child.setExpression(mParams.getMap().entrySet().stream().map(e -> String.format(Locale.ROOT, "%s=%s", e.getKey(), e.getValue())).collect(Collectors.joining(",")));
    }
    explanation.addChild(child);
    return explanation;
}
Also used : StreamExplanation(org.apache.solr.client.solrj.io.stream.expr.StreamExplanation) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Aggregations

StreamExplanation (org.apache.solr.client.solrj.io.stream.expr.StreamExplanation)34 Explanation (org.apache.solr.client.solrj.io.stream.expr.Explanation)10 Test (org.junit.Test)8 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)7 StreamExpression (org.apache.solr.client.solrj.io.stream.expr.StreamExpression)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Tuple (org.apache.solr.client.solrj.io.Tuple)2 StreamFactory (org.apache.solr.client.solrj.io.stream.expr.StreamFactory)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 MethodHandles (java.lang.invoke.MethodHandles)1 SQLException (java.sql.SQLException)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Locale (java.util.Locale)1 Entry (java.util.Map.Entry)1 Random (java.util.Random)1