Search in sources :

Example 21 with FieldComparator

use of org.apache.solr.client.solrj.io.comp.FieldComparator in project lucene-solr by apache.

the class SolrTable method getComps.

private static FieldComparator[] getComps(List<Pair<String, String>> orders) {
    FieldComparator[] comps = new FieldComparator[orders.size()];
    for (int i = 0; i < orders.size(); i++) {
        Pair<String, String> sortItem = orders.get(i);
        String ordering = sortItem.getValue();
        ComparatorOrder comparatorOrder = ascDescComp(ordering);
        String sortKey = sortItem.getKey();
        comps[i] = new FieldComparator(sortKey, comparatorOrder);
    }
    return comps;
}
Also used : FieldComparator(org.apache.solr.client.solrj.io.comp.FieldComparator) MultipleFieldComparator(org.apache.solr.client.solrj.io.comp.MultipleFieldComparator) ComparatorOrder(org.apache.solr.client.solrj.io.comp.ComparatorOrder)

Example 22 with FieldComparator

use of org.apache.solr.client.solrj.io.comp.FieldComparator in project lucene-solr by apache.

the class BiJoinStream method createSideComparator.

private StreamComparator createSideComparator(StreamEqualitor eq, StreamComparator comp) throws IOException {
    if (eq instanceof MultipleFieldEqualitor && comp instanceof MultipleFieldComparator) {
        // we know the comp is at least as long as the eq because we've already validated the tuple order
        StreamComparator[] compoundComps = new StreamComparator[((MultipleFieldEqualitor) eq).getEqs().length];
        for (int idx = 0; idx < compoundComps.length; ++idx) {
            StreamComparator sourceComparator = ((MultipleFieldComparator) comp).getComps()[idx];
            if (sourceComparator instanceof FieldComparator) {
                FieldComparator fieldComparator = (FieldComparator) sourceComparator;
                compoundComps[idx] = new FieldComparator(fieldComparator.getLeftFieldName(), fieldComparator.getRightFieldName(), fieldComparator.getOrder());
            } else {
                throw new IOException("Failed to create an side comparator");
            }
        }
        return new MultipleFieldComparator(compoundComps);
    } else if (comp instanceof MultipleFieldComparator) {
        StreamComparator sourceComparator = ((MultipleFieldComparator) comp).getComps()[0];
        if (sourceComparator instanceof FieldComparator) {
            FieldComparator fieldComparator = (FieldComparator) sourceComparator;
            return new FieldComparator(fieldComparator.getLeftFieldName(), fieldComparator.getRightFieldName(), fieldComparator.getOrder());
        } else {
            throw new IOException("Failed to create an side comparator");
        }
    } else {
        StreamComparator sourceComparator = comp;
        if (sourceComparator instanceof FieldComparator) {
            FieldComparator fieldComparator = (FieldComparator) sourceComparator;
            return new FieldComparator(fieldComparator.getLeftFieldName(), fieldComparator.getRightFieldName(), fieldComparator.getOrder());
        } else {
            throw new IOException("Failed to create an side comparator");
        }
    }
}
Also used : MultipleFieldEqualitor(org.apache.solr.client.solrj.io.eq.MultipleFieldEqualitor) StreamComparator(org.apache.solr.client.solrj.io.comp.StreamComparator) 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) IOException(java.io.IOException)

Example 23 with FieldComparator

use of org.apache.solr.client.solrj.io.comp.FieldComparator 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 24 with FieldComparator

use of org.apache.solr.client.solrj.io.comp.FieldComparator 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 25 with FieldComparator

use of org.apache.solr.client.solrj.io.comp.FieldComparator in project lucene-solr by apache.

the class TopicStream method init.

private void init(String zkHost, String checkpointCollection, String collection, String id, long initialCheckpoint, long checkpointEvery, SolrParams params) {
    this.zkHost = zkHost;
    ModifiableSolrParams mParams = new ModifiableSolrParams(params);
    if (mParams.getParams("rows") == null) {
        mParams.set("rows", "500");
    }
    this.params = mParams;
    this.collection = collection;
    this.checkpointCollection = checkpointCollection;
    this.checkpointEvery = checkpointEvery;
    this.id = id;
    this.initialCheckpoint = initialCheckpoint;
    this.comp = new FieldComparator("_version_", ComparatorOrder.ASCENDING);
}
Also used : FieldComparator(org.apache.solr.client.solrj.io.comp.FieldComparator) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Aggregations

FieldComparator (org.apache.solr.client.solrj.io.comp.FieldComparator)39 MultipleFieldComparator (org.apache.solr.client.solrj.io.comp.MultipleFieldComparator)30 Tuple (org.apache.solr.client.solrj.io.Tuple)23 Test (org.junit.Test)23 UpdateRequest (org.apache.solr.client.solrj.request.UpdateRequest)21 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)21 SolrClientCache (org.apache.solr.client.solrj.io.SolrClientCache)20 SolrParams (org.apache.solr.common.params.SolrParams)15 FieldEqualitor (org.apache.solr.client.solrj.io.eq.FieldEqualitor)8 StreamFactory (org.apache.solr.client.solrj.io.stream.expr.StreamFactory)8 IOException (java.io.IOException)7 ComparatorOrder (org.apache.solr.client.solrj.io.comp.ComparatorOrder)5 MeanMetric (org.apache.solr.client.solrj.io.stream.metrics.MeanMetric)5 MinMetric (org.apache.solr.client.solrj.io.stream.metrics.MinMetric)5 StreamComparator (org.apache.solr.client.solrj.io.comp.StreamComparator)4 MultipleFieldEqualitor (org.apache.solr.client.solrj.io.eq.MultipleFieldEqualitor)4 GroupOperation (org.apache.solr.client.solrj.io.ops.GroupOperation)4 StreamExpression (org.apache.solr.client.solrj.io.stream.expr.StreamExpression)4 Bucket (org.apache.solr.client.solrj.io.stream.metrics.Bucket)4 CountMetric (org.apache.solr.client.solrj.io.stream.metrics.CountMetric)4