Search in sources :

Example 1 with SolrStream

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

the class TestSQLHandler method testMixedCaseFields.

private void testMixedCaseFields() throws Exception {
    try {
        CloudJettyRunner jetty = this.cloudJettys.get(0);
        del("*:*");
        commit();
        indexDoc(sdoc("id", "1", "Text_t", "XXXX XXXX", "Str_s", "a", "Field_i", "7"));
        indexDoc(sdoc("id", "2", "Text_t", "XXXX XXXX", "Str_s", "b", "Field_i", "8"));
        indexDoc(sdoc("id", "3", "Text_t", "XXXX XXXX", "Str_s", "a", "Field_i", "20"));
        indexDoc(sdoc("id", "4", "Text_t", "XXXX XXXX", "Str_s", "b", "Field_i", "11"));
        indexDoc(sdoc("id", "5", "Text_t", "XXXX XXXX", "Str_s", "c", "Field_i", "30"));
        indexDoc(sdoc("id", "6", "Text_t", "XXXX XXXX", "Str_s", "c", "Field_i", "40"));
        indexDoc(sdoc("id", "7", "Text_t", "XXXX XXXX", "Str_s", "c", "Field_i", "50"));
        indexDoc(sdoc("id", "8", "Text_t", "XXXX XXXX", "Str_s", "c", "Field_i", "60"));
        commit();
        SolrParams sParams = mapParams(CommonParams.QT, "/sql", "aggregationMode", "map_reduce", "stmt", "select id, Field_i, Str_s from collection1 where Text_t='XXXX' order by Field_i desc");
        SolrStream solrStream = new SolrStream(jetty.url, sParams);
        List<Tuple> tuples = getTuples(solrStream);
        assert (tuples.size() == 8);
        Tuple tuple;
        tuple = tuples.get(0);
        assert (tuple.getLong("id") == 8);
        assert (tuple.getLong("Field_i") == 60);
        assert (tuple.get("Str_s").equals("c"));
        tuple = tuples.get(1);
        assert (tuple.getLong("id") == 7);
        assert (tuple.getLong("Field_i") == 50);
        assert (tuple.get("Str_s").equals("c"));
        tuple = tuples.get(2);
        assert (tuple.getLong("id") == 6);
        assert (tuple.getLong("Field_i") == 40);
        assert (tuple.get("Str_s").equals("c"));
        tuple = tuples.get(3);
        assert (tuple.getLong("id") == 5);
        assert (tuple.getLong("Field_i") == 30);
        assert (tuple.get("Str_s").equals("c"));
        tuple = tuples.get(4);
        assert (tuple.getLong("id") == 3);
        assert (tuple.getLong("Field_i") == 20);
        assert (tuple.get("Str_s").equals("a"));
        tuple = tuples.get(5);
        assert (tuple.getLong("id") == 4);
        assert (tuple.getLong("Field_i") == 11);
        assert (tuple.get("Str_s").equals("b"));
        tuple = tuples.get(6);
        assert (tuple.getLong("id") == 2);
        assert (tuple.getLong("Field_i") == 8);
        assert (tuple.get("Str_s").equals("b"));
        tuple = tuples.get(7);
        assert (tuple.getLong("id") == 1);
        assert (tuple.getLong("Field_i") == 7);
        assert (tuple.get("Str_s").equals("a"));
        // TODO get sum(Field_i) as named one
        sParams = mapParams(CommonParams.QT, "/sql", "stmt", "select Str_s, sum(Field_i) from collection1 where id='(1 8)' group by Str_s having (sum(Field_i) = 7 OR sum(Field_i) = 60) order by sum(Field_i) desc");
        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.getDouble("EXPR$1") == 60);
        tuple = tuples.get(1);
        assert (tuple.get("Str_s").equals("a"));
        assert (tuple.getDouble("EXPR$1") == 7);
        sParams = mapParams(CommonParams.QT, "/sql", "aggregationMode", "map_reduce", "stmt", "select Str_s, sum(Field_i) from collection1 where id='(1 8)' group by Str_s having (sum(Field_i) = 7 OR sum(Field_i) = 60) order by sum(Field_i) desc");
        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.getDouble("EXPR$1") == 60);
        tuple = tuples.get(1);
        assert (tuple.get("Str_s").equals("a"));
        assert (tuple.getDouble("EXPR$1") == 7);
    } 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 2 with SolrStream

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

the class TestSQLHandler method testParallelSelectDistinct.

private void testParallelSelectDistinct() 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", "numWorkers", "2", "aggregationMode", "map_reduce", "stmt", "select distinct str_s, field_i from collection1 order by str_s asc, field_i asc");
        SolrStream solrStream = new SolrStream(jetty.url, sParams);
        List<Tuple> tuples = getTuples(solrStream);
        assert (tuples.size() == 6);
        Tuple 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", "numWorkers", "2", "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);
        //reverse the sort
        sParams = mapParams(CommonParams.QT, "/sql", "numWorkers", "2", "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", "numWorkers", "2", "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", "numWorkers", "2", "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", "numWorkers", "2", "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 : 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 3 with SolrStream

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

the class TestSQLHandler method testSelectDistinctFacets.

private void testSelectDistinctFacets() 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", "facet", "stmt", "select distinct str_s, field_i from collection1 order by str_s asc, field_i asc");
        System.out.println("######## selectDistinctFacets #######");
        SolrStream solrStream = new SolrStream(jetty.url, sParams);
        List<Tuple> tuples = getTuples(solrStream);
        //assert(false);
        assert (tuples.size() == 6);
        Tuple 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", "facet", "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);
        //reverse the sort
        sParams = mapParams(CommonParams.QT, "/sql", "aggregationMode", "facet", "stmt", "select distinct str_s as myString, field_i as myInt from collection1 order by str_s desc, myInt 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("myInt") == 60);
        tuple = tuples.get(1);
        assert (tuple.get("myString").equals("c"));
        assert (tuple.getLong("myInt") == 50);
        tuple = tuples.get(2);
        assert (tuple.get("myString").equals("c"));
        assert (tuple.getLong("myInt") == 30);
        tuple = tuples.get(3);
        assert (tuple.get("myString").equals("b"));
        assert (tuple.getLong("myInt") == 2);
        tuple = tuples.get(4);
        assert (tuple.get("myString").equals("a"));
        assert (tuple.getLong("myInt") == 20);
        tuple = tuples.get(5);
        assert (tuple.get("myString").equals("a"));
        assert (tuple.getLong("myInt") == 1);
        //test with limit
        sParams = mapParams(CommonParams.QT, "/sql", "aggregationMode", "facet", "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", "facet", "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", "facet", "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 : 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 4 with SolrStream

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

the class TestSQLHandler method testParallelBasicGrouping.

private void testParallelBasicGrouping() throws Exception {
    try {
        CloudJettyRunner jetty = this.cloudJettys.get(0);
        del("*:*");
        commit();
        indexr("id", "1", "text", "XXXX XXXX", "str_s", "a", "field_i", "7");
        indexr("id", "2", "text", "XXXX XXXX", "str_s", "b", "field_i", "8");
        indexr("id", "3", "text", "XXXX XXXX", "str_s", "a", "field_i", "20");
        indexr("id", "4", "text", "XXXX XXXX", "str_s", "b", "field_i", "11");
        indexr("id", "5", "text", "XXXX XXXX", "str_s", "c", "field_i", "30");
        indexr("id", "6", "text", "XXXX XXXX", "str_s", "c", "field_i", "40");
        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", "numWorkers", "2", "aggregationMode", "map_reduce", "stmt", "select str_s, count(*), sum(field_i), min(field_i), max(field_i), " + "avg(field_i) from collection1 where text='XXXX' group by str_s " + "order by sum(field_i) 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);
        sParams = mapParams(CommonParams.QT, "/sql", "numWorkers", "2", "aggregationMode", "map_reduce", "stmt", "select str_s, count(*), sum(field_i), min(field_i), max(field_i), " + "cast(avg(1.0 * field_i) as float) from collection1 where text='XXXX' group by str_s " + "order by sum(field_i) asc limit 2");
        solrStream = new SolrStream(jetty.url, sParams);
        tuples = getTuples(solrStream);
        //Only two results because of the limit.
        assert (tuples.size() == 2);
        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") == 9.5);
        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") == 13.5);
        sParams = mapParams(CommonParams.QT, "/sql", "numWorkers", "2", "aggregationMode", "map_reduce", "stmt", "select str_s, count(*), sum(field_i) as mySum, min(field_i), max(field_i), " + "avg(field_i) from collection1 where text='XXXX' group by str_s order by mySum asc limit 2");
        solrStream = new SolrStream(jetty.url, sParams);
        tuples = getTuples(solrStream);
        //Only two results because of the limit.
        assert (tuples.size() == 2);
        tuple = tuples.get(0);
        assert (tuple.get("str_s").equals("b"));
        //count(*)
        assert (tuple.getDouble("EXPR$1") == 2);
        assert (tuple.getDouble("mySum") == 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);
        assert (tuple.getDouble("mySum") == 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);
        sParams = mapParams(CommonParams.QT, "/sql", "numWorkers", "2", "aggregationMode", "map_reduce", "stmt", "select str_s, count(*), sum(field_i), min(field_i), max(field_i), " + "avg(field_i) from collection1 where text='XXXX' group by str_s order by str_s desc");
        solrStream = new SolrStream(jetty.url, sParams);
        tuples = getTuples(solrStream);
        assert (tuples.size() == 3);
        tuple = tuples.get(0);
        assert (tuple.get("str_s").equals("c"));
        //count(*)
        assert (tuple.getDouble("EXPR$1") == 4);
        //sum(field_i)
        assert (tuple.getDouble("EXPR$2") == 180);
        //min(field_i)
        assert (tuple.getDouble("EXPR$3") == 30);
        //max(field_i)
        assert (tuple.getDouble("EXPR$4") == 60);
        //avg(field_i)
        assert (tuple.getDouble("EXPR$5") == 45);
        tuple = tuples.get(1);
        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(2);
        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);
        sParams = mapParams(CommonParams.QT, "/sql", "numWorkers", "2", "aggregationMode", "map_reduce", "stmt", "select str_s as myString, count(*), sum(field_i), min(field_i), max(field_i), " + "avg(field_i) from collection1 where text='XXXX' group by str_s order by myString desc");
        solrStream = new SolrStream(jetty.url, sParams);
        tuples = getTuples(solrStream);
        assert (tuples.size() == 3);
        tuple = tuples.get(0);
        assert (tuple.get("myString").equals("c"));
        //count(*)
        assert (tuple.getDouble("EXPR$1") == 4);
        //sum(field_i)
        assert (tuple.getDouble("EXPR$2") == 180);
        //min(field_i)
        assert (tuple.getDouble("EXPR$3") == 30);
        //max(field_i)
        assert (tuple.getDouble("EXPR$4") == 60);
        //avg(field_i)
        assert (tuple.getDouble("EXPR$5") == 45);
        tuple = tuples.get(1);
        assert (tuple.get("myString").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(2);
        assert (tuple.get("myString").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);
        sParams = mapParams(CommonParams.QT, "/sql", "numWorkers", "2", "aggregationMode", "map_reduce", "stmt", "select str_s, count(*), sum(field_i), min(field_i), max(field_i), " + "avg(field_i) from collection1 where text='XXXX' group by str_s having sum(field_i) = 19");
        solrStream = new SolrStream(jetty.url, sParams);
        tuples = getTuples(solrStream);
        assert (tuples.size() == 1);
        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);
        sParams = mapParams(CommonParams.QT, "/sql", "numWorkers", "2", "aggregationMode", "map_reduce", "stmt", "select str_s, count(*), sum(field_i), min(field_i), max(field_i), " + "avg(field_i) from collection1 where text='XXXX' group by str_s " + "having ((sum(field_i) = 19) AND (min(field_i) = 8))");
        solrStream = new SolrStream(jetty.url, sParams);
        tuples = getTuples(solrStream);
        assert (tuples.size() == 1);
        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);
        sParams = mapParams(CommonParams.QT, "/sql", "numWorkers", "2", "aggregationMode", "map_reduce", "stmt", "select str_s, count(*), sum(field_i), min(field_i), max(field_i), " + "avg(field_i) from collection1 where text='XXXX' group by str_s " + "having ((sum(field_i) = 19) AND (min(field_i) = 100))");
        solrStream = new SolrStream(jetty.url, sParams);
        tuples = getTuples(solrStream);
        assert (tuples.size() == 0);
    } 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 5 with SolrStream

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

the class TestSQLHandler method testBasicGroupingFacets.

private void testBasicGroupingFacets() throws Exception {
    try {
        CloudJettyRunner jetty = this.cloudJettys.get(0);
        del("*:*");
        commit();
        indexr("id", "1", "text", "XXXX XXXX", "str_s", "a", "field_i", "7");
        indexr("id", "2", "text", "XXXX XXXX", "str_s", "b", "field_i", "8");
        indexr("id", "3", "text", "XXXX XXXX", "str_s", "a", "field_i", "20");
        indexr("id", "4", "text", "XXXX XXXX", "str_s", "b", "field_i", "11");
        indexr("id", "5", "text", "XXXX XXXX", "str_s", "c", "field_i", "30");
        indexr("id", "6", "text", "XXXX XXXX", "str_s", "c", "field_i", "40");
        indexr("id", "7", "text", "XXXX XXXX", "str_s", "c", "field_i", "50");
        indexr("id", "8", "text", "XXXX XXXX", "str_s", "c", "field_i", "60");
        indexr("id", "9", "text", "XXXX XXXY", "str_s", "d", "field_i", "70");
        commit();
        SolrParams sParams = mapParams(CommonParams.QT, "/sql", "aggregationMode", "facet", "stmt", "select str_s, count(*), sum(field_i), min(field_i), max(field_i), " + "cast(avg(1.0 * field_i) as float) from collection1 where text='XXXX' group by str_s " + "order by sum(field_i) 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") == 9.5D);
        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") == 13.5D);
        sParams = mapParams(CommonParams.QT, "/sql", "aggregationMode", "facet", "stmt", "select str_s, count(*), sum(field_i), min(field_i), max(field_i), " + "avg(field_i) from collection1 where text='XXXX' group by str_s " + "order by sum(field_i) asc limit 2");
        solrStream = new SolrStream(jetty.url, sParams);
        tuples = getTuples(solrStream);
        //Only two results because of the limit.
        assert (tuples.size() == 2);
        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);
        sParams = mapParams(CommonParams.QT, "/sql", "aggregationMode", "facet", "stmt", "select str_s, count(*), sum(field_i), min(field_i), max(field_i), " + "cast(avg(1.0 * field_i) as float) from collection1 where (text='XXXX' AND NOT (text='XXXY')) " + "group by str_s order by str_s desc");
        solrStream = new SolrStream(jetty.url, sParams);
        tuples = getTuples(solrStream);
        assert (tuples.size() == 3);
        tuple = tuples.get(0);
        assert (tuple.get("str_s").equals("c"));
        //count(*)
        assert (tuple.getDouble("EXPR$1") == 4);
        //sum(field_i)
        assert (tuple.getDouble("EXPR$2") == 180);
        //min(field_i)
        assert (tuple.getDouble("EXPR$3") == 30);
        //max(field_i)
        assert (tuple.getDouble("EXPR$4") == 60);
        //avg(field_i)
        assert (tuple.getDouble("EXPR$5") == 45);
        tuple = tuples.get(1);
        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") == 9.5D);
        tuple = tuples.get(2);
        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") == 13.5D);
        sParams = mapParams(CommonParams.QT, "/sql", "aggregationMode", "facet", "stmt", "select str_s as myString, count(*), sum(field_i) as mySum, min(field_i), max(field_i), " + "cast(avg(1.0 * field_i) as float) from collection1 where (text='XXXX' AND NOT (text='XXXY')) " + "group by str_s order by myString desc");
        solrStream = new SolrStream(jetty.url, sParams);
        tuples = getTuples(solrStream);
        assert (tuples.size() == 3);
        tuple = tuples.get(0);
        assert (tuple.get("myString").equals("c"));
        //count(*)
        assert (tuple.getDouble("EXPR$1") == 4);
        assert (tuple.getDouble("mySum") == 180);
        //min(field_i)
        assert (tuple.getDouble("EXPR$3") == 30);
        //max(field_i)
        assert (tuple.getDouble("EXPR$4") == 60);
        //avg(field_i)
        assert (tuple.getDouble("EXPR$5") == 45);
        tuple = tuples.get(1);
        assert (tuple.get("myString").equals("b"));
        //count(*)
        assert (tuple.getDouble("EXPR$1") == 2);
        assert (tuple.getDouble("mySum") == 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") == 9.5D);
        tuple = tuples.get(2);
        assert (tuple.get("myString").equals("a"));
        //count(*)
        assert (tuple.getDouble("EXPR$1") == 2);
        assert (tuple.getDouble("mySum") == 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") == 13.5D);
        sParams = mapParams(CommonParams.QT, "/sql", "aggregationMode", "facet", "stmt", "select str_s, count(*), sum(field_i), min(field_i), max(field_i), " + "cast(avg(1.0 * field_i) as float) from collection1 where text='XXXX' group by str_s having sum(field_i) = 19");
        solrStream = new SolrStream(jetty.url, sParams);
        tuples = getTuples(solrStream);
        assert (tuples.size() == 1);
        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") == 9.5D);
        sParams = mapParams(CommonParams.QT, "/sql", "aggregationMode", "facet", "stmt", "select str_s, count(*), sum(field_i), min(field_i), max(field_i), " + "cast(avg(1.0 * field_i) as float) from collection1 where text='XXXX' group by str_s " + "having ((sum(field_i) = 19) AND (min(field_i) = 8))");
        solrStream = new SolrStream(jetty.url, sParams);
        tuples = getTuples(solrStream);
        assert (tuples.size() == 1);
        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") == 9.5D);
        sParams = mapParams(CommonParams.QT, "/sql", "aggregationMode", "facet", "stmt", "select str_s, count(*), sum(field_i) as mySum, min(field_i), max(field_i), " + "cast(avg(1.0 * field_i) as float) from collection1 where text='XXXX' group by str_s " + "having ((sum(field_i) = 19) AND (min(field_i) = 8))");
        solrStream = new SolrStream(jetty.url, sParams);
        tuples = getTuples(solrStream);
        assert (tuples.size() == 1);
        tuple = tuples.get(0);
        assert (tuple.get("str_s").equals("b"));
        //count(*)
        assert (tuple.getDouble("EXPR$1") == 2);
        assert (tuple.getDouble("mySum") == 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") == 9.5D);
        sParams = mapParams(CommonParams.QT, "/sql", "aggregationMode", "facet", "stmt", "select str_s, count(*), sum(field_i), min(field_i), max(field_i), " + "cast(avg(1.0 * field_i) as float) from collection1 where text='XXXX' group by str_s " + "having ((sum(field_i) = 19) AND (min(field_i) = 100))");
        solrStream = new SolrStream(jetty.url, sParams);
        tuples = getTuples(solrStream);
        assert (tuples.size() == 0);
    } 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