Search in sources :

Example 1 with Explanation

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

the class TemporalEvaluatorsTest method testExplain.

@Test
public void testExplain() throws IOException {
    StreamExpression express = StreamExpressionParser.parse("month('myfield')");
    TemporalEvaluatorMonth datePartEvaluator = new TemporalEvaluatorMonth(express, factory);
    Explanation explain = datePartEvaluator.toExplanation(factory);
    assertEquals("month(myfield)", explain.getExpression());
    express = StreamExpressionParser.parse("day(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbb)");
    TemporalEvaluatorDay dayPartEvaluator = new TemporalEvaluatorDay(express, factory);
    explain = dayPartEvaluator.toExplanation(factory);
    assertEquals("day(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbb)", explain.getExpression());
}
Also used : StreamExpression(org.apache.solr.client.solrj.io.stream.expr.StreamExpression) TemporalEvaluatorDay(org.apache.solr.client.solrj.io.eval.TemporalEvaluatorDay) Explanation(org.apache.solr.client.solrj.io.stream.expr.Explanation) TemporalEvaluatorMonth(org.apache.solr.client.solrj.io.eval.TemporalEvaluatorMonth) Test(org.junit.Test)

Example 2 with Explanation

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

the class TopicStream 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 1 is a datastore so add it at this point
        StreamExplanation child = new StreamExplanation(getStreamNodeId() + "-datastore");
        child.setFunctionName(String.format(Locale.ROOT, "solr (%s)", collection));
        // TODO: fix this so we know the # of workers - check with Joel about a Topic's ability to be in a
        // parallel stream.
        child.setImplementingClass("Solr/Lucene");
        child.setExpressionType(ExpressionType.DATASTORE);
        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);
    }
    {
        // child 2 is a place where we store and read checkpoint info from
        StreamExplanation child = new StreamExplanation(getStreamNodeId() + "-checkpoint");
        child.setFunctionName(String.format(Locale.ROOT, "solr (checkpoint store)"));
        child.setImplementingClass("Solr/Lucene");
        child.setExpressionType(ExpressionType.DATASTORE);
        child.setExpression(String.format(Locale.ROOT, "id=%s, collection=%s, checkpointEvery=%d", id, checkpointCollection, checkpointEvery));
        explanation.addChild(child);
    }
    return explanation;
}
Also used : StreamExplanation(org.apache.solr.client.solrj.io.stream.expr.StreamExplanation) VERSION_FIELD(org.apache.solr.common.params.CommonParams.VERSION_FIELD) StreamExplanation(org.apache.solr.client.solrj.io.stream.expr.StreamExplanation) Tuple(org.apache.solr.client.solrj.io.Tuple) ClusterState(org.apache.solr.common.cloud.ClusterState) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) Random(java.util.Random) StreamExpression(org.apache.solr.client.solrj.io.stream.expr.StreamExpression) TreeSet(java.util.TreeSet) SolrParams(org.apache.solr.common.params.SolrParams) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) StreamFactory(org.apache.solr.client.solrj.io.stream.expr.StreamFactory) Builder(org.apache.solr.client.solrj.impl.CloudSolrClient.Builder) ZkCoreNodeProps(org.apache.solr.common.cloud.ZkCoreNodeProps) Locale(java.util.Locale) Map(java.util.Map) Expressible(org.apache.solr.client.solrj.io.stream.expr.Expressible) FieldComparator(org.apache.solr.client.solrj.io.comp.FieldComparator) ExecutorUtil(org.apache.solr.common.util.ExecutorUtil) ExecutorService(java.util.concurrent.ExecutorService) StreamExpressionNamedParameter(org.apache.solr.client.solrj.io.stream.expr.StreamExpressionNamedParameter) SORT(org.apache.solr.common.params.CommonParams.SORT) ZkStateReader(org.apache.solr.common.cloud.ZkStateReader) Slice(org.apache.solr.common.cloud.Slice) Logger(org.slf4j.Logger) ComparatorOrder(org.apache.solr.client.solrj.io.comp.ComparatorOrder) ExpressionType(org.apache.solr.client.solrj.io.stream.expr.Explanation.ExpressionType) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) MethodHandles(java.lang.invoke.MethodHandles) Collection(java.util.Collection) Set(java.util.Set) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) Explanation(org.apache.solr.client.solrj.io.stream.expr.Explanation) Replica(org.apache.solr.common.cloud.Replica) StreamExpressionValue(org.apache.solr.client.solrj.io.stream.expr.StreamExpressionValue) SolrDocument(org.apache.solr.common.SolrDocument) List(java.util.List) HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) DISTRIB(org.apache.solr.common.params.CommonParams.DISTRIB) UpdateRequest(org.apache.solr.client.solrj.request.UpdateRequest) ID(org.apache.solr.common.params.CommonParams.ID) Entry(java.util.Map.Entry) SolrjNamedThreadFactory(org.apache.solr.common.util.SolrjNamedThreadFactory) Collections(java.util.Collections) SolrInputDocument(org.apache.solr.common.SolrInputDocument) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Example 3 with Explanation

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

the class StreamExpressionToExplanationTest method testReducerStream.

@Test
public void testReducerStream() throws Exception {
    ReducerStream stream;
    String expressionString;
    // Basic test
    stream = new ReducerStream(StreamExpressionParser.parse("reduce(" + "search(collection1, q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_s desc, a_f asc\")," + "by=\"a_s\", group(sort=\"a_i desc\", n=\"5\"))"), factory);
    Explanation explanation = stream.toExplanation(factory);
    Assert.assertEquals("reduce", explanation.getFunctionName());
    Assert.assertEquals(ReducerStream.class.getName(), explanation.getImplementingClass());
    Assert.assertEquals(1, ((StreamExplanation) explanation).getChildren().size());
}
Also used : StreamExplanation(org.apache.solr.client.solrj.io.stream.expr.StreamExplanation) 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 4 with Explanation

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

the class StreamExpressionToExplanationTest method testCloudSolrStream.

@Test
public void testCloudSolrStream() throws Exception {
    CloudSolrStream stream;
    // Basic test
    stream = new CloudSolrStream(StreamExpressionParser.parse("search(collection1, q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc, a_i asc\")"), factory);
    Explanation explanation = stream.toExplanation(factory);
    Assert.assertEquals("search", explanation.getFunctionName());
    Assert.assertEquals(CloudSolrStream.class.getName(), explanation.getImplementingClass());
}
Also used : 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 5 with Explanation

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

the class StreamExpressionToExplanationTest method testJDBCStream.

@Test
public void testJDBCStream() throws Exception {
    JDBCStream stream;
    String expressionString;
    // Basic test
    stream = new JDBCStream(StreamExpressionParser.parse("jdbc(connection=\"jdbc:hsqldb:mem:.\", sql=\"select PEOPLE.ID, PEOPLE.NAME, COUNTRIES.COUNTRY_NAME from PEOPLE inner join COUNTRIES on PEOPLE.COUNTRY_CODE = COUNTRIES.CODE order by PEOPLE.ID\", sort=\"ID asc\")"), factory);
    Explanation explanation = stream.toExplanation(factory);
    Assert.assertEquals("jdbc", explanation.getFunctionName());
    Assert.assertEquals(JDBCStream.class.getName(), explanation.getImplementingClass());
    Assert.assertEquals(1, ((StreamExplanation) explanation).getChildren().size());
}
Also used : StreamExplanation(org.apache.solr.client.solrj.io.stream.expr.StreamExplanation) StreamExplanation(org.apache.solr.client.solrj.io.stream.expr.StreamExplanation) Explanation(org.apache.solr.client.solrj.io.stream.expr.Explanation) Test(org.junit.Test)

Aggregations

Explanation (org.apache.solr.client.solrj.io.stream.expr.Explanation)17 StreamExplanation (org.apache.solr.client.solrj.io.stream.expr.StreamExplanation)16 Test (org.junit.Test)15 StreamExpression (org.apache.solr.client.solrj.io.stream.expr.StreamExpression)3 IOException (java.io.IOException)1 MethodHandles (java.lang.invoke.MethodHandles)1 ArrayList (java.util.ArrayList)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 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Random (java.util.Random)1 Set (java.util.Set)1 TreeSet (java.util.TreeSet)1 ExecutorService (java.util.concurrent.ExecutorService)1 Future (java.util.concurrent.Future)1 Collectors (java.util.stream.Collectors)1