Search in sources :

Example 1 with MinMetric

use of org.apache.solr.client.solrj.io.stream.metrics.MinMetric in project lucene-solr by apache.

the class StreamingTest method testFacetStream.

@Test
public void testFacetStream() 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", "a_s,a_i,a_f", "sort", "a_s asc");
        Bucket[] buckets = { new Bucket("a_s") };
        Metric[] metrics = { new SumMetric("a_i"), new SumMetric("a_f"), new MinMetric("a_i"), new MinMetric("a_f"), new MaxMetric("a_i"), new MaxMetric("a_f"), new MeanMetric("a_i"), new MeanMetric("a_f"), new CountMetric() };
        FieldComparator[] sorts = { new FieldComparator("sum(a_i)", ComparatorOrder.ASCENDING) };
        FacetStream facetStream = new FacetStream(zkHost, COLLECTIONORALIAS, sParamsA, buckets, metrics, sorts, 100);
        List<Tuple> tuples = getTuples(facetStream);
        assert (tuples.size() == 3);
        //Test Long and Double Sums
        Tuple tuple = tuples.get(0);
        String bucket = tuple.getString("a_s");
        Double sumi = tuple.getDouble("sum(a_i)");
        Double sumf = tuple.getDouble("sum(a_f)");
        Double mini = tuple.getDouble("min(a_i)");
        Double minf = tuple.getDouble("min(a_f)");
        Double maxi = tuple.getDouble("max(a_i)");
        Double maxf = tuple.getDouble("max(a_f)");
        Double avgi = tuple.getDouble("avg(a_i)");
        Double avgf = tuple.getDouble("avg(a_f)");
        Double count = tuple.getDouble("count(*)");
        assertEquals("hello4", bucket);
        assertEquals(15, sumi.longValue());
        assertEquals(11.0, sumf.doubleValue(), 0.01);
        assertEquals(4.0, mini.doubleValue(), 0.01);
        assertEquals(4.0, minf.doubleValue(), 0.01);
        assertEquals(11.0, maxi.doubleValue(), 0.01);
        assertEquals(7.0, maxf.doubleValue(), 0.01);
        assertEquals(7.5, avgi.doubleValue(), 0.01);
        assertEquals(5.5, avgf.doubleValue(), 0.01);
        assertEquals(2, count.doubleValue(), 0.01);
        tuple = tuples.get(1);
        bucket = tuple.getString("a_s");
        sumi = tuple.getDouble("sum(a_i)");
        sumf = tuple.getDouble("sum(a_f)");
        mini = tuple.getDouble("min(a_i)");
        minf = tuple.getDouble("min(a_f)");
        maxi = tuple.getDouble("max(a_i)");
        maxf = tuple.getDouble("max(a_f)");
        avgi = tuple.getDouble("avg(a_i)");
        avgf = tuple.getDouble("avg(a_f)");
        count = tuple.getDouble("count(*)");
        assertEquals("hello0", bucket);
        assertEquals(17, sumi.doubleValue(), .01);
        assertEquals(18, sumf.doubleValue(), .01);
        assertEquals(0.0, mini.doubleValue(), .01);
        assertEquals(1.0, minf.doubleValue(), .01);
        assertEquals(14.0, maxi.doubleValue(), .01);
        assertEquals(10.0, maxf.doubleValue(), .01);
        assertEquals(4.25, avgi.doubleValue(), .01);
        assertEquals(4.5, avgf.doubleValue(), .01);
        assertEquals(4, count.doubleValue(), .01);
        tuple = tuples.get(2);
        bucket = tuple.getString("a_s");
        sumi = tuple.getDouble("sum(a_i)");
        sumf = tuple.getDouble("sum(a_f)");
        mini = tuple.getDouble("min(a_i)");
        minf = tuple.getDouble("min(a_f)");
        maxi = tuple.getDouble("max(a_i)");
        maxf = tuple.getDouble("max(a_f)");
        avgi = tuple.getDouble("avg(a_i)");
        avgf = tuple.getDouble("avg(a_f)");
        count = tuple.getDouble("count(*)");
        assertEquals("hello3", bucket);
        assertEquals(38.0, sumi.doubleValue(), 0.01);
        assertEquals(26.0, sumf.doubleValue(), 0.01);
        assertEquals(3.0, mini.doubleValue(), 0.01);
        assertEquals(3.0, minf.doubleValue(), 0.01);
        assertEquals(13.0, maxi.doubleValue(), 0.01);
        assertEquals(9.0, maxf.doubleValue(), 0.01);
        assertEquals(9.5, avgi.doubleValue(), 0.01);
        assertEquals(6.5, avgf.doubleValue(), 0.01);
        assertEquals(4, count.doubleValue(), 0.01);
        //Reverse the Sort.
        sorts[0] = new FieldComparator("sum(a_i)", ComparatorOrder.DESCENDING);
        facetStream = new FacetStream(zkHost, COLLECTIONORALIAS, sParamsA, buckets, metrics, sorts, 100);
        tuples = getTuples(facetStream);
        assertEquals(3, tuples.size());
        //Test Long and Double Sums
        tuple = tuples.get(0);
        bucket = tuple.getString("a_s");
        sumi = tuple.getDouble("sum(a_i)");
        sumf = tuple.getDouble("sum(a_f)");
        mini = tuple.getDouble("min(a_i)");
        minf = tuple.getDouble("min(a_f)");
        maxi = tuple.getDouble("max(a_i)");
        maxf = tuple.getDouble("max(a_f)");
        avgi = tuple.getDouble("avg(a_i)");
        avgf = tuple.getDouble("avg(a_f)");
        count = tuple.getDouble("count(*)");
        assertEquals("hello3", bucket);
        assertEquals(38, sumi.doubleValue(), 0.1);
        assertEquals(26, sumf.doubleValue(), 0.1);
        assertEquals(3, mini.doubleValue(), 0.1);
        assertEquals(3, minf.doubleValue(), 0.1);
        assertEquals(13, maxi.doubleValue(), 0.1);
        assertEquals(9, maxf.doubleValue(), 0.1);
        assertEquals(9.5, avgi.doubleValue(), 0.1);
        assertEquals(6.5, avgf.doubleValue(), 0.1);
        assertEquals(4, count.doubleValue(), 0.1);
        tuple = tuples.get(1);
        bucket = tuple.getString("a_s");
        sumi = tuple.getDouble("sum(a_i)");
        sumf = tuple.getDouble("sum(a_f)");
        mini = tuple.getDouble("min(a_i)");
        minf = tuple.getDouble("min(a_f)");
        maxi = tuple.getDouble("max(a_i)");
        maxf = tuple.getDouble("max(a_f)");
        avgi = tuple.getDouble("avg(a_i)");
        avgf = tuple.getDouble("avg(a_f)");
        count = tuple.getDouble("count(*)");
        assertEquals("hello0", bucket);
        assertEquals(17, sumi.doubleValue(), 0.01);
        assertEquals(18, sumf.doubleValue(), 0.01);
        assertEquals(0, mini.doubleValue(), 0.01);
        assertEquals(1, minf.doubleValue(), 0.01);
        assertEquals(14, maxi.doubleValue(), 0.01);
        assertEquals(10, maxf.doubleValue(), 0.01);
        assertEquals(4.25, avgi.doubleValue(), 0.01);
        assertEquals(4.5, avgf.doubleValue(), 0.01);
        assertEquals(4, count.doubleValue(), 0.01);
        tuple = tuples.get(2);
        bucket = tuple.getString("a_s");
        sumi = tuple.getDouble("sum(a_i)");
        sumf = tuple.getDouble("sum(a_f)");
        mini = tuple.getDouble("min(a_i)");
        minf = tuple.getDouble("min(a_f)");
        maxi = tuple.getDouble("max(a_i)");
        maxf = tuple.getDouble("max(a_f)");
        avgi = tuple.getDouble("avg(a_i)");
        avgf = tuple.getDouble("avg(a_f)");
        count = tuple.getDouble("count(*)");
        assertEquals("hello4", bucket);
        assertEquals(15, sumi.longValue());
        assertEquals(11, sumf.doubleValue(), 0.01);
        assertEquals(4.0, mini.doubleValue(), 0.01);
        assertEquals(4.0, minf.doubleValue(), 0.01);
        assertEquals(11.0, maxi.doubleValue(), 0.01);
        assertEquals(7.0, maxf.doubleValue(), 0.01);
        assertEquals(7.5, avgi.doubleValue(), 0.01);
        assertEquals(5.5, avgf.doubleValue(), 0.01);
        assertEquals(2, count.doubleValue(), 0.01);
        //Test index sort
        sorts[0] = new FieldComparator("a_s", ComparatorOrder.DESCENDING);
        facetStream = new FacetStream(zkHost, COLLECTIONORALIAS, sParamsA, buckets, metrics, sorts, 100);
        facetStream.setStreamContext(streamContext);
        tuples = getTuples(facetStream);
        assertEquals(3, tuples.size());
        tuple = tuples.get(0);
        bucket = tuple.getString("a_s");
        sumi = tuple.getDouble("sum(a_i)");
        sumf = tuple.getDouble("sum(a_f)");
        mini = tuple.getDouble("min(a_i)");
        minf = tuple.getDouble("min(a_f)");
        maxi = tuple.getDouble("max(a_i)");
        maxf = tuple.getDouble("max(a_f)");
        avgi = tuple.getDouble("avg(a_i)");
        avgf = tuple.getDouble("avg(a_f)");
        count = tuple.getDouble("count(*)");
        assertEquals("hello4", bucket);
        assertEquals(15, sumi.longValue());
        assertEquals(11, sumf.doubleValue(), 0.01);
        assertEquals(4, mini.doubleValue(), 0.01);
        assertEquals(4, minf.doubleValue(), 0.01);
        assertEquals(11, maxi.doubleValue(), 0.01);
        assertEquals(7, maxf.doubleValue(), 0.01);
        assertEquals(7.5, avgi.doubleValue(), 0.01);
        assertEquals(5.5, avgf.doubleValue(), 0.01);
        assertEquals(2, count.doubleValue(), 0.01);
        tuple = tuples.get(1);
        bucket = tuple.getString("a_s");
        sumi = tuple.getDouble("sum(a_i)");
        sumf = tuple.getDouble("sum(a_f)");
        mini = tuple.getDouble("min(a_i)");
        minf = tuple.getDouble("min(a_f)");
        maxi = tuple.getDouble("max(a_i)");
        maxf = tuple.getDouble("max(a_f)");
        avgi = tuple.getDouble("avg(a_i)");
        avgf = tuple.getDouble("avg(a_f)");
        count = tuple.getDouble("count(*)");
        assertTrue(bucket.equals("hello3"));
        assertTrue(sumi.doubleValue() == 38.0D);
        assertTrue(sumf.doubleValue() == 26.0D);
        assertTrue(mini.doubleValue() == 3.0D);
        assertTrue(minf.doubleValue() == 3.0D);
        assertTrue(maxi.doubleValue() == 13.0D);
        assertTrue(maxf.doubleValue() == 9.0D);
        assertTrue(avgi.doubleValue() == 9.5D);
        assertTrue(avgf.doubleValue() == 6.5D);
        assertTrue(count.doubleValue() == 4);
        tuple = tuples.get(2);
        bucket = tuple.getString("a_s");
        sumi = tuple.getDouble("sum(a_i)");
        sumf = tuple.getDouble("sum(a_f)");
        mini = tuple.getDouble("min(a_i)");
        minf = tuple.getDouble("min(a_f)");
        maxi = tuple.getDouble("max(a_i)");
        maxf = tuple.getDouble("max(a_f)");
        avgi = tuple.getDouble("avg(a_i)");
        avgf = tuple.getDouble("avg(a_f)");
        count = tuple.getDouble("count(*)");
        assertEquals("hello0", bucket);
        assertEquals(17, sumi.doubleValue(), 0.01);
        assertEquals(18, sumf.doubleValue(), 0.01);
        assertEquals(0, mini.doubleValue(), 0.01);
        assertEquals(1, minf.doubleValue(), 0.01);
        assertEquals(14, maxi.doubleValue(), 0.01);
        assertEquals(10, maxf.doubleValue(), 0.01);
        assertEquals(4.25, avgi.doubleValue(), 0.01);
        assertEquals(4.5, avgf.doubleValue(), 0.01);
        assertEquals(4, count.doubleValue(), 0.01);
        //Test index sort
        sorts[0] = new FieldComparator("a_s", ComparatorOrder.ASCENDING);
        facetStream = new FacetStream(zkHost, COLLECTIONORALIAS, sParamsA, buckets, metrics, sorts, 100);
        facetStream.setStreamContext(streamContext);
        tuples = getTuples(facetStream);
        assertEquals(3, tuples.size());
        tuple = tuples.get(0);
        bucket = tuple.getString("a_s");
        sumi = tuple.getDouble("sum(a_i)");
        sumf = tuple.getDouble("sum(a_f)");
        mini = tuple.getDouble("min(a_i)");
        minf = tuple.getDouble("min(a_f)");
        maxi = tuple.getDouble("max(a_i)");
        maxf = tuple.getDouble("max(a_f)");
        avgi = tuple.getDouble("avg(a_i)");
        avgf = tuple.getDouble("avg(a_f)");
        count = tuple.getDouble("count(*)");
        assertEquals("hello0", bucket);
        assertEquals(17, sumi.doubleValue(), 0.01);
        assertEquals(18, sumf.doubleValue(), 0.01);
        assertEquals(0, mini.doubleValue(), 0.01);
        assertEquals(1, minf.doubleValue(), 0.01);
        assertEquals(14, maxi.doubleValue(), 0.01);
        assertEquals(10, maxf.doubleValue(), 0.01);
        assertEquals(4.25, avgi.doubleValue(), 0.0001);
        assertEquals(4.5, avgf.doubleValue(), 0.001);
        assertEquals(4, count.doubleValue(), 0.01);
        tuple = tuples.get(1);
        bucket = tuple.getString("a_s");
        sumi = tuple.getDouble("sum(a_i)");
        sumf = tuple.getDouble("sum(a_f)");
        mini = tuple.getDouble("min(a_i)");
        minf = tuple.getDouble("min(a_f)");
        maxi = tuple.getDouble("max(a_i)");
        maxf = tuple.getDouble("max(a_f)");
        avgi = tuple.getDouble("avg(a_i)");
        avgf = tuple.getDouble("avg(a_f)");
        count = tuple.getDouble("count(*)");
        assertEquals("hello3", bucket);
        assertEquals(38, sumi.doubleValue(), 0.01);
        assertEquals(26, sumf.doubleValue(), 0.01);
        assertEquals(3, mini.doubleValue(), 0.01);
        assertEquals(3, minf.doubleValue(), 0.01);
        assertEquals(13, maxi.doubleValue(), 0.01);
        assertEquals(9, maxf.doubleValue(), 0.01);
        assertEquals(9.5, avgi.doubleValue(), 0.01);
        assertEquals(6.5, avgf.doubleValue(), 0.01);
        assertEquals(4, count.doubleValue(), 0.01);
        tuple = tuples.get(2);
        bucket = tuple.getString("a_s");
        sumi = tuple.getDouble("sum(a_i)");
        sumf = tuple.getDouble("sum(a_f)");
        mini = tuple.getDouble("min(a_i)");
        minf = tuple.getDouble("min(a_f)");
        maxi = tuple.getDouble("max(a_i)");
        maxf = tuple.getDouble("max(a_f)");
        avgi = tuple.getDouble("avg(a_i)");
        avgf = tuple.getDouble("avg(a_f)");
        count = tuple.getDouble("count(*)");
        assertEquals("hello4", bucket);
        assertEquals(15, sumi.longValue());
        assertEquals(11.0, sumf.doubleValue(), 0.1);
        assertEquals(4.0, mini.doubleValue(), 0.1);
        assertEquals(4.0, minf.doubleValue(), 0.1);
        assertEquals(11.0, maxi.doubleValue(), 0.1);
        assertEquals(7.0, maxf.doubleValue(), 0.1);
        assertEquals(7.5, avgi.doubleValue(), 0.1);
        assertEquals(5.5, avgf.doubleValue(), 0.1);
        assertEquals(2, count.doubleValue(), 0.1);
    } finally {
        solrClientCache.close();
    }
}
Also used : UpdateRequest(org.apache.solr.client.solrj.request.UpdateRequest) CountMetric(org.apache.solr.client.solrj.io.stream.metrics.CountMetric) MaxMetric(org.apache.solr.client.solrj.io.stream.metrics.MaxMetric) MinMetric(org.apache.solr.client.solrj.io.stream.metrics.MinMetric) SumMetric(org.apache.solr.client.solrj.io.stream.metrics.SumMetric) MeanMetric(org.apache.solr.client.solrj.io.stream.metrics.MeanMetric) Bucket(org.apache.solr.client.solrj.io.stream.metrics.Bucket) 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) MinMetric(org.apache.solr.client.solrj.io.stream.metrics.MinMetric) SumMetric(org.apache.solr.client.solrj.io.stream.metrics.SumMetric) Metric(org.apache.solr.client.solrj.io.stream.metrics.Metric) MeanMetric(org.apache.solr.client.solrj.io.stream.metrics.MeanMetric) CountMetric(org.apache.solr.client.solrj.io.stream.metrics.CountMetric) MaxMetric(org.apache.solr.client.solrj.io.stream.metrics.MaxMetric) Tuple(org.apache.solr.client.solrj.io.Tuple) Test(org.junit.Test)

Example 2 with MinMetric

use of org.apache.solr.client.solrj.io.stream.metrics.MinMetric in project lucene-solr by apache.

the class StreamingTest method testRollupStream.

@Test
public void testRollupStream() 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", "a_s,a_i,a_f", "sort", "a_s asc");
        CloudSolrStream stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsA);
        Bucket[] buckets = { new Bucket("a_s") };
        Metric[] metrics = { new SumMetric("a_i"), new SumMetric("a_f"), new MinMetric("a_i"), new MinMetric("a_f"), new MaxMetric("a_i"), new MaxMetric("a_f"), new MeanMetric("a_i"), new MeanMetric("a_f"), new CountMetric() };
        RollupStream rollupStream = new RollupStream(stream, buckets, metrics);
        rollupStream.setStreamContext(streamContext);
        List<Tuple> tuples = getTuples(rollupStream);
        assert (tuples.size() == 3);
        //Test Long and Double Sums
        Tuple tuple = tuples.get(0);
        String bucket = tuple.getString("a_s");
        Double sumi = tuple.getDouble("sum(a_i)");
        Double sumf = tuple.getDouble("sum(a_f)");
        Double mini = tuple.getDouble("min(a_i)");
        Double minf = tuple.getDouble("min(a_f)");
        Double maxi = tuple.getDouble("max(a_i)");
        Double maxf = tuple.getDouble("max(a_f)");
        Double avgi = tuple.getDouble("avg(a_i)");
        Double avgf = tuple.getDouble("avg(a_f)");
        Double count = tuple.getDouble("count(*)");
        assertEquals("hello0", bucket);
        assertEquals(17, sumi.doubleValue(), 0.001);
        assertEquals(18, sumf.doubleValue(), 0.001);
        assertEquals(0, mini.doubleValue(), 0.001);
        assertEquals(1, minf.doubleValue(), 0.001);
        assertEquals(14, maxi.doubleValue(), 0.001);
        assertEquals(10, maxf.doubleValue(), 0.001);
        assertEquals(4.25, avgi.doubleValue(), 0.001);
        assertEquals(4.5, avgf.doubleValue(), 0.001);
        assertEquals(4, count.doubleValue(), 0.001);
        tuple = tuples.get(1);
        bucket = tuple.getString("a_s");
        sumi = tuple.getDouble("sum(a_i)");
        sumf = tuple.getDouble("sum(a_f)");
        mini = tuple.getDouble("min(a_i)");
        minf = tuple.getDouble("min(a_f)");
        maxi = tuple.getDouble("max(a_i)");
        maxf = tuple.getDouble("max(a_f)");
        avgi = tuple.getDouble("avg(a_i)");
        avgf = tuple.getDouble("avg(a_f)");
        count = tuple.getDouble("count(*)");
        assertEquals("hello3", bucket);
        assertEquals(38, sumi.doubleValue(), 0.001);
        assertEquals(26, sumf.doubleValue(), 0.001);
        assertEquals(3, mini.doubleValue(), 0.001);
        assertEquals(3, minf.doubleValue(), 0.001);
        assertEquals(13, maxi.doubleValue(), 0.001);
        assertEquals(9, maxf.doubleValue(), 0.001);
        assertEquals(9.5, avgi.doubleValue(), 0.001);
        assertEquals(6.5, avgf.doubleValue(), 0.001);
        assertEquals(4, count.doubleValue(), 0.001);
        tuple = tuples.get(2);
        bucket = tuple.getString("a_s");
        sumi = tuple.getDouble("sum(a_i)");
        sumf = tuple.getDouble("sum(a_f)");
        mini = tuple.getDouble("min(a_i)");
        minf = tuple.getDouble("min(a_f)");
        maxi = tuple.getDouble("max(a_i)");
        maxf = tuple.getDouble("max(a_f)");
        avgi = tuple.getDouble("avg(a_i)");
        avgf = tuple.getDouble("avg(a_f)");
        count = tuple.getDouble("count(*)");
        assertEquals("hello4", bucket);
        assertEquals(15, sumi.longValue());
        assertEquals(11, sumf.doubleValue(), 0.01);
        assertEquals(4, mini.doubleValue(), 0.01);
        assertEquals(4, minf.doubleValue(), 0.01);
        assertEquals(11, maxi.doubleValue(), 0.01);
        assertEquals(7, maxf.doubleValue(), 0.01);
        assertEquals(7.5, avgi.doubleValue(), 0.01);
        assertEquals(5.5, avgf.doubleValue(), 0.01);
        assertEquals(2, count.doubleValue(), 0.01);
        // Test will null metrics
        rollupStream = new RollupStream(stream, buckets, metrics);
        rollupStream.setStreamContext(streamContext);
        tuples = getTuples(rollupStream);
        assert (tuples.size() == 3);
        tuple = tuples.get(0);
        bucket = tuple.getString("a_s");
        assertTrue(bucket.equals("hello0"));
        tuple = tuples.get(1);
        bucket = tuple.getString("a_s");
        assertTrue(bucket.equals("hello3"));
        tuple = tuples.get(2);
        bucket = tuple.getString("a_s");
        assertTrue(bucket.equals("hello4"));
        //Test will null value in the grouping field
        new UpdateRequest().add(id, "12", "a_s", null, "a_i", "14", "a_f", "10").commit(cluster.getSolrClient(), COLLECTIONORALIAS);
        sParamsA = mapParams("q", "*:*", "fl", "a_s,a_i,a_f", "sort", "a_s asc", "qt", "/export");
        stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsA);
        Bucket[] buckets1 = { new Bucket("a_s") };
        Metric[] metrics1 = { new SumMetric("a_i"), new SumMetric("a_f"), new MinMetric("a_i"), new MinMetric("a_f"), new MaxMetric("a_i"), new MaxMetric("a_f"), new MeanMetric("a_i"), new MeanMetric("a_f"), new CountMetric() };
        rollupStream = new RollupStream(stream, buckets1, metrics1);
        rollupStream.setStreamContext(streamContext);
        tuples = getTuples(rollupStream);
        //Check that we've got the extra NULL bucket
        assertEquals(4, tuples.size());
        tuple = tuples.get(0);
        assertEquals("NULL", tuple.getString("a_s"));
        sumi = tuple.getDouble("sum(a_i)");
        sumf = tuple.getDouble("sum(a_f)");
        mini = tuple.getDouble("min(a_i)");
        minf = tuple.getDouble("min(a_f)");
        maxi = tuple.getDouble("max(a_i)");
        maxf = tuple.getDouble("max(a_f)");
        avgi = tuple.getDouble("avg(a_i)");
        avgf = tuple.getDouble("avg(a_f)");
        count = tuple.getDouble("count(*)");
        assertEquals(14, sumi.doubleValue(), 0.01);
        assertEquals(10, sumf.doubleValue(), 0.01);
        assertEquals(14, mini.doubleValue(), 0.01);
        assertEquals(10, minf.doubleValue(), 0.01);
        assertEquals(14, maxi.doubleValue(), 0.01);
        assertEquals(10, maxf.doubleValue(), 0.01);
        assertEquals(14, avgi.doubleValue(), 0.01);
        assertEquals(10, avgf.doubleValue(), 0.01);
        assertEquals(1, count.doubleValue(), 0.01);
    } finally {
        solrClientCache.close();
    }
}
Also used : UpdateRequest(org.apache.solr.client.solrj.request.UpdateRequest) CountMetric(org.apache.solr.client.solrj.io.stream.metrics.CountMetric) MaxMetric(org.apache.solr.client.solrj.io.stream.metrics.MaxMetric) MinMetric(org.apache.solr.client.solrj.io.stream.metrics.MinMetric) SumMetric(org.apache.solr.client.solrj.io.stream.metrics.SumMetric) MeanMetric(org.apache.solr.client.solrj.io.stream.metrics.MeanMetric) Bucket(org.apache.solr.client.solrj.io.stream.metrics.Bucket) SolrClientCache(org.apache.solr.client.solrj.io.SolrClientCache) SolrParams(org.apache.solr.common.params.SolrParams) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) MinMetric(org.apache.solr.client.solrj.io.stream.metrics.MinMetric) SumMetric(org.apache.solr.client.solrj.io.stream.metrics.SumMetric) Metric(org.apache.solr.client.solrj.io.stream.metrics.Metric) MeanMetric(org.apache.solr.client.solrj.io.stream.metrics.MeanMetric) CountMetric(org.apache.solr.client.solrj.io.stream.metrics.CountMetric) MaxMetric(org.apache.solr.client.solrj.io.stream.metrics.MaxMetric) Tuple(org.apache.solr.client.solrj.io.Tuple) Test(org.junit.Test)

Example 3 with MinMetric

use of org.apache.solr.client.solrj.io.stream.metrics.MinMetric in project lucene-solr by apache.

the class StreamExpressionToExpessionTest method testMinMetric.

@Test
public void testMinMetric() throws Exception {
    Metric metric;
    String expressionString;
    // Basic test
    metric = new MinMetric(StreamExpressionParser.parse("min(foo)"), factory);
    expressionString = metric.toExpression(factory).toString();
    assertEquals("min(foo)", expressionString);
}
Also used : MeanMetric(org.apache.solr.client.solrj.io.stream.metrics.MeanMetric) MinMetric(org.apache.solr.client.solrj.io.stream.metrics.MinMetric) CountMetric(org.apache.solr.client.solrj.io.stream.metrics.CountMetric) MaxMetric(org.apache.solr.client.solrj.io.stream.metrics.MaxMetric) Metric(org.apache.solr.client.solrj.io.stream.metrics.Metric) SumMetric(org.apache.solr.client.solrj.io.stream.metrics.SumMetric) MinMetric(org.apache.solr.client.solrj.io.stream.metrics.MinMetric) Test(org.junit.Test)

Example 4 with MinMetric

use of org.apache.solr.client.solrj.io.stream.metrics.MinMetric in project lucene-solr by apache.

the class StreamingTest method testParallelRollupStream.

@Test
public void testParallelRollupStream() 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", "a_s,a_i,a_f", "sort", "a_s asc", "partitionKeys", "a_s");
        CloudSolrStream stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsA);
        Bucket[] buckets = { new Bucket("a_s") };
        Metric[] metrics = { new SumMetric("a_i"), new SumMetric("a_f"), new MinMetric("a_i"), new MinMetric("a_f"), new MaxMetric("a_i"), new MaxMetric("a_f"), new MeanMetric("a_i"), new MeanMetric("a_f"), new CountMetric() };
        RollupStream rollupStream = new RollupStream(stream, buckets, metrics);
        ParallelStream parallelStream = parallelStream(rollupStream, new FieldComparator("a_s", ComparatorOrder.ASCENDING));
        attachStreamFactory(parallelStream);
        parallelStream.setStreamContext(streamContext);
        List<Tuple> tuples = getTuples(parallelStream);
        assertEquals(3, tuples.size());
        //Test Long and Double Sums
        Tuple tuple = tuples.get(0);
        String bucket = tuple.getString("a_s");
        Double sumi = tuple.getDouble("sum(a_i)");
        Double sumf = tuple.getDouble("sum(a_f)");
        Double mini = tuple.getDouble("min(a_i)");
        Double minf = tuple.getDouble("min(a_f)");
        Double maxi = tuple.getDouble("max(a_i)");
        Double maxf = tuple.getDouble("max(a_f)");
        Double avgi = tuple.getDouble("avg(a_i)");
        Double avgf = tuple.getDouble("avg(a_f)");
        Double count = tuple.getDouble("count(*)");
        assertEquals("hello0", bucket);
        assertEquals(17, sumi.doubleValue(), 0.001);
        assertEquals(18, sumf.doubleValue(), 0.001);
        assertEquals(0, mini.doubleValue(), 0.001);
        assertEquals(1, minf.doubleValue(), 0.001);
        assertEquals(14, maxi.doubleValue(), 0.001);
        assertEquals(10, maxf.doubleValue(), 0.001);
        assertEquals(4.25, avgi.doubleValue(), 0.001);
        assertEquals(4.5, avgf.doubleValue(), 0.001);
        assertEquals(4, count.doubleValue(), 0.001);
        tuple = tuples.get(1);
        bucket = tuple.getString("a_s");
        sumi = tuple.getDouble("sum(a_i)");
        sumf = tuple.getDouble("sum(a_f)");
        mini = tuple.getDouble("min(a_i)");
        minf = tuple.getDouble("min(a_f)");
        maxi = tuple.getDouble("max(a_i)");
        maxf = tuple.getDouble("max(a_f)");
        avgi = tuple.getDouble("avg(a_i)");
        avgf = tuple.getDouble("avg(a_f)");
        count = tuple.getDouble("count(*)");
        assertEquals("hello3", bucket);
        assertEquals(38, sumi.doubleValue(), 0.001);
        assertEquals(26, sumf.doubleValue(), 0.001);
        assertEquals(3, mini.doubleValue(), 0.001);
        assertEquals(3, minf.doubleValue(), 0.001);
        assertEquals(13, maxi.doubleValue(), 0.001);
        assertEquals(9, maxf.doubleValue(), 0.001);
        assertEquals(9.5, avgi.doubleValue(), 0.001);
        assertEquals(6.5, avgf.doubleValue(), 0.001);
        assertEquals(4, count.doubleValue(), 0.001);
        tuple = tuples.get(2);
        bucket = tuple.getString("a_s");
        sumi = tuple.getDouble("sum(a_i)");
        sumf = tuple.getDouble("sum(a_f)");
        mini = tuple.getDouble("min(a_i)");
        minf = tuple.getDouble("min(a_f)");
        maxi = tuple.getDouble("max(a_i)");
        maxf = tuple.getDouble("max(a_f)");
        avgi = tuple.getDouble("avg(a_i)");
        avgf = tuple.getDouble("avg(a_f)");
        count = tuple.getDouble("count(*)");
        assertEquals("hello4", bucket);
        assertEquals(15, sumi.longValue());
        assertEquals(11, sumf.doubleValue(), 0.001);
        assertEquals(4, mini.doubleValue(), 0.001);
        assertEquals(4, minf.doubleValue(), 0.001);
        assertEquals(11, maxi.doubleValue(), 0.001);
        assertEquals(7, maxf.doubleValue(), 0.001);
        assertEquals(7.5, avgi.doubleValue(), 0.001);
        assertEquals(5.5, avgf.doubleValue(), 0.001);
        assertEquals(2, count.doubleValue(), 0.001);
    } finally {
        solrClientCache.close();
    }
}
Also used : UpdateRequest(org.apache.solr.client.solrj.request.UpdateRequest) CountMetric(org.apache.solr.client.solrj.io.stream.metrics.CountMetric) MaxMetric(org.apache.solr.client.solrj.io.stream.metrics.MaxMetric) MinMetric(org.apache.solr.client.solrj.io.stream.metrics.MinMetric) SumMetric(org.apache.solr.client.solrj.io.stream.metrics.SumMetric) MeanMetric(org.apache.solr.client.solrj.io.stream.metrics.MeanMetric) Bucket(org.apache.solr.client.solrj.io.stream.metrics.Bucket) 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) MinMetric(org.apache.solr.client.solrj.io.stream.metrics.MinMetric) SumMetric(org.apache.solr.client.solrj.io.stream.metrics.SumMetric) Metric(org.apache.solr.client.solrj.io.stream.metrics.Metric) MeanMetric(org.apache.solr.client.solrj.io.stream.metrics.MeanMetric) CountMetric(org.apache.solr.client.solrj.io.stream.metrics.CountMetric) MaxMetric(org.apache.solr.client.solrj.io.stream.metrics.MaxMetric) Tuple(org.apache.solr.client.solrj.io.Tuple) Test(org.junit.Test)

Example 5 with MinMetric

use of org.apache.solr.client.solrj.io.stream.metrics.MinMetric in project lucene-solr by apache.

the class StreamingTest method testStatsStream.

@Test
public void testStatsStream() 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", "*:*");
        Metric[] metrics = { new SumMetric("a_i"), new SumMetric("a_f"), new MinMetric("a_i"), new MinMetric("a_f"), new MaxMetric("a_i"), new MaxMetric("a_f"), new MeanMetric("a_i"), new MeanMetric("a_f"), new CountMetric() };
        StatsStream statsStream = new StatsStream(zkHost, COLLECTIONORALIAS, sParamsA, metrics);
        statsStream.setStreamContext(streamContext);
        List<Tuple> tuples = getTuples(statsStream);
        assertEquals(1, tuples.size());
        //Test Long and Double Sums
        Tuple tuple = tuples.get(0);
        Double sumi = tuple.getDouble("sum(a_i)");
        Double sumf = tuple.getDouble("sum(a_f)");
        Double mini = tuple.getDouble("min(a_i)");
        Double minf = tuple.getDouble("min(a_f)");
        Double maxi = tuple.getDouble("max(a_i)");
        Double maxf = tuple.getDouble("max(a_f)");
        Double avgi = tuple.getDouble("avg(a_i)");
        Double avgf = tuple.getDouble("avg(a_f)");
        Double count = tuple.getDouble("count(*)");
        assertEquals(70, sumi.longValue());
        assertEquals(55.0, sumf.doubleValue(), 0.01);
        assertEquals(0.0, mini.doubleValue(), 0.01);
        assertEquals(1.0, minf.doubleValue(), 0.01);
        assertEquals(14.0, maxi.doubleValue(), 0.01);
        assertEquals(10.0, maxf.doubleValue(), 0.01);
        assertEquals(7.0, avgi.doubleValue(), .01);
        assertEquals(5.5, avgf.doubleValue(), .001);
        assertEquals(10, count.doubleValue(), .01);
    } finally {
        solrClientCache.close();
    }
}
Also used : UpdateRequest(org.apache.solr.client.solrj.request.UpdateRequest) CountMetric(org.apache.solr.client.solrj.io.stream.metrics.CountMetric) MaxMetric(org.apache.solr.client.solrj.io.stream.metrics.MaxMetric) MinMetric(org.apache.solr.client.solrj.io.stream.metrics.MinMetric) SumMetric(org.apache.solr.client.solrj.io.stream.metrics.SumMetric) MeanMetric(org.apache.solr.client.solrj.io.stream.metrics.MeanMetric) SolrClientCache(org.apache.solr.client.solrj.io.SolrClientCache) SolrParams(org.apache.solr.common.params.SolrParams) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) MinMetric(org.apache.solr.client.solrj.io.stream.metrics.MinMetric) SumMetric(org.apache.solr.client.solrj.io.stream.metrics.SumMetric) Metric(org.apache.solr.client.solrj.io.stream.metrics.Metric) MeanMetric(org.apache.solr.client.solrj.io.stream.metrics.MeanMetric) CountMetric(org.apache.solr.client.solrj.io.stream.metrics.CountMetric) MaxMetric(org.apache.solr.client.solrj.io.stream.metrics.MaxMetric) Tuple(org.apache.solr.client.solrj.io.Tuple) Test(org.junit.Test)

Aggregations

CountMetric (org.apache.solr.client.solrj.io.stream.metrics.CountMetric)5 MaxMetric (org.apache.solr.client.solrj.io.stream.metrics.MaxMetric)5 MeanMetric (org.apache.solr.client.solrj.io.stream.metrics.MeanMetric)5 Metric (org.apache.solr.client.solrj.io.stream.metrics.Metric)5 MinMetric (org.apache.solr.client.solrj.io.stream.metrics.MinMetric)5 SumMetric (org.apache.solr.client.solrj.io.stream.metrics.SumMetric)5 Test (org.junit.Test)5 SolrClientCache (org.apache.solr.client.solrj.io.SolrClientCache)4 Tuple (org.apache.solr.client.solrj.io.Tuple)4 UpdateRequest (org.apache.solr.client.solrj.request.UpdateRequest)4 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)4 SolrParams (org.apache.solr.common.params.SolrParams)4 Bucket (org.apache.solr.client.solrj.io.stream.metrics.Bucket)3 FieldComparator (org.apache.solr.client.solrj.io.comp.FieldComparator)2 MultipleFieldComparator (org.apache.solr.client.solrj.io.comp.MultipleFieldComparator)2