Search in sources :

Example 6 with FieldEqualitor

use of org.apache.solr.client.solrj.io.eq.FieldEqualitor in project lucene-solr by apache.

the class StreamingTest method testParallelReducerStream.

@Test
public void testParallelReducerStream() throws Exception {
    new UpdateRequest().add(id, "0", "a_s", "hello0", "a_i", "0", "a_f", "1").add(id, "2", "a_s", "hello0", "a_i", "2", "a_f", "2").add(id, "3", "a_s", "hello3", "a_i", "3", "a_f", "3").add(id, "4", "a_s", "hello4", "a_i", "4", "a_f", "4").add(id, "1", "a_s", "hello0", "a_i", "1", "a_f", "5").add(id, "5", "a_s", "hello3", "a_i", "10", "a_f", "6").add(id, "6", "a_s", "hello4", "a_i", "11", "a_f", "7").add(id, "7", "a_s", "hello3", "a_i", "12", "a_f", "8").add(id, "8", "a_s", "hello3", "a_i", "13", "a_f", "9").add(id, "9", "a_s", "hello0", "a_i", "14", "a_f", "10").commit(cluster.getSolrClient(), COLLECTIONORALIAS);
    StreamContext streamContext = new StreamContext();
    SolrClientCache solrClientCache = new SolrClientCache();
    streamContext.setSolrClientCache(solrClientCache);
    try {
        SolrParams sParamsA = mapParams("q", "*:*", "fl", "id,a_s,a_i,a_f", "sort", "a_s asc,a_f asc", "partitionKeys", "a_s");
        CloudSolrStream stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsA);
        ReducerStream rstream = new ReducerStream(stream, new FieldEqualitor("a_s"), new GroupOperation(new FieldComparator("a_f", ComparatorOrder.DESCENDING), 5));
        ParallelStream pstream = parallelStream(rstream, new FieldComparator("a_s", ComparatorOrder.ASCENDING));
        attachStreamFactory(pstream);
        pstream.setStreamContext(streamContext);
        List<Tuple> tuples = getTuples(pstream);
        assertEquals(3, tuples.size());
        Tuple t0 = tuples.get(0);
        List<Map> maps0 = t0.getMaps("group");
        assertMaps(maps0, 9, 1, 2, 0);
        Tuple t1 = tuples.get(1);
        List<Map> maps1 = t1.getMaps("group");
        assertMaps(maps1, 8, 7, 5, 3);
        Tuple t2 = tuples.get(2);
        List<Map> maps2 = t2.getMaps("group");
        assertMaps(maps2, 6, 4);
        //Test Descending with Ascending subsort
        sParamsA = mapParams("q", "*:*", "fl", "id,a_s,a_i,a_f", "sort", "a_s desc,a_f asc", "partitionKeys", "a_s");
        stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsA);
        rstream = new ReducerStream(stream, new FieldEqualitor("a_s"), new GroupOperation(new FieldComparator("a_f", ComparatorOrder.ASCENDING), 3));
        pstream = parallelStream(rstream, new FieldComparator("a_s", ComparatorOrder.DESCENDING));
        attachStreamFactory(pstream);
        pstream.setStreamContext(streamContext);
        tuples = getTuples(pstream);
        assertEquals(3, tuples.size());
        t0 = tuples.get(0);
        maps0 = t0.getMaps("group");
        assertMaps(maps0, 4, 6);
        t1 = tuples.get(1);
        maps1 = t1.getMaps("group");
        assertMaps(maps1, 3, 5, 7);
        t2 = tuples.get(2);
        maps2 = t2.getMaps("group");
        assertMaps(maps2, 0, 2, 1);
    } finally {
        solrClientCache.close();
    }
}
Also used : UpdateRequest(org.apache.solr.client.solrj.request.UpdateRequest) FieldEqualitor(org.apache.solr.client.solrj.io.eq.FieldEqualitor) SolrClientCache(org.apache.solr.client.solrj.io.SolrClientCache) SolrParams(org.apache.solr.common.params.SolrParams) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) FieldComparator(org.apache.solr.client.solrj.io.comp.FieldComparator) MultipleFieldComparator(org.apache.solr.client.solrj.io.comp.MultipleFieldComparator) Map(java.util.Map) GroupOperation(org.apache.solr.client.solrj.io.ops.GroupOperation) Tuple(org.apache.solr.client.solrj.io.Tuple) Test(org.junit.Test)

Example 7 with FieldEqualitor

use of org.apache.solr.client.solrj.io.eq.FieldEqualitor in project lucene-solr by apache.

the class StreamingTest method testZeroReducerStream.

@Test
public void testZeroReducerStream() throws Exception {
    //Gracefully handle zero results
    new UpdateRequest().add(id, "0", "a_s", "hello0", "a_i", "0", "a_f", "1").add(id, "2", "a_s", "hello0", "a_i", "2", "a_f", "2").add(id, "3", "a_s", "hello3", "a_i", "3", "a_f", "3").add(id, "4", "a_s", "hello4", "a_i", "4", "a_f", "4").add(id, "1", "a_s", "hello0", "a_i", "1", "a_f", "5").add(id, "5", "a_s", "hello3", "a_i", "10", "a_f", "6").add(id, "6", "a_s", "hello4", "a_i", "11", "a_f", "7").add(id, "7", "a_s", "hello3", "a_i", "12", "a_f", "8").add(id, "8", "a_s", "hello3", "a_i", "13", "a_f", "9").add(id, "9", "a_s", "hello0", "a_i", "14", "a_f", "10").commit(cluster.getSolrClient(), COLLECTIONORALIAS);
    StreamContext streamContext = new StreamContext();
    SolrClientCache solrClientCache = new SolrClientCache();
    streamContext.setSolrClientCache(solrClientCache);
    try {
        //Test with spaces in the parameter lists.
        SolrParams sParamsA = mapParams("q", "blah", "fl", "id,a_s, a_i,  a_f", "sort", "a_s asc  ,  a_f   asc");
        CloudSolrStream stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsA);
        ReducerStream rstream = new ReducerStream(stream, new FieldEqualitor("a_s"), new GroupOperation(new FieldComparator("a_f", ComparatorOrder.ASCENDING), 5));
        rstream.setStreamContext(streamContext);
        List<Tuple> tuples = getTuples(rstream);
        assertEquals(0, tuples.size());
    } finally {
        solrClientCache.close();
    }
}
Also used : UpdateRequest(org.apache.solr.client.solrj.request.UpdateRequest) FieldEqualitor(org.apache.solr.client.solrj.io.eq.FieldEqualitor) SolrClientCache(org.apache.solr.client.solrj.io.SolrClientCache) SolrParams(org.apache.solr.common.params.SolrParams) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) FieldComparator(org.apache.solr.client.solrj.io.comp.FieldComparator) MultipleFieldComparator(org.apache.solr.client.solrj.io.comp.MultipleFieldComparator) GroupOperation(org.apache.solr.client.solrj.io.ops.GroupOperation) Tuple(org.apache.solr.client.solrj.io.Tuple) Test(org.junit.Test)

Example 8 with FieldEqualitor

use of org.apache.solr.client.solrj.io.eq.FieldEqualitor in project lucene-solr by apache.

the class ReducerStream method convertToEqualitor.

private StreamEqualitor convertToEqualitor(StreamComparator comp) {
    if (comp instanceof MultipleFieldComparator) {
        MultipleFieldComparator mComp = (MultipleFieldComparator) comp;
        StreamEqualitor[] eqs = new StreamEqualitor[mComp.getComps().length];
        for (int idx = 0; idx < mComp.getComps().length; ++idx) {
            eqs[idx] = convertToEqualitor(mComp.getComps()[idx]);
        }
        return new MultipleFieldEqualitor(eqs);
    } else {
        FieldComparator fComp = (FieldComparator) comp;
        return new FieldEqualitor(fComp.getLeftFieldName(), fComp.getRightFieldName());
    }
}
Also used : MultipleFieldEqualitor(org.apache.solr.client.solrj.io.eq.MultipleFieldEqualitor) FieldEqualitor(org.apache.solr.client.solrj.io.eq.FieldEqualitor) MultipleFieldEqualitor(org.apache.solr.client.solrj.io.eq.MultipleFieldEqualitor) MultipleFieldComparator(org.apache.solr.client.solrj.io.comp.MultipleFieldComparator) FieldComparator(org.apache.solr.client.solrj.io.comp.FieldComparator) MultipleFieldComparator(org.apache.solr.client.solrj.io.comp.MultipleFieldComparator) StreamEqualitor(org.apache.solr.client.solrj.io.eq.StreamEqualitor)

Example 9 with FieldEqualitor

use of org.apache.solr.client.solrj.io.eq.FieldEqualitor in project lucene-solr by apache.

the class StreamingTest method testZeroParallelReducerStream.

@Test
public void testZeroParallelReducerStream() throws Exception {
    new UpdateRequest().add(id, "0", "a_s", "hello0", "a_i", "0", "a_f", "1").add(id, "2", "a_s", "hello0", "a_i", "2", "a_f", "2").add(id, "3", "a_s", "hello3", "a_i", "3", "a_f", "3").add(id, "4", "a_s", "hello4", "a_i", "4", "a_f", "4").add(id, "1", "a_s", "hello0", "a_i", "1", "a_f", "5").add(id, "5", "a_s", "hello3", "a_i", "10", "a_f", "6").add(id, "6", "a_s", "hello4", "a_i", "11", "a_f", "7").add(id, "7", "a_s", "hello3", "a_i", "12", "a_f", "8").add(id, "8", "a_s", "hello3", "a_i", "13", "a_f", "9").add(id, "9", "a_s", "hello0", "a_i", "14", "a_f", "10").commit(cluster.getSolrClient(), COLLECTIONORALIAS);
    StreamContext streamContext = new StreamContext();
    SolrClientCache solrClientCache = new SolrClientCache();
    streamContext.setSolrClientCache(solrClientCache);
    try {
        SolrParams sParamsA = mapParams("q", "blah", "fl", "id,a_s,a_i,a_f", "sort", "a_s asc,a_f asc", "partitionKeys", "a_s");
        CloudSolrStream stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsA);
        ReducerStream rstream = new ReducerStream(stream, new FieldEqualitor("a_s"), new GroupOperation(new FieldComparator("a_s", ComparatorOrder.ASCENDING), 2));
        ParallelStream pstream = parallelStream(rstream, new FieldComparator("a_s", ComparatorOrder.ASCENDING));
        attachStreamFactory(pstream);
        pstream.setStreamContext(streamContext);
        List<Tuple> tuples = getTuples(pstream);
        assert (tuples.size() == 0);
    } finally {
        solrClientCache.close();
    }
}
Also used : UpdateRequest(org.apache.solr.client.solrj.request.UpdateRequest) FieldEqualitor(org.apache.solr.client.solrj.io.eq.FieldEqualitor) SolrClientCache(org.apache.solr.client.solrj.io.SolrClientCache) SolrParams(org.apache.solr.common.params.SolrParams) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) FieldComparator(org.apache.solr.client.solrj.io.comp.FieldComparator) MultipleFieldComparator(org.apache.solr.client.solrj.io.comp.MultipleFieldComparator) GroupOperation(org.apache.solr.client.solrj.io.ops.GroupOperation) Tuple(org.apache.solr.client.solrj.io.Tuple) Test(org.junit.Test)

Aggregations

FieldEqualitor (org.apache.solr.client.solrj.io.eq.FieldEqualitor)9 FieldComparator (org.apache.solr.client.solrj.io.comp.FieldComparator)8 MultipleFieldComparator (org.apache.solr.client.solrj.io.comp.MultipleFieldComparator)8 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)7 SolrClientCache (org.apache.solr.client.solrj.io.SolrClientCache)6 Tuple (org.apache.solr.client.solrj.io.Tuple)6 UpdateRequest (org.apache.solr.client.solrj.request.UpdateRequest)6 SolrParams (org.apache.solr.common.params.SolrParams)6 Test (org.junit.Test)6 GroupOperation (org.apache.solr.client.solrj.io.ops.GroupOperation)4 MultipleFieldEqualitor (org.apache.solr.client.solrj.io.eq.MultipleFieldEqualitor)3 StreamEqualitor (org.apache.solr.client.solrj.io.eq.StreamEqualitor)3 Map (java.util.Map)2 StreamComparator (org.apache.solr.client.solrj.io.comp.StreamComparator)2 IOException (java.io.IOException)1 StreamFactory (org.apache.solr.client.solrj.io.stream.expr.StreamFactory)1