Search in sources :

Example 11 with SolrStream

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

the class TestSQLHandler method testTimeSeriesGrouping.

private void testTimeSeriesGrouping() throws Exception {
    try {
        CloudJettyRunner jetty = this.cloudJettys.get(0);
        del("*:*");
        commit();
        indexr("id", "1", "year_i", "2015", "month_i", "11", "day_i", "7", "item_i", "5");
        indexr("id", "2", "year_i", "2015", "month_i", "11", "day_i", "7", "item_i", "10");
        indexr("id", "3", "year_i", "2015", "month_i", "11", "day_i", "8", "item_i", "30");
        indexr("id", "4", "year_i", "2015", "month_i", "11", "day_i", "8", "item_i", "12");
        indexr("id", "5", "year_i", "2015", "month_i", "10", "day_i", "1", "item_i", "4");
        indexr("id", "6", "year_i", "2015", "month_i", "10", "day_i", "3", "item_i", "5");
        indexr("id", "7", "year_i", "2014", "month_i", "4", "day_i", "4", "item_i", "6");
        indexr("id", "8", "year_i", "2014", "month_i", "4", "day_i", "2", "item_i", "1");
        commit();
        SolrParams sParams = mapParams(CommonParams.QT, "/sql", "stmt", "select year_i, sum(item_i) from collection1 group by year_i order by year_i desc");
        SolrStream solrStream = new SolrStream(jetty.url, sParams);
        List<Tuple> tuples = getTuples(solrStream);
        assert (tuples.size() == 2);
        Tuple tuple;
        tuple = tuples.get(0);
        assert (tuple.getLong("year_i") == 2015);
        //sum(item_i)
        assert (tuple.getDouble("EXPR$1") == 66);
        tuple = tuples.get(1);
        assert (tuple.getLong("year_i") == 2014);
        //sum(item_i)
        assert (tuple.getDouble("EXPR$1") == 7);
        sParams = mapParams(CommonParams.QT, "/sql", "stmt", "select year_i, month_i, sum(item_i) from collection1 group by year_i, month_i " + "order by year_i desc, month_i desc");
        solrStream = new SolrStream(jetty.url, sParams);
        tuples = getTuples(solrStream);
        assert (tuples.size() == 3);
        tuple = tuples.get(0);
        assert (tuple.getLong("year_i") == 2015);
        assert (tuple.getLong("month_i") == 11);
        //sum(item_i)
        assert (tuple.getDouble("EXPR$2") == 57);
        tuple = tuples.get(1);
        assert (tuple.getLong("year_i") == 2015);
        assert (tuple.getLong("month_i") == 10);
        //sum(item_i)
        assert (tuple.getDouble("EXPR$2") == 9);
        tuple = tuples.get(2);
        assert (tuple.getLong("year_i") == 2014);
        assert (tuple.getLong("month_i") == 4);
        //sum(item_i)
        assert (tuple.getDouble("EXPR$2") == 7);
        sParams = mapParams(CommonParams.QT, "/sql", "stmt", "select year_i, month_i, day_i, sum(item_i) from collection1 group by year_i, month_i, day_i " + "order by year_i desc, month_i desc, day_i desc");
        solrStream = new SolrStream(jetty.url, sParams);
        tuples = getTuples(solrStream);
        assert (tuples.size() == 6);
        tuple = tuples.get(0);
        assert (tuple.getLong("year_i") == 2015);
        assert (tuple.getLong("month_i") == 11);
        assert (tuple.getLong("day_i") == 8);
        //sum(item_i)
        assert (tuple.getDouble("EXPR$3") == 42);
        tuple = tuples.get(1);
        assert (tuple.getLong("year_i") == 2015);
        assert (tuple.getLong("month_i") == 11);
        assert (tuple.getLong("day_i") == 7);
        //sum(item_i)
        assert (tuple.getDouble("EXPR$3") == 15);
        tuple = tuples.get(2);
        assert (tuple.getLong("year_i") == 2015);
        assert (tuple.getLong("month_i") == 10);
        assert (tuple.getLong("day_i") == 3);
        //sum(item_i)
        assert (tuple.getDouble("EXPR$3") == 5);
        tuple = tuples.get(3);
        assert (tuple.getLong("year_i") == 2015);
        assert (tuple.getLong("month_i") == 10);
        assert (tuple.getLong("day_i") == 1);
        //sum(item_i)
        assert (tuple.getDouble("EXPR$3") == 4);
        tuple = tuples.get(4);
        assert (tuple.getLong("year_i") == 2014);
        assert (tuple.getLong("month_i") == 4);
        assert (tuple.getLong("day_i") == 4);
        //sum(item_i)
        assert (tuple.getDouble("EXPR$3") == 6);
        tuple = tuples.get(5);
        assert (tuple.getLong("year_i") == 2014);
        assert (tuple.getLong("month_i") == 4);
        assert (tuple.getLong("day_i") == 2);
        //sum(item_i)
        assert (tuple.getDouble("EXPR$3") == 1);
    } finally {
        delete();
    }
}
Also used : SolrParams(org.apache.solr.common.params.SolrParams) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) SolrStream(org.apache.solr.client.solrj.io.stream.SolrStream) Tuple(org.apache.solr.client.solrj.io.Tuple)

Example 12 with SolrStream

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

the class TestSQLHandler method testTimeSeriesGroupingFacet.

private void testTimeSeriesGroupingFacet() throws Exception {
    try {
        CloudJettyRunner jetty = this.cloudJettys.get(0);
        del("*:*");
        commit();
        indexr("id", "1", "year_i", "2015", "month_i", "11", "day_i", "7", "item_i", "5");
        indexr("id", "2", "year_i", "2015", "month_i", "11", "day_i", "7", "item_i", "10");
        indexr("id", "3", "year_i", "2015", "month_i", "11", "day_i", "8", "item_i", "30");
        indexr("id", "4", "year_i", "2015", "month_i", "11", "day_i", "8", "item_i", "12");
        indexr("id", "5", "year_i", "2015", "month_i", "10", "day_i", "1", "item_i", "4");
        indexr("id", "6", "year_i", "2015", "month_i", "10", "day_i", "3", "item_i", "5");
        indexr("id", "7", "year_i", "2014", "month_i", "4", "day_i", "4", "item_i", "6");
        indexr("id", "8", "year_i", "2014", "month_i", "4", "day_i", "2", "item_i", "1");
        commit();
        SolrParams sParams = mapParams(CommonParams.QT, "/sql", "aggregationMode", "facet", "stmt", "select year_i, sum(item_i) from collection1 group by year_i order by year_i desc");
        SolrStream solrStream = new SolrStream(jetty.url, sParams);
        List<Tuple> tuples = getTuples(solrStream);
        assert (tuples.size() == 2);
        Tuple tuple;
        tuple = tuples.get(0);
        assert (tuple.getLong("year_i") == 2015);
        //sum(item_i)
        assert (tuple.getDouble("EXPR$1") == 66);
        tuple = tuples.get(1);
        assert (tuple.getLong("year_i") == 2014);
        //sum(item_i)
        assert (tuple.getDouble("EXPR$1") == 7);
        sParams = mapParams(CommonParams.QT, "/sql", "aggregationMode", "facet", "stmt", "select year_i, month_i, sum(item_i) from collection1 group by year_i, month_i " + "order by year_i desc, month_i desc");
        solrStream = new SolrStream(jetty.url, sParams);
        tuples = getTuples(solrStream);
        assert (tuples.size() == 3);
        tuple = tuples.get(0);
        assert (tuple.getLong("year_i") == 2015);
        assert (tuple.getLong("month_i") == 11);
        //sum(item_i)
        assert (tuple.getDouble("EXPR$2") == 57);
        tuple = tuples.get(1);
        assert (tuple.getLong("year_i") == 2015);
        assert (tuple.getLong("month_i") == 10);
        //sum(item_i)
        assert (tuple.getDouble("EXPR$2") == 9);
        tuple = tuples.get(2);
        assert (tuple.getLong("year_i") == 2014);
        assert (tuple.getLong("month_i") == 4);
        //sum(item_i)
        assert (tuple.getDouble("EXPR$2") == 7);
        sParams = mapParams(CommonParams.QT, "/sql", "aggregationMode", "facet", "stmt", "select year_i, month_i, day_i, sum(item_i) from collection1 group by year_i, month_i, day_i " + "order by year_i desc, month_i desc, day_i desc");
        solrStream = new SolrStream(jetty.url, sParams);
        tuples = getTuples(solrStream);
        assert (tuples.size() == 6);
        tuple = tuples.get(0);
        assert (tuple.getLong("year_i") == 2015);
        assert (tuple.getLong("month_i") == 11);
        assert (tuple.getLong("day_i") == 8);
        //sum(item_i)
        assert (tuple.getDouble("EXPR$3") == 42);
        tuple = tuples.get(1);
        assert (tuple.getLong("year_i") == 2015);
        assert (tuple.getLong("month_i") == 11);
        assert (tuple.getLong("day_i") == 7);
        //sum(item_i)
        assert (tuple.getDouble("EXPR$3") == 15);
        tuple = tuples.get(2);
        assert (tuple.getLong("year_i") == 2015);
        assert (tuple.getLong("month_i") == 10);
        assert (tuple.getLong("day_i") == 3);
        //sum(item_i)
        assert (tuple.getDouble("EXPR$3") == 5);
        tuple = tuples.get(3);
        assert (tuple.getLong("year_i") == 2015);
        assert (tuple.getLong("month_i") == 10);
        assert (tuple.getLong("day_i") == 1);
        //sum(item_i)
        assert (tuple.getDouble("EXPR$3") == 4);
        tuple = tuples.get(4);
        assert (tuple.getLong("year_i") == 2014);
        assert (tuple.getLong("month_i") == 4);
        assert (tuple.getLong("day_i") == 4);
        //sum(item_i)
        assert (tuple.getDouble("EXPR$3") == 6);
        tuple = tuples.get(5);
        assert (tuple.getLong("year_i") == 2014);
        assert (tuple.getLong("month_i") == 4);
        assert (tuple.getLong("day_i") == 2);
        //sum(item_i)
        assert (tuple.getDouble("EXPR$3") == 1);
    } finally {
        delete();
    }
}
Also used : SolrParams(org.apache.solr.common.params.SolrParams) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) SolrStream(org.apache.solr.client.solrj.io.stream.SolrStream) Tuple(org.apache.solr.client.solrj.io.Tuple)

Example 13 with SolrStream

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

the class TestSQLHandler method testSelectDistinct.

private void testSelectDistinct() throws Exception {
    try {
        CloudJettyRunner jetty = this.cloudJettys.get(0);
        del("*:*");
        commit();
        indexr("id", "1", "text", "XXXX XXXX", "str_s", "a", "field_i", "1");
        indexr("id", "2", "text", "XXXX XXXX", "str_s", "b", "field_i", "2");
        indexr("id", "3", "text", "XXXX XXXX", "str_s", "a", "field_i", "20");
        indexr("id", "4", "text", "XXXX XXXX", "str_s", "b", "field_i", "2");
        indexr("id", "5", "text", "XXXX XXXX", "str_s", "c", "field_i", "30");
        indexr("id", "6", "text", "XXXX XXXX", "str_s", "c", "field_i", "30");
        indexr("id", "7", "text", "XXXX XXXX", "str_s", "c", "field_i", "50");
        indexr("id", "8", "text", "XXXX XXXX", "str_s", "c", "field_i", "60");
        commit();
        SolrParams sParams = mapParams(CommonParams.QT, "/sql", "aggregationMode", "map_reduce", "stmt", "select distinct str_s, field_i from collection1 order by str_s asc, field_i asc");
        System.out.println("##################### testSelectDistinct()");
        TupleStream solrStream = new SolrStream(jetty.url, sParams);
        List<Tuple> tuples = getTuples(solrStream);
        assert (tuples.size() == 6);
        Tuple tuple = tuples.get(0);
        assert (tuple.get("str_s").equals("a"));
        assert (tuple.getLong("field_i") == 1);
        tuple = tuples.get(1);
        assert (tuple.get("str_s").equals("a"));
        assert (tuple.getLong("field_i") == 20);
        tuple = tuples.get(2);
        assert (tuple.get("str_s").equals("b"));
        assert (tuple.getLong("field_i") == 2);
        tuple = tuples.get(3);
        assert (tuple.get("str_s").equals("c"));
        assert (tuple.getLong("field_i") == 30);
        tuple = tuples.get(4);
        assert (tuple.get("str_s").equals("c"));
        assert (tuple.getLong("field_i") == 50);
        tuple = tuples.get(5);
        assert (tuple.get("str_s").equals("c"));
        assert (tuple.getLong("field_i") == 60);
        //reverse the sort
        sParams = mapParams(CommonParams.QT, "/sql", "aggregationMode", "map_reduce", "stmt", "select distinct str_s, field_i from collection1 order by str_s desc, field_i desc");
        solrStream = new SolrStream(jetty.url, sParams);
        tuples = getTuples(solrStream);
        assert (tuples.size() == 6);
        tuple = tuples.get(0);
        assert (tuple.get("str_s").equals("c"));
        assert (tuple.getLong("field_i") == 60);
        tuple = tuples.get(1);
        assert (tuple.get("str_s").equals("c"));
        assert (tuple.getLong("field_i") == 50);
        tuple = tuples.get(2);
        assert (tuple.get("str_s").equals("c"));
        assert (tuple.getLong("field_i") == 30);
        tuple = tuples.get(3);
        assert (tuple.get("str_s").equals("b"));
        assert (tuple.getLong("field_i") == 2);
        tuple = tuples.get(4);
        assert (tuple.get("str_s").equals("a"));
        assert (tuple.getLong("field_i") == 20);
        tuple = tuples.get(5);
        assert (tuple.get("str_s").equals("a"));
        assert (tuple.getLong("field_i") == 1);
        sParams = mapParams(CommonParams.QT, "/sql", "aggregationMode", "map_reduce", "stmt", "select distinct str_s as myString, field_i from collection1 order by myString desc, field_i desc");
        solrStream = new SolrStream(jetty.url, sParams);
        tuples = getTuples(solrStream);
        assert (tuples.size() == 6);
        tuple = tuples.get(0);
        assert (tuple.get("myString").equals("c"));
        assert (tuple.getLong("field_i") == 60);
        tuple = tuples.get(1);
        assert (tuple.get("myString").equals("c"));
        assert (tuple.getLong("field_i") == 50);
        tuple = tuples.get(2);
        assert (tuple.get("myString").equals("c"));
        assert (tuple.getLong("field_i") == 30);
        tuple = tuples.get(3);
        assert (tuple.get("myString").equals("b"));
        assert (tuple.getLong("field_i") == 2);
        tuple = tuples.get(4);
        assert (tuple.get("myString").equals("a"));
        assert (tuple.getLong("field_i") == 20);
        tuple = tuples.get(5);
        assert (tuple.get("myString").equals("a"));
        assert (tuple.getLong("field_i") == 1);
        //test with limit
        sParams = mapParams(CommonParams.QT, "/sql", "aggregationMode", "map_reduce", "stmt", "select distinct str_s, field_i from collection1 order by str_s desc, field_i desc limit 2");
        solrStream = new SolrStream(jetty.url, sParams);
        tuples = getTuples(solrStream);
        assert (tuples.size() == 2);
        tuple = tuples.get(0);
        assert (tuple.get("str_s").equals("c"));
        assert (tuple.getLong("field_i") == 60);
        tuple = tuples.get(1);
        assert (tuple.get("str_s").equals("c"));
        assert (tuple.getLong("field_i") == 50);
        // Test without a sort. Sort should be asc by default.
        sParams = mapParams(CommonParams.QT, "/sql", "aggregationMode", "map_reduce", "stmt", "select distinct str_s, field_i from collection1");
        solrStream = new SolrStream(jetty.url, sParams);
        tuples = getTuples(solrStream);
        assert (tuples.size() == 6);
        tuple = tuples.get(0);
        assert (tuple.get("str_s").equals("a"));
        assert (tuple.getLong("field_i") == 1);
        tuple = tuples.get(1);
        assert (tuple.get("str_s").equals("a"));
        assert (tuple.getLong("field_i") == 20);
        tuple = tuples.get(2);
        assert (tuple.get("str_s").equals("b"));
        assert (tuple.getLong("field_i") == 2);
        tuple = tuples.get(3);
        assert (tuple.get("str_s").equals("c"));
        assert (tuple.getLong("field_i") == 30);
        tuple = tuples.get(4);
        assert (tuple.get("str_s").equals("c"));
        assert (tuple.getLong("field_i") == 50);
        tuple = tuples.get(5);
        assert (tuple.get("str_s").equals("c"));
        assert (tuple.getLong("field_i") == 60);
        // Test with a predicate.
        sParams = mapParams(CommonParams.QT, "/sql", "aggregationMode", "map_reduce", "stmt", "select distinct str_s, field_i from collection1 where str_s = 'a'");
        solrStream = new SolrStream(jetty.url, sParams);
        tuples = getTuples(solrStream);
        assert (tuples.size() == 2);
        tuple = tuples.get(0);
        assert (tuple.get("str_s").equals("a"));
        assert (tuple.getLong("field_i") == 1);
        tuple = tuples.get(1);
        assert (tuple.get("str_s").equals("a"));
        assert (tuple.getLong("field_i") == 20);
    } finally {
        delete();
    }
}
Also used : TupleStream(org.apache.solr.client.solrj.io.stream.TupleStream) SolrParams(org.apache.solr.common.params.SolrParams) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) SolrStream(org.apache.solr.client.solrj.io.stream.SolrStream) Tuple(org.apache.solr.client.solrj.io.Tuple)

Example 14 with SolrStream

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

the class TestSQLHandler method testWhere.

private void testWhere() throws Exception {
    try {
        CloudJettyRunner jetty = this.cloudJettys.get(0);
        del("*:*");
        commit();
        indexDoc(sdoc("id", "1", "text", "XXXX XXXX", "str_s", "a", "field_i", "7"));
        indexDoc(sdoc("id", "2", "text", "XXXX XXXX", "str_s", "b", "field_i", "8"));
        indexDoc(sdoc("id", "3", "text", "XXXX XXXX", "str_s", "a", "field_i", "20"));
        indexDoc(sdoc("id", "4", "text", "XXXX XXXX", "str_s", "b", "field_i", "11"));
        indexDoc(sdoc("id", "5", "text", "XXXX XXXX", "str_s", "c", "field_i", "30"));
        indexDoc(sdoc("id", "6", "text", "XXXX XXXX", "str_s", "c", "field_i", "40"));
        indexDoc(sdoc("id", "7", "text", "XXXX XXXX", "str_s", "c", "field_i", "50"));
        indexDoc(sdoc("id", "8", "text", "XXXX XXXX", "str_s", "c", "field_i", "60"));
        commit();
        // Equals
        SolrParams sParams = mapParams(CommonParams.QT, "/sql", "stmt", "select id from collection1 where id = 1 order by id asc");
        SolrStream solrStream = new SolrStream(jetty.url, sParams);
        List<Tuple> tuples = getTuples(solrStream);
        assertEquals(1, tuples.size());
        Tuple tuple = tuples.get(0);
        assertEquals(1L, tuple.get("id"));
        // Not Equals <>
        sParams = mapParams(CommonParams.QT, "/sql", "stmt", "select id from collection1 where id <> 1 order by id asc limit 10");
        solrStream = new SolrStream(jetty.url, sParams);
        tuples = getTuples(solrStream);
        assertEquals(7, tuples.size());
        tuple = tuples.get(0);
        assertEquals(2L, tuple.get("id"));
        tuple = tuples.get(1);
        assertEquals(3L, tuple.get("id"));
        tuple = tuples.get(2);
        assertEquals(4L, tuple.get("id"));
        tuple = tuples.get(3);
        assertEquals(5L, tuple.get("id"));
        tuple = tuples.get(4);
        assertEquals(6L, tuple.get("id"));
        tuple = tuples.get(5);
        assertEquals(7L, tuple.get("id"));
        tuple = tuples.get(6);
        assertEquals(8L, tuple.get("id"));
        // TODO requires different Calcite SQL conformance level
        // Not Equals !=
        //      sParams = mapParams(CommonParams.QT, "/sql",
        //          "stmt", "select id from collection1 where id != 1 order by id asc limit 10");
        //
        //      solrStream = new SolrStream(jetty.url, sParams);
        //      tuples = getTuples(solrStream);
        //
        //      assertEquals(7, tuples.size());
        //
        //      tuple = tuples.get(0);
        //      assertEquals(2L, tuple.get("id"));
        //      tuple = tuples.get(1);
        //      assertEquals(3L, tuple.get("id"));
        //      tuple = tuples.get(2);
        //      assertEquals(4L, tuple.get("id"));
        //      tuple = tuples.get(3);
        //      assertEquals(5L, tuple.get("id"));
        //      tuple = tuples.get(4);
        //      assertEquals(6L, tuple.get("id"));
        //      tuple = tuples.get(5);
        //      assertEquals(7L, tuple.get("id"));
        //      tuple = tuples.get(6);
        //      assertEquals(8L, tuple.get("id"));
        // Less than
        sParams = mapParams(CommonParams.QT, "/sql", "stmt", "select id from collection1 where id < 2 order by id asc");
        solrStream = new SolrStream(jetty.url, sParams);
        tuples = getTuples(solrStream);
        assertEquals(1, tuples.size());
        tuple = tuples.get(0);
        assertEquals(1L, tuple.get("id"));
        // Less than equal
        sParams = mapParams(CommonParams.QT, "/sql", "stmt", "select id from collection1 where id <= 2 order by id asc");
        solrStream = new SolrStream(jetty.url, sParams);
        tuples = getTuples(solrStream);
        assertEquals(2, tuples.size());
        tuple = tuples.get(0);
        assertEquals(1L, tuple.get("id"));
        tuple = tuples.get(1);
        assertEquals(2L, tuple.get("id"));
        // Greater than
        sParams = mapParams(CommonParams.QT, "/sql", "stmt", "select id from collection1 where id > 7 order by id asc");
        solrStream = new SolrStream(jetty.url, sParams);
        tuples = getTuples(solrStream);
        assertEquals(1, tuples.size());
        tuple = tuples.get(0);
        assertEquals(8L, tuple.get("id"));
        // Greater than equal
        sParams = mapParams(CommonParams.QT, "/sql", "stmt", "select id from collection1 where id >= 7 order by id asc");
        solrStream = new SolrStream(jetty.url, sParams);
        tuples = getTuples(solrStream);
        assertEquals(2, tuples.size());
        tuple = tuples.get(0);
        assertEquals(7L, tuple.get("id"));
        tuple = tuples.get(1);
        assertEquals(8L, tuple.get("id"));
    } finally {
        delete();
    }
}
Also used : SolrParams(org.apache.solr.common.params.SolrParams) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) SolrStream(org.apache.solr.client.solrj.io.stream.SolrStream) Tuple(org.apache.solr.client.solrj.io.Tuple)

Example 15 with SolrStream

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

the class TestSQLHandler method testBasicGroupingTint.

private void testBasicGroupingTint() throws Exception {
    try {
        CloudJettyRunner jetty = this.cloudJettys.get(0);
        del("*:*");
        commit();
        indexr("id", "1", "text", "XXXX XXXX", "str_s", "a", "field_ti", "7");
        indexr("id", "2", "text", "XXXX XXXX", "str_s", "b", "field_ti", "8");
        indexr("id", "3", "text", "XXXX XXXX", "str_s", "a", "field_ti", "20");
        indexr("id", "4", "text", "XXXX XXXX", "str_s", "b", "field_ti", "11");
        indexr("id", "5", "text", "XXXX XXXX", "str_s", "c", "field_ti", "30");
        indexr("id", "6", "text", "XXXX XXXX", "str_s", "c", "field_ti", "40");
        indexr("id", "7", "text", "XXXX XXXX", "str_s", "c", "field_ti", "50");
        indexr("id", "8", "text", "XXXX XXXX", "str_s", "c", "field_ti", "60");
        indexr("id", "9", "text", "XXXX XXXY", "str_s", "d", "field_ti", "70");
        commit();
        SolrParams sParams = mapParams(CommonParams.QT, "/sql", "stmt", "select str_s, count(*), sum(field_ti), min(field_ti), max(field_ti), avg(field_ti) from collection1 where text='XXXX' group by str_s order by sum(field_ti) asc limit 2");
        SolrStream solrStream = new SolrStream(jetty.url, sParams);
        List<Tuple> tuples = getTuples(solrStream);
        //Only two results because of the limit.
        assert (tuples.size() == 2);
        Tuple tuple;
        tuple = tuples.get(0);
        assert (tuple.get("str_s").equals("b"));
        //count(*)
        assert (tuple.getDouble("EXPR$1") == 2);
        //sum(field_i)
        assert (tuple.getDouble("EXPR$2") == 19);
        //min(field_i)
        assert (tuple.getDouble("EXPR$3") == 8);
        //max(field_i)
        assert (tuple.getDouble("EXPR$4") == 11);
        //avg(field_i)
        assert (tuple.getDouble("EXPR$5") == 10);
        tuple = tuples.get(1);
        assert (tuple.get("str_s").equals("a"));
        //count(*)
        assert (tuple.getDouble("EXPR$1") == 2);
        //sum(field_i)
        assert (tuple.getDouble("EXPR$2") == 27);
        //min(field_i)
        assert (tuple.getDouble("EXPR$3") == 7);
        //max(field_i)
        assert (tuple.getDouble("EXPR$4") == 20);
        //avg(field_i)
        assert (tuple.getDouble("EXPR$5") == 14);
    } finally {
        delete();
    }
}
Also used : SolrParams(org.apache.solr.common.params.SolrParams) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) SolrStream(org.apache.solr.client.solrj.io.stream.SolrStream) Tuple(org.apache.solr.client.solrj.io.Tuple)

Aggregations

SolrStream (org.apache.solr.client.solrj.io.stream.SolrStream)17 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)17 SolrParams (org.apache.solr.common.params.SolrParams)16 Tuple (org.apache.solr.client.solrj.io.Tuple)15 IOException (java.io.IOException)2 Replica (org.apache.solr.common.cloud.Replica)2 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 Random (java.util.Random)1 CloudSolrStream (org.apache.solr.client.solrj.io.stream.CloudSolrStream)1 ExceptionStream (org.apache.solr.client.solrj.io.stream.ExceptionStream)1 TupleStream (org.apache.solr.client.solrj.io.stream.TupleStream)1 Slice (org.apache.solr.common.cloud.Slice)1 ZkCoreNodeProps (org.apache.solr.common.cloud.ZkCoreNodeProps)1 ZkStateReader (org.apache.solr.common.cloud.ZkStateReader)1 Test (org.junit.Test)1