Search in sources :

Example 16 with SolrStream

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

the class TestSQLHandler method testParallelTimeSeriesGrouping.

private void testParallelTimeSeriesGrouping() 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", "numWorkers", "2", "aggregationMode", "map_reduce", "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);
        // SOLR-8601, This tests that the bucket is actually a Long and not parsed from a String.
        assert (tuple.get("year_i") instanceof Long);
        //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", "numWorkers", "2", "aggregationMode", "map_reduce", "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);
        assert (tuple.get("year_i") instanceof Long);
        assert (tuple.get("month_i") instanceof Long);
        //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", "numWorkers", "2", "aggregationMode", "map_reduce", "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 17 with SolrStream

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

the class TestSQLHandler method testSQLException.

private void testSQLException() 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();
        SolrParams sParams = mapParams(CommonParams.QT, "/sql", "aggregationMode", "map_reduce", "stmt", "select id, str_s from collection1 where text='XXXX' order by field_iff desc");
        SolrStream solrStream = new SolrStream(jetty.url, sParams);
        Tuple tuple = getTuple(new ExceptionStream(solrStream));
        assert (tuple.EOF);
        assert (tuple.EXCEPTION);
        assert (tuple.getException().contains("Column 'field_iff' not found in any table"));
        sParams = mapParams(CommonParams.QT, "/sql", "stmt", "select id, field_iff, str_s from collection1 where text='XXXX' order by field_iff desc");
        solrStream = new SolrStream(jetty.url, sParams);
        tuple = getTuple(new ExceptionStream(solrStream));
        assert (tuple.EOF);
        assert (tuple.EXCEPTION);
        assert (tuple.getException().contains("Column 'field_iff' not found in any table"));
        sParams = mapParams(CommonParams.QT, "/sql", "aggregationMode", "map_reduce", "stmt", "select str_s, count(*), sum(field_iff), 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_iff) = 19) AND (min(field_i) = 8))");
        solrStream = new SolrStream(jetty.url, sParams);
        tuple = getTuple(new ExceptionStream(solrStream));
        assert (tuple.EOF);
        assert (tuple.EXCEPTION);
        assert (tuple.getException().contains("Column 'field_iff' not found in any table"));
        sParams = mapParams(CommonParams.QT, "/sql", "aggregationMode", "map_reduce", "stmt", "select str_s, count(*), blah(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);
        tuple = getTuple(new ExceptionStream(solrStream));
        assert (tuple.EOF);
        assert (tuple.EXCEPTION);
        assert (tuple.getException().contains("No match found for function signature blah"));
    } finally {
        delete();
    }
}
Also used : ExceptionStream(org.apache.solr.client.solrj.io.stream.ExceptionStream) 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