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"));
}
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;
}
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;
}
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;
}
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;
}
Aggregations