You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by jb...@apache.org on 2019/03/27 19:53:26 UTC

[lucene-solr] branch branch_8x updated (4ff187e -> 843763d)

This is an automated email from the ASF dual-hosted git repository.

jbernste pushed a change to branch branch_8x
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git.


    from 4ff187e  LUCENE-8732: ConstantScoreQuery can now early terminate the query if the minimum score is greater than the constant score and total hits are not requested
     new 168e409  SOLR-13294: TestSQLHandler failures on windows jenkins machines
     new 843763d  SOLR-13294: Change test file name

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../{cloud-dynamic => sql}/conf/schema.xml         |   24 +-
 .../{cloud-subdirs => sql}/conf/solrconfig.xml     |    0
 .../org/apache/solr/handler/TestSQLHandler.java    | 1804 +++++++-------------
 3 files changed, 595 insertions(+), 1233 deletions(-)
 copy solr/core/src/test-files/solr/configsets/{cloud-dynamic => sql}/conf/schema.xml (94%)
 copy solr/core/src/test-files/solr/configsets/{cloud-subdirs => sql}/conf/solrconfig.xml (100%)


[lucene-solr] 02/02: SOLR-13294: Change test file name

Posted by jb...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jbernste pushed a commit to branch branch_8x
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git

commit 843763db061149f5c416dabaa3a5cce712fce2a4
Author: Joel Bernstein <jb...@apache.org>
AuthorDate: Wed Mar 27 15:34:03 2019 -0400

    SOLR-13294: Change test file name
---
 solr/core/src/test/org/apache/solr/handler/TestSQLHandler.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/solr/core/src/test/org/apache/solr/handler/TestSQLHandler.java b/solr/core/src/test/org/apache/solr/handler/TestSQLHandler.java
index c26db3a..e858c2f 100644
--- a/solr/core/src/test/org/apache/solr/handler/TestSQLHandler.java
+++ b/solr/core/src/test/org/apache/solr/handler/TestSQLHandler.java
@@ -41,7 +41,7 @@ import org.junit.Test;
 @Slow
 @SolrTestCaseJ4.SuppressSSL
 @LuceneTestCase.SuppressCodecs({"Lucene3x", "Lucene40","Lucene41","Lucene42","Lucene45"})
-public class TestSQLHandler2 extends SolrCloudTestCase {
+public class TestSQLHandler extends SolrCloudTestCase {
 
   private static final String COLLECTIONORALIAS = "collection1";
   private static final int TIMEOUT = DEFAULT_TIMEOUT;


[lucene-solr] 01/02: SOLR-13294: TestSQLHandler failures on windows jenkins machines

Posted by jb...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jbernste pushed a commit to branch branch_8x
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git

commit 168e409d6d9e4593e47bdb97b8d53d3badabd808
Author: Joel Bernstein <jb...@apache.org>
AuthorDate: Wed Mar 27 15:31:57 2019 -0400

    SOLR-13294: TestSQLHandler failures on windows jenkins machines
---
 .../test-files/solr/configsets/sql/conf/schema.xml |  293 ++++
 .../solr/configsets/sql/conf/solrconfig.xml        |   48 +
 .../org/apache/solr/handler/TestSQLHandler.java    | 1804 +++++++-------------
 3 files changed, 924 insertions(+), 1221 deletions(-)

diff --git a/solr/core/src/test-files/solr/configsets/sql/conf/schema.xml b/solr/core/src/test-files/solr/configsets/sql/conf/schema.xml
new file mode 100644
index 0000000..b5e2dea
--- /dev/null
+++ b/solr/core/src/test-files/solr/configsets/sql/conf/schema.xml
@@ -0,0 +1,293 @@
+<?xml version="1.0" ?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements.  See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License.  You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<!-- The Solr schema file, version 1.6  -->
+
+<schema name="sql" version="1.6">
+  <!-- attribute "name" is the name of this schema and is only used for display purposes.
+       Applications should change this to reflect the nature of the search collection.
+       version="x.y" is Solr's version number for the schema syntax and semantics.  It should
+       not normally be changed by applications.
+       1.0: multiValued attribute did not exist, all fields are multiValued by nature
+       1.1: multiValued attribute introduced, false by default
+       1.2: omitTermFreqAndPositions attribute introduced, true by default except for text fields.
+       1.3: removed optional field compress feature
+       1.4: default auto-phrase (QueryParser feature) to off
+       1.5: omitNorms defaults to true for primitive field types (int, float, boolean, string...)
+       1.6: useDocValuesAsStored defaults to true.
+     -->
+  <fieldType name="int" class="${solr.tests.IntegerFieldType}" docValues="true" precisionStep="0" positionIncrementGap="0"/>
+  <fieldType name="float" class="${solr.tests.FloatFieldType}" docValues="true" precisionStep="0" positionIncrementGap="0"/>
+  <fieldType name="long" class="${solr.tests.LongFieldType}" docValues="true" precisionStep="0" positionIncrementGap="0"/>
+  <fieldType name="double" class="${solr.tests.DoubleFieldType}" docValues="true" precisionStep="0" positionIncrementGap="0"/>
+
+  <fieldType name="tint" class="${solr.tests.IntegerFieldType}" docValues="true" precisionStep="8" positionIncrementGap="0"/>
+  <fieldType name="tfloat" class="${solr.tests.FloatFieldType}" docValues="true" precisionStep="8" positionIncrementGap="0"/>
+  <fieldType name="tlong" class="${solr.tests.LongFieldType}" docValues="true" precisionStep="8" positionIncrementGap="0"/>
+  <fieldType name="tdouble" class="${solr.tests.DoubleFieldType}" docValues="true" precisionStep="8" positionIncrementGap="0"/>
+
+  <!-- Field type demonstrating an Analyzer failure -->
+  <fieldType name="failtype1" class="solr.TextField">
+    <analyzer type="index">
+      <tokenizer class="solr.MockTokenizerFactory"/>
+      <filter class="solr.WordDelimiterGraphFilterFactory" generateWordParts="1" generateNumberParts="0" catenateWords="0"
+              catenateNumbers="0" catenateAll="0"/>
+      <filter class="solr.LowerCaseFilterFactory"/>
+      <filter class="solr.FlattenGraphFilterFactory"/>
+    </analyzer>
+  </fieldType>
+
+  <!-- Demonstrating ignoreCaseChange -->
+  <fieldType name="wdf_nocase" class="solr.TextField">
+    <analyzer type="index">
+      <tokenizer class="solr.MockTokenizerFactory"/>
+      <filter class="solr.WordDelimiterGraphFilterFactory" generateWordParts="1" generateNumberParts="0" catenateWords="0"
+              catenateNumbers="0" catenateAll="0" splitOnCaseChange="0" preserveOriginal="0"/>
+      <filter class="solr.LowerCaseFilterFactory"/>
+      <filter class="solr.FlattenGraphFilterFactory"/>
+    </analyzer>
+    <analyzer type="query">
+      <tokenizer class="solr.MockTokenizerFactory"/>
+      <filter class="solr.WordDelimiterGraphFilterFactory" generateWordParts="1" generateNumberParts="0" catenateWords="0"
+              catenateNumbers="0" catenateAll="0" splitOnCaseChange="0" preserveOriginal="0"/>
+      <filter class="solr.LowerCaseFilterFactory"/>
+    </analyzer>
+  </fieldType>
+
+  <fieldType name="wdf_preserve" class="solr.TextField">
+    <analyzer type="index">
+      <tokenizer class="solr.MockTokenizerFactory"/>
+      <filter class="solr.WordDelimiterGraphFilterFactory" generateWordParts="0" generateNumberParts="1" catenateWords="0"
+              catenateNumbers="0" catenateAll="0" splitOnCaseChange="0" preserveOriginal="1"/>
+      <filter class="solr.LowerCaseFilterFactory"/>
+      <filter class="solr.FlattenGraphFilterFactory"/>
+    </analyzer>
+    <analyzer type="query">
+      <tokenizer class="solr.MockTokenizerFactory"/>
+      <filter class="solr.WordDelimiterGraphFilterFactory" generateWordParts="0" generateNumberParts="1" catenateWords="0"
+              catenateNumbers="0" catenateAll="0" splitOnCaseChange="0" preserveOriginal="1"/>
+      <filter class="solr.LowerCaseFilterFactory"/>
+    </analyzer>
+  </fieldType>
+
+
+  <!-- HighlitText optimizes storage for (long) columns which will be highlit -->
+  <fieldType name="highlittext" class="solr.TextField"/>
+
+  <fieldType name="boolean" class="solr.BoolField" sortMissingLast="true"/>
+  <fieldType name="string" class="solr.StrField" sortMissingLast="true"/>
+
+  <!-- format for date is 1995-12-31T23:59:59.999Z and only the fractional
+       seconds part (.999) is optional.
+    -->
+  <fieldType name="date" class="${solr.tests.DateFieldType}" docValues="${solr.tests.numeric.dv}" sortMissingLast="true"/>
+  <fieldType name="tdate" class="${solr.tests.DateFieldType}" docValues="${solr.tests.numeric.dv}" sortMissingLast="true" precisionStep="6"/>
+
+  <fieldType name="text" class="solr.TextField" positionIncrementGap="100" autoGeneratePhraseQueries="true">
+    <analyzer type="index">
+      <tokenizer class="solr.MockTokenizerFactory"/>
+      <filter class="solr.WordDelimiterGraphFilterFactory" generateWordParts="1" generateNumberParts="1" catenateWords="1"
+              catenateNumbers="1" catenateAll="0" splitOnCaseChange="1"/>
+      <filter class="solr.LowerCaseFilterFactory"/>
+      <filter class="solr.PorterStemFilterFactory"/>
+      <filter class="solr.FlattenGraphFilterFactory"/>
+    </analyzer>
+    <analyzer type="query">
+      <tokenizer class="solr.MockTokenizerFactory"/>
+      <filter class="solr.WordDelimiterGraphFilterFactory" generateWordParts="1" generateNumberParts="1" catenateWords="0"
+              catenateNumbers="0" catenateAll="0" splitOnCaseChange="1"/>
+      <filter class="solr.LowerCaseFilterFactory"/>
+      <filter class="solr.PorterStemFilterFactory"/>
+    </analyzer>
+  </fieldType>
+
+  <fieldType name="unstemmed" class="solr.TextField" positionIncrementGap="100" autoGeneratePhraseQueries="true">
+    <analyzer>
+      <tokenizer class="solr.MockTokenizerFactory"/>
+      <filter class="solr.LowerCaseFilterFactory"/>
+    </analyzer>
+  </fieldType>
+
+  <!-- field type that doesn't generate phrases from unquoted multiple tokens per analysis unit -->
+  <fieldType name="text_np" class="solr.TextField" positionIncrementGap="100">
+    <analyzer type="index">
+      <tokenizer class="solr.MockTokenizerFactory"/>
+      <filter class="solr.WordDelimiterGraphFilterFactory" generateWordParts="1" generateNumberParts="1" catenateWords="1"
+              catenateNumbers="1" catenateAll="0" splitOnCaseChange="1"/>
+      <filter class="solr.LowerCaseFilterFactory"/>
+      <filter class="solr.PorterStemFilterFactory"/>
+      <filter class="solr.FlattenGraphFilterFactory"/>
+    </analyzer>
+    <analyzer type="query">
+      <tokenizer class="solr.MockTokenizerFactory"/>
+      <filter class="solr.WordDelimiterGraphFilterFactory" generateWordParts="1" generateNumberParts="1" catenateWords="0"
+              catenateNumbers="0" catenateAll="0" splitOnCaseChange="1"/>
+      <filter class="solr.LowerCaseFilterFactory"/>
+      <filter class="solr.PorterStemFilterFactory"/>
+    </analyzer>
+  </fieldType>
+
+  <fieldType name="nametext" class="solr.TextField">
+    <analyzer class="org.apache.lucene.analysis.core.WhitespaceAnalyzer"/>
+  </fieldType>
+
+  <fieldType name="unstored" class="solr.StrField" indexed="true" stored="false"/>
+
+  <fieldType name="textgap" class="solr.TextField" multiValued="true" positionIncrementGap="100">
+    <analyzer>
+      <tokenizer class="solr.MockTokenizerFactory"/>
+      <filter class="solr.LowerCaseFilterFactory"/>
+    </analyzer>
+  </fieldType>
+
+  <fieldType name="uuid" class="solr.UUIDField"/>
+  <fieldType name="ignored" class="solr.StrField" indexed="false" stored="false"/>
+
+
+  <fieldType name="random" class="solr.RandomSortField" indexed="true"/>
+
+  <!-- Poly field -->
+  <fieldType name="xy" class="solr.PointType" dimension="2" subFieldType="double"/>
+  <fieldType name="xyd" class="solr.PointType" dimension="2" subFieldSuffix="*_d"/>
+  <fieldType name="geohash" class="solr.GeoHashField"/>
+
+  <fieldType name="point" class="solr.PointType" dimension="2" subFieldSuffix="_d"/>
+  <!-- A specialized field for geospatial search. If indexed, this fieldType must not be multivalued. -->
+  <fieldType name="location" class="solr.LatLonType" subFieldSuffix="_coordinate"/>
+
+  <fieldType class="org.apache.solr.schema.SortableBinaryField" name="sortable_binary"/>
+
+  <field name="id" type="string" indexed="true" stored="true" multiValued="false" docValues="true" required="true"/>
+  <field name="signatureField" type="string" indexed="true" stored="false"/>
+  <field name="uuid" type="uuid" stored="true"/>
+  <field name="name" type="nametext" indexed="true" stored="true"/>
+  <field name="text" type="text" indexed="true" stored="false" multiValued="true"/>
+  <field name="subject" type="text" indexed="true" stored="true"/>
+  <field name="title" type="nametext" indexed="true" stored="true"/>
+  <field name="weight" type="float" indexed="true" stored="true"/>
+  <field name="bday" type="date" indexed="true" stored="true"/>
+
+  <field name="text_np" type="text_np" indexed="true" stored="false"/>
+
+  <!-- to test property inheritance and overriding -->
+  <field name="shouldbeunstored" type="unstored"/>
+  <field name="shouldbestored" type="unstored" stored="true"/>
+  <field name="shouldbeunindexed" type="unstored" indexed="false" stored="true"/>
+
+
+  <!-- test different combinations of indexed and stored -->
+  <field name="bind" type="boolean" indexed="true" stored="false"/>
+  <field name="bsto" type="boolean" indexed="false" stored="true"/>
+  <field name="bindsto" type="boolean" indexed="true" stored="true"/>
+  <field name="isto" type="int" indexed="false" stored="true"/>
+  <field name="iind" type="int" indexed="true" stored="false"/>
+  <field name="ssto" type="string" indexed="false" stored="true"/>
+  <field name="sind" type="string" indexed="true" stored="false"/>
+  <field name="sindsto" type="string" indexed="true" stored="true"/>
+
+  <!-- test combinations of term vector settings -->
+  <field name="test_basictv" type="text" termVectors="true"/>
+  <field name="test_notv" type="text" termVectors="false"/>
+  <field name="test_postv" type="text" termVectors="true" termPositions="true"/>
+  <field name="test_offtv" type="text" termVectors="true" termOffsets="true"/>
+  <field name="test_posofftv" type="text" termVectors="true"
+         termPositions="true" termOffsets="true"/>
+
+  <!-- test highlit field settings -->
+  <field name="test_hlt" type="highlittext" indexed="true"/>
+  <field name="test_hlt_off" type="highlittext" indexed="true"/>
+
+  <!--
+  <field name="timestamp" type="date" indexed="true" stored="true" default="NOW"/>
+  -->
+  <field name="timestamp" type="date" indexed="true" stored="true"/>
+
+  <!-- Test a point field for distances -->
+  <field name="point" type="xy" indexed="true" stored="true" multiValued="false"/>
+  <field name="pointD" type="xyd" indexed="true" stored="true" multiValued="false"/>
+  <field name="point_hash" type="geohash" indexed="true" stored="true" multiValued="false"/>
+  <field name="store" type="location" indexed="true" stored="true"/>
+
+  <!-- to test uniq fields -->
+  <field name="uniq" type="string" indexed="true" stored="true" multiValued="true"/>
+  <field name="uniq2" type="string" indexed="true" stored="true" multiValued="true"/>
+  <field name="uniq3" type="string" indexed="true" stored="true"/>
+  <field name="nouniq" type="string" indexed="true" stored="true" multiValued="true"/>
+
+
+  <field name="copyfield_source" type="string" indexed="true" stored="true" multiValued="true"/>
+
+  <field name="payload" type="sortable_binary" indexed="false"
+         stored="true" multiValued="false" docValues="true"/>
+
+  <!-- for versioning -->
+  <field name="_version_" type="long" indexed="true" stored="true"/>
+  <!-- points to the root document of a block of nested documents -->
+  <field name="_root_" type="string" indexed="true" stored="true"/>
+
+  <field name="_route_" type="string" indexed="true" stored="true" multiValued="false"/>
+
+  <field name="multi_int_with_docvals" type="tint" multiValued="true" docValues="true" indexed="false"/>
+
+  <dynamicField name="*_coordinate" type="tdouble" indexed="true" stored="false"/>
+
+  <dynamicField name="*_sI" type="string" indexed="true" stored="false"/>
+  <dynamicField name="*_sS" type="string" indexed="false" stored="true"/>
+  <dynamicField name="t_*" type="text" indexed="true" stored="true"/>
+  <dynamicField name="tv_*" type="text" indexed="true" stored="true"
+                termVectors="true" termPositions="true" termOffsets="true"/>
+  <dynamicField name="tv_mv_*" type="text" indexed="true" stored="true" multiValued="true"
+                termVectors="true" termPositions="true" termOffsets="true"/>
+
+  <dynamicField name="*_mfacet" type="string" indexed="true" stored="false" multiValued="true"/>
+
+  <dynamicField name="*_i" type="int" indexed="true" stored="true"/>
+  <dynamicField name="*_is" type="int" indexed="true" stored="true" multiValued="true"/>
+  <dynamicField name="*_s1" type="string" indexed="true" stored="true" multiValued="false"/>
+  <dynamicField name="*_s" type="string" indexed="true" stored="true" docValues="true" multiValued="false"/>
+  <dynamicField name="*_l" type="long" indexed="true" stored="true"/>
+  <dynamicField name="*_ll" type="long" indexed="true" stored="true" multiValued="true"/>
+  <dynamicField name="*_t" type="text" indexed="true" stored="true"/>
+  <dynamicField name="*_u" type="unstemmed" indexed="true" stored="true"/>
+  <dynamicField name="*_ws" type="nametext" indexed="true" stored="true"/>
+  <dynamicField name="*_b" type="boolean" indexed="true" stored="true"/>
+  <dynamicField name="*_f" type="float" indexed="true" stored="true"/>
+  <dynamicField name="*_d" type="double" indexed="true" stored="true"/>
+  <dynamicField name="*_dt" type="date" indexed="true" stored="true"/>
+
+  <!-- some trie-coded dynamic fields for faster range queries -->
+  <dynamicField name="*_ti" type="tint" indexed="true" stored="true"/>
+  <dynamicField name="*_tl" type="tlong" indexed="true" stored="true"/>
+  <dynamicField name="*_tf" type="tfloat" indexed="true" stored="true"/>
+  <dynamicField name="*_td" type="tdouble" indexed="true" stored="true"/>
+  <dynamicField name="*_tdt" type="tdate" indexed="true" stored="true"/>
+
+  <dynamicField name="ignored_*" type="ignored" multiValued="true"/>
+  <dynamicField name="attr_*" type="text" indexed="true" stored="true" multiValued="true"/>
+
+  <dynamicField name="random_*" type="random"/>
+
+
+  <uniqueKey>id</uniqueKey>
+
+  <!-- example of a custom similarity -->
+  <similarity class="solr.CustomSimilarityFactory">
+    <str name="echo">I am your default sim</str>
+  </similarity>
+
+</schema>
diff --git a/solr/core/src/test-files/solr/configsets/sql/conf/solrconfig.xml b/solr/core/src/test-files/solr/configsets/sql/conf/solrconfig.xml
new file mode 100644
index 0000000..059e58f
--- /dev/null
+++ b/solr/core/src/test-files/solr/configsets/sql/conf/solrconfig.xml
@@ -0,0 +1,48 @@
+<?xml version="1.0" ?>
+
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements.  See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License.  You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<!-- Minimal solrconfig.xml with /select, /admin and /update only -->
+
+<config>
+
+  <dataDir>${solr.data.dir:}</dataDir>
+
+  <directoryFactory name="DirectoryFactory"
+                    class="${solr.directoryFactory:solr.NRTCachingDirectoryFactory}"/>
+  <schemaFactory class="ClassicIndexSchemaFactory"/>
+
+  <luceneMatchVersion>${tests.luceneMatchVersion:LATEST}</luceneMatchVersion>
+
+  <updateHandler class="solr.DirectUpdateHandler2">
+    <commitWithin>
+      <softCommit>${solr.commitwithin.softcommit:true}</softCommit>
+    </commitWithin>
+    <updateLog></updateLog>
+  </updateHandler>
+
+  <requestHandler name="/select" class="solr.SearchHandler">
+    <lst name="defaults">
+      <str name="echoParams">explicit</str>
+      <str name="indent">true</str>
+      <str name="df">text</str>
+    </lst>
+
+  </requestHandler>
+</config>
+
diff --git a/solr/core/src/test/org/apache/solr/handler/TestSQLHandler.java b/solr/core/src/test/org/apache/solr/handler/TestSQLHandler.java
index 757452d..c26db3a 100644
--- a/solr/core/src/test/org/apache/solr/handler/TestSQLHandler.java
+++ b/solr/core/src/test/org/apache/solr/handler/TestSQLHandler.java
@@ -16,136 +16,88 @@
  */
 package org.apache.solr.handler;
 
-import java.lang.invoke.MethodHandles;
-
-import java.io.BufferedReader;
 import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Random;
-import java.util.concurrent.TimeUnit;
+import java.util.Map;
 
 import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.LuceneTestCase.Slow;
 import org.apache.solr.SolrTestCaseJ4;
-import org.apache.solr.client.solrj.SolrClient;
-import org.apache.solr.client.solrj.SolrRequest;
-import org.apache.solr.client.solrj.SolrServerException;
-import org.apache.solr.client.solrj.impl.InputStreamResponseParser;
 import org.apache.solr.client.solrj.io.Tuple;
 import org.apache.solr.client.solrj.io.stream.ExceptionStream;
 import org.apache.solr.client.solrj.io.stream.SolrStream;
 import org.apache.solr.client.solrj.io.stream.TupleStream;
-import org.apache.solr.client.solrj.request.QueryRequest;
-import org.apache.solr.cloud.AbstractFullDistribZkTestBase;
+import org.apache.solr.client.solrj.request.CollectionAdminRequest;
+import org.apache.solr.client.solrj.request.UpdateRequest;
 import org.apache.solr.cloud.SolrCloudTestCase;
-import org.apache.solr.common.cloud.Replica;
 import org.apache.solr.common.params.CommonParams;
 import org.apache.solr.common.params.ModifiableSolrParams;
 import org.apache.solr.common.params.SolrParams;
-import org.apache.solr.common.util.NamedList;
-import org.junit.After;
 import org.junit.Before;
+import org.junit.BeforeClass;
 import org.junit.Test;
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-@LuceneTestCase.Slow
+@Slow
 @SolrTestCaseJ4.SuppressSSL
 @LuceneTestCase.SuppressCodecs({"Lucene3x", "Lucene40","Lucene41","Lucene42","Lucene45"})
-public class TestSQLHandler extends AbstractFullDistribZkTestBase {
-  private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
-
-  static {
-    schemaString = "schema-sql.xml";
-  }
-
-  public TestSQLHandler() {
-    sliceCount = 2;
-  }
-
-  @Override
-  protected String getCloudSolrConfig() {
-    return "solrconfig-sql.xml";
-  }
+public class TestSQLHandler2 extends SolrCloudTestCase {
+
+  private static final String COLLECTIONORALIAS = "collection1";
+  private static final int TIMEOUT = DEFAULT_TIMEOUT;
+  private static final String id = "id";
+
+  private static boolean useAlias;
+
+  @BeforeClass
+  public static void setupCluster() throws Exception {
+    configureCluster(4)
+        .addConfig("conf", configset("sql"))
+        .configure();
+
+    String collection;
+    useAlias = random().nextBoolean();
+    if (useAlias) {
+      collection = COLLECTIONORALIAS + "_collection";
+    } else {
+      collection = COLLECTIONORALIAS;
+    }
 
-  @Override
-  protected String getCloudSchemaFile() {
-    return schemaString;
+    CollectionAdminRequest.createCollection(collection, "conf", 2, 1).process(cluster.getSolrClient());
+    cluster.waitForActiveCollection(collection, 2, 2);
+    if (useAlias) {
+      CollectionAdminRequest.createAlias(COLLECTIONORALIAS, collection).process(cluster.getSolrClient());
+    }
   }
 
   @Before
-  @Override
-  public void setUp() throws Exception {
-    super.setUp();
-
-    System.setProperty("numShards", Integer.toString(sliceCount));
-  }
-
-  @Override
-  @After
-  public void tearDown() throws Exception {
-    super.tearDown();
-    resetExceptionIgnores();
+  public void cleanIndex() throws Exception {
+    new UpdateRequest()
+        .deleteByQuery("*:*")
+        .commit(cluster.getSolrClient(), COLLECTIONORALIAS);
   }
 
   @Test
-  public void doTest() throws Exception {
-    cloudClient.waitForState(DEFAULT_COLLECTION, 30, TimeUnit.SECONDS,
-        SolrCloudTestCase.activeClusterShape(sliceCount, 4));
-
-    testBasicSelect();
-    testWhere();
-    testMixedCaseFields();
-    testBasicGrouping();
-    testBasicGroupingTint();
-    testBasicGroupingIntLongPoints();
-    testBasicGroupingFloatDoublePoints();
-    testBasicGroupingFacets();
-    testSelectDistinct();
-    testSelectDistinctFacets();
-    testAggregatesWithoutGrouping();
-    testSQLException();
-    testTimeSeriesGrouping();
-    testTimeSeriesGroupingFacet();
-    testParallelBasicGrouping();
-    testParallelSelectDistinct();
-    testParallelTimeSeriesGrouping();
-  }
-
-  private void testBasicSelect() throws Exception {
-
-    del("*:*");
+  public void testBasicSelect() throws Exception {
 
-    commit();
 
-    indexDoc(sdoc("id", "1", "text", "XXXX XXXX", "str_s", "a", "field_i", "7", "field_i_p", "7",
-        "field_f_p", "7.5", "field_d_p", "7.5", "field_l_p", "7"));
-    indexDoc(sdoc("id", "2", "text", "XXXX XXXX", "str_s", "b", "field_i", "8", "field_i_p", "8",
-        "field_f_p", "8.5", "field_d_p", "8.5", "field_l_p", "8"));
-    indexDoc(sdoc("id", "3", "text", "XXXX XXXX", "str_s", "a", "field_i", "20", "field_i_p", "20",
-        "field_f_p", "20.5", "field_d_p", "20.5", "field_l_p", "20"));
-    indexDoc(sdoc("id", "4", "text", "XXXX XXXX", "str_s", "b", "field_i", "11", "field_i_p", "11",
-        "field_f_p", "11.5", "field_d_p", "11.5", "field_l_p", "11"));
-    indexDoc(sdoc("id", "5", "text", "XXXX XXXX", "str_s", "c", "field_i", "30", "field_i_p", "30", "" +
-        "field_f_p", "30.5", "field_d_p", "30.5", "field_l_p", "30"));
-    indexDoc(sdoc("id", "6", "text", "XXXX XXXX", "str_s", "c", "field_i", "40", "field_i_p", "40",
-        "field_f_p", "40.5", "field_d_p", "40.5", "field_l_p", "40"));
-    indexDoc(sdoc("id", "7", "text", "XXXX XXXX", "str_s", "c", "field_i", "50", "field_i_p", "50",
-        "field_f_p", "50.5", "field_d_p", "50.5", "field_l_p", "50"));
-    indexDoc(sdoc("id", "8", "text", "XXXX XXXX", "str_s", "c", "field_i", "60", "field_i_p", "60",
-        "field_f_p", "60.5", "field_d_p", "60.5", "field_l_p", "60"));
-    commit();
-
-    System.out.println("############# testBasicSelect() ############");
+    new UpdateRequest()
+        .add("id", "1", "text_t", "XXXX XXXX", "str_s", "a", "field_i", "7", "field_f", "7.5", "field_d", "7.5", "field_l", "7")
+        .add("id", "2", "text_t", "XXXX XXXX", "str_s", "b", "field_i", "8", "field_f", "8.5", "field_d", "8.5", "field_l", "8")
+        .add("id", "3", "text_t", "XXXX XXXX", "str_s", "a", "field_i", "20", "field_f", "20.5", "field_d", "20.5", "field_l", "20")
+        .add("id", "4", "text_t", "XXXX XXXX", "str_s", "b", "field_i", "11", "field_f", "11.5", "field_d", "11.5", "field_l", "11")
+        .add("id", "5", "text_t", "XXXX XXXX", "str_s", "c", "field_i", "30", "field_f", "30.5", "field_d", "30.5", "field_l", "30")
+        .add("id", "6", "text_t", "XXXX XXXX", "str_s", "c", "field_i", "40", "field_f", "40.5", "field_d", "40.5", "field_l", "40")
+        .add("id", "7", "text_t", "XXXX XXXX", "str_s", "c", "field_i", "50", "field_f", "50.5", "field_d", "50.5", "field_l", "50")
+        .add("id", "8", "text_t", "XXXX XXXX", "str_s", "c", "field_i", "60", "field_f", "60.5", "field_d", "60.5", "field_l", "60")
+        .commit(cluster.getSolrClient(), COLLECTIONORALIAS);
 
     SolrParams sParams = mapParams(CommonParams.QT, "/sql",
         "stmt",
-        "select id, field_i, str_s, field_i_p, field_f_p, field_d_p, field_l_p from collection1 where (text='(XXXX)' OR text='XXXX') AND text='XXXX' order by field_i desc");
+        "select id, field_i, str_s, field_f, field_d, field_l from collection1 where (text_t='(XXXX)' OR text_t='XXXX') AND text_t='XXXX' order by field_i desc");
 
-    List<Tuple> tuples = getTuples(sParams);
+    String baseUrl = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;
+    List<Tuple> tuples = getTuples(sParams, baseUrl);
 
     assert (tuples.size() == 8);
     Tuple tuple;
@@ -154,83 +106,82 @@ public class TestSQLHandler extends AbstractFullDistribZkTestBase {
     assertEquals(tuple.getLong("id").longValue(), 8);
     assertEquals(tuple.getLong("field_i").longValue(), 60);
     assert (tuple.get("str_s").equals("c"));
-    assertEquals(tuple.getLong("field_i_p").longValue(), 60L);
-    assertEquals(tuple.getDouble("field_f_p"), 60.5, 0.0);
-    assertEquals(tuple.getDouble("field_d_p"), 60.5, 0.0);
-    assertEquals(tuple.getLong("field_l_p").longValue(), 60);
+    assertEquals(tuple.getLong("field_i").longValue(), 60L);
+    assertEquals(tuple.getDouble("field_f"), 60.5, 0.0);
+    assertEquals(tuple.getDouble("field_d"), 60.5, 0.0);
+    assertEquals(tuple.getLong("field_l").longValue(), 60);
 
     tuple = tuples.get(1);
     assertEquals(tuple.getLong("id").longValue(), 7);
     assertEquals(tuple.getLong("field_i").longValue(), 50);
     assert (tuple.get("str_s").equals("c"));
-    assertEquals(tuple.getLong("field_i_p").longValue(), 50);
-    assertEquals(tuple.getDouble("field_f_p"), 50.5, 0.0);
-    assertEquals(tuple.getDouble("field_d_p"), 50.5, 0.0);
-    assertEquals(tuple.getLong("field_l_p").longValue(), 50);
+    assertEquals(tuple.getLong("field_i").longValue(), 50);
+    assertEquals(tuple.getDouble("field_f"), 50.5, 0.0);
+    assertEquals(tuple.getDouble("field_d"), 50.5, 0.0);
+    assertEquals(tuple.getLong("field_l").longValue(), 50);
 
     tuple = tuples.get(2);
     assertEquals(tuple.getLong("id").longValue(), 6);
     assertEquals(tuple.getLong("field_i").longValue(), 40);
     assert (tuple.get("str_s").equals("c"));
-    assertEquals(tuple.getLong("field_i_p").longValue(), 40);
-    assertEquals(tuple.getDouble("field_f_p"), 40.5, 0.0);
-    assertEquals(tuple.getDouble("field_d_p"), 40.5, 0.0);
-    assertEquals(tuple.getLong("field_l_p").longValue(), 40);
+    assertEquals(tuple.getLong("field_i").longValue(), 40);
+    assertEquals(tuple.getDouble("field_f"), 40.5, 0.0);
+    assertEquals(tuple.getDouble("field_d"), 40.5, 0.0);
+    assertEquals(tuple.getLong("field_l").longValue(), 40);
 
     tuple = tuples.get(3);
     assertEquals(tuple.getLong("id").longValue(), 5);
     assertEquals(tuple.getLong("field_i").longValue(), 30);
     assert (tuple.get("str_s").equals("c"));
-    assertEquals(tuple.getLong("field_i_p").longValue(), 30);
-    assertEquals(tuple.getDouble("field_f_p"), 30.5, 0.0);
-    assertEquals(tuple.getDouble("field_d_p"), 30.5, 0.0);
-    assertEquals(tuple.getLong("field_l_p").longValue(), 30);
+    assertEquals(tuple.getLong("field_i").longValue(), 30);
+    assertEquals(tuple.getDouble("field_f"), 30.5, 0.0);
+    assertEquals(tuple.getDouble("field_d"), 30.5, 0.0);
+    assertEquals(tuple.getLong("field_l").longValue(), 30);
 
     tuple = tuples.get(4);
     assertEquals(tuple.getLong("id").longValue(), 3);
     assertEquals(tuple.getLong("field_i").longValue(), 20);
     assert (tuple.get("str_s").equals("a"));
-    assertEquals(tuple.getLong("field_i_p").longValue(), 20);
-    assertEquals(tuple.getDouble("field_f_p"), 20.5, 0.0);
-    assertEquals(tuple.getDouble("field_d_p"), 20.5, 0.0);
-    assertEquals(tuple.getLong("field_l_p").longValue(), 20);
+    assertEquals(tuple.getLong("field_i").longValue(), 20);
+    assertEquals(tuple.getDouble("field_f"), 20.5, 0.0);
+    assertEquals(tuple.getDouble("field_d"), 20.5, 0.0);
+    assertEquals(tuple.getLong("field_l").longValue(), 20);
 
     tuple = tuples.get(5);
     assertEquals(tuple.getLong("id").longValue(), 4);
     assertEquals(tuple.getLong("field_i").longValue(), 11);
     assert (tuple.get("str_s").equals("b"));
-    assertEquals(tuple.getLong("field_i_p").longValue(), 11);
-    assertEquals(tuple.getDouble("field_f_p"), 11.5, 0.0);
-    assertEquals(tuple.getDouble("field_d_p"), 11.5, 0.0);
-    assertEquals(tuple.getLong("field_l_p").longValue(), 11);
+    assertEquals(tuple.getLong("field_i").longValue(), 11);
+    assertEquals(tuple.getDouble("field_f"), 11.5, 0.0);
+    assertEquals(tuple.getDouble("field_d"), 11.5, 0.0);
+    assertEquals(tuple.getLong("field_l").longValue(), 11);
 
     tuple = tuples.get(6);
     assertEquals(tuple.getLong("id").longValue(), 2);
     assertEquals(tuple.getLong("field_i").longValue(), 8);
     assert (tuple.get("str_s").equals("b"));
-    assertEquals(tuple.getLong("field_i_p").longValue(), 8);
-    assertEquals(tuple.getDouble("field_f_p"), 8.5, 0.0);
-    assertEquals(tuple.getDouble("field_d_p"), 8.5, 0.0);
-    assertEquals(tuple.getLong("field_l_p").longValue(), 8);
+    assertEquals(tuple.getLong("field_i").longValue(), 8);
+    assertEquals(tuple.getDouble("field_f"), 8.5, 0.0);
+    assertEquals(tuple.getDouble("field_d"), 8.5, 0.0);
+    assertEquals(tuple.getLong("field_l").longValue(), 8);
 
     tuple = tuples.get(7);
     assertEquals(tuple.getLong("id").longValue(), 1);
     assertEquals(tuple.getLong("field_i").longValue(), 7);
     assert (tuple.get("str_s").equals("a"));
-    assertEquals(tuple.getLong("field_i_p").longValue(), 7);
-    assertEquals(tuple.getDouble("field_f_p"), 7.5, 0.0);
-    assertEquals(tuple.getDouble("field_d_p"), 7.5, 0.0);
-    assertEquals(tuple.getLong("field_l_p").longValue(), 7);
+    assertEquals(tuple.getLong("field_i").longValue(), 7);
+    assertEquals(tuple.getDouble("field_f"), 7.5, 0.0);
+    assertEquals(tuple.getDouble("field_d"), 7.5, 0.0);
+    assertEquals(tuple.getLong("field_l").longValue(), 7);
 
     // Assert field order
-    assertResponseContains(clients.get(0), sParams,
-        "{\"docs\":[{\"id\":\"8\",\"field_i\":60,\"str_s\":\"c\",\"field_i_p\":60,\"field_f_p\":60.5,\"field_d_p\":60.5,\"field_l_p\":60}");
+    //assertResponseContains(clients.get(0), sParams, "{\"docs\":[{\"id\":\"8\",\"field_i\":60,\"str_s\":\"c\",\"field_i\":60,\"field_f\":60.5,\"field_d\":60.5,\"field_l\":60}");
+
 
-    // Test unlimited unsorted result. Should sort on _version_ desc
     sParams = mapParams(CommonParams.QT, "/sql", "stmt",
-        "select id, field_i, str_s from collection1 where text='XXXX'");
+        "select id, field_i, str_s from collection1 where text_t='XXXX' order by id desc");
 
-    tuples = getTuples(sParams);
+    tuples = getTuples(sParams, baseUrl);
 
     assert (tuples.size() == 8);
 
@@ -275,9 +226,9 @@ public class TestSQLHandler extends AbstractFullDistribZkTestBase {
     assert (tuple.get("str_s").equals("a"));
 
     sParams = mapParams(CommonParams.QT, "/sql",
-        "stmt", "select id, field_i, str_s from collection1 where text='XXXX' order by field_i desc limit 1");
+        "stmt", "select id, field_i, str_s from collection1 where text_t='XXXX' order by field_i desc limit 1");
 
-    tuples = getTuples(sParams);
+    tuples = getTuples(sParams, baseUrl);
 
     assert (tuples.size() == 1);
 
@@ -287,9 +238,9 @@ public class TestSQLHandler extends AbstractFullDistribZkTestBase {
     assert (tuple.get("str_s").equals("c"));
 
     sParams = mapParams(CommonParams.QT, "/sql", "stmt",
-        "select id, field_i, str_s from collection1 where text='XXXX' AND id='(1 2 3)' order by field_i desc");
+        "select id, field_i, str_s from collection1 where text_t='XXXX' AND id='(1 2 3)' order by field_i desc");
 
-    tuples = getTuples(sParams);
+    tuples = getTuples(sParams, baseUrl);
 
     assert (tuples.size() == 3);
 
@@ -310,32 +261,9 @@ public class TestSQLHandler extends AbstractFullDistribZkTestBase {
 
     sParams = mapParams(CommonParams.QT, "/sql",
         "stmt",
-        "select id as myId, field_i as myInt, str_s as myString from collection1 where text='XXXX' AND id='(1 2 3)' order by myInt desc");
-
-    tuples = getTuples(sParams);
-
-    assert (tuples.size() == 3);
-
-    tuple = tuples.get(0);
-    assert (tuple.getLong("myId") == 3);
-    assert (tuple.getLong("myInt") == 20);
-    assert (tuple.get("myString").equals("a"));
-
-    tuple = tuples.get(1);
-    assert (tuple.getLong("myId") == 2);
-    assert (tuple.getLong("myInt") == 8);
-    assert (tuple.get("myString").equals("b"));
-
-    tuple = tuples.get(2);
-    assert (tuple.getLong("myId") == 1);
-    assert (tuple.getLong("myInt") == 7);
-    assert (tuple.get("myString").equals("a"));
-
-    sParams = mapParams(CommonParams.QT, "/sql",
-        "stmt",
-        "select id as myId, field_i as myInt, str_s as myString from collection1 where text='XXXX' AND id='(1 2 3)' order by field_i desc");
+        "select id as myId, field_i as myInt, str_s as myString from collection1 where text_t='XXXX' AND id='(1 2 3)' order by myInt desc");
 
-    tuples = getTuples(sParams);
+    tuples = getTuples(sParams, baseUrl);
 
     assert (tuples.size() == 3);
 
@@ -354,18 +282,11 @@ public class TestSQLHandler extends AbstractFullDistribZkTestBase {
     assert (tuple.getLong("myInt") == 7);
     assert (tuple.get("myString").equals("a"));
 
-    // Test after reload SOLR-9059//
-    Replica leader = getShardLeader("collection1", "shard1", 30 /* timeout secs */);
-
-    // reload collection and wait to see the core report it has been reloaded
-    boolean wasReloaded = reloadCollection(leader, "collection1");
-    assertTrue(wasReloaded);
-
     sParams = mapParams(CommonParams.QT, "/sql",
         "stmt",
-        "select id as myId, field_i as myInt, str_s as myString from collection1 where text='XXXX' AND id='(1 2 3)' order by field_i desc");
+        "select id as myId, field_i as myInt, str_s as myString from collection1 where text_t='XXXX' AND id='(1 2 3)' order by field_i desc");
 
-    tuples = getTuples(sParams);
+    tuples = getTuples(sParams, baseUrl);
 
     assert (tuples.size() == 3);
 
@@ -388,33 +309,34 @@ public class TestSQLHandler extends AbstractFullDistribZkTestBase {
     sParams = mapParams(CommonParams.QT, "/sql",
         "stmt", "select id, field_i, str_s from collection1 where 1 = 0");
 
-    tuples = getTuples(sParams);
+    tuples = getTuples(sParams, baseUrl);
 
     assertEquals(0, tuples.size());
 
   }
 
-  private void testWhere() throws Exception {
 
-    del("*:*");
+  @Test
+  public void testWhere() throws Exception {
 
-    commit();
+    new UpdateRequest()
+        .add("id", "1", "text_t", "XXXX XXXX", "str_s", "a", "field_i", "7")
+        .add("id", "2", "text_t", "XXXX XXXX", "str_s", "b", "field_i", "8")
+        .add("id", "3", "text_t", "XXXX XXXX", "str_s", "a", "field_i", "20")
+        .add("id", "4", "text_t", "XXXX XXXX", "str_s", "b", "field_i", "11")
+        .add("id", "5", "text_t", "XXXX XXXX", "str_s", "c", "field_i", "30")
+        .add("id", "6", "text_t", "XXXX XXXX", "str_s", "c", "field_i", "40")
+        .add("id", "7", "text_t", "XXXX XXXX", "str_s", "c", "field_i", "50")
+        .add("id", "8", "text_t", "XXXX XXXX", "str_s", "c", "field_i", "60")
+        .commit(cluster.getSolrClient(), COLLECTIONORALIAS);
 
-    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();
+    String baseUrl = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;
 
     // Equals
     SolrParams sParams = mapParams(CommonParams.QT, "/sql",
         "stmt", "select id from collection1 where id = 1 order by id asc");
 
-    List<Tuple> tuples = getTuples(sParams);
+    List<Tuple> tuples = getTuples(sParams, baseUrl);
 
     assertEquals(1, tuples.size());
 
@@ -425,7 +347,7 @@ public class TestSQLHandler extends AbstractFullDistribZkTestBase {
     sParams = mapParams(CommonParams.QT, "/sql",
         "stmt", "select id from collection1 where id <> 1 order by id asc limit 10");
 
-    tuples = getTuples(sParams);
+    tuples = getTuples(sParams,baseUrl);
 
     assertEquals(7, tuples.size());
 
@@ -472,7 +394,7 @@ public class TestSQLHandler extends AbstractFullDistribZkTestBase {
     sParams = mapParams(CommonParams.QT, "/sql",
         "stmt", "select id from collection1 where id < 2 order by id asc");
 
-    tuples = getTuples(sParams);
+    tuples = getTuples(sParams, baseUrl);
 
     assertEquals(1, tuples.size());
 
@@ -483,7 +405,7 @@ public class TestSQLHandler extends AbstractFullDistribZkTestBase {
     sParams = mapParams(CommonParams.QT, "/sql",
         "stmt", "select id from collection1 where id <= 2 order by id asc");
 
-    tuples = getTuples(sParams);
+    tuples = getTuples(sParams, baseUrl);
 
     assertEquals(2, tuples.size());
 
@@ -496,7 +418,7 @@ public class TestSQLHandler extends AbstractFullDistribZkTestBase {
     sParams = mapParams(CommonParams.QT, "/sql",
         "stmt", "select id from collection1 where id > 7 order by id asc");
 
-    tuples = getTuples(sParams);
+    tuples = getTuples(sParams, baseUrl);
 
     assertEquals(1, tuples.size());
 
@@ -507,7 +429,7 @@ public class TestSQLHandler extends AbstractFullDistribZkTestBase {
     sParams = mapParams(CommonParams.QT, "/sql",
         "stmt", "select id from collection1 where id >= 7 order by id asc");
 
-    tuples = getTuples(sParams);
+    tuples = getTuples(sParams, baseUrl);
 
     assertEquals(2, tuples.size());
 
@@ -518,26 +440,26 @@ public class TestSQLHandler extends AbstractFullDistribZkTestBase {
 
   }
 
-  private void testMixedCaseFields() throws Exception {
-
-    del("*:*");
+  @Test
+  public void testMixedCaseFields() throws Exception {
 
-    commit();
+    new UpdateRequest()
+        .add("id", "1", "Text_t", "XXXX XXXX", "Str_s", "a", "Field_i", "7")
+        .add("id", "2", "Text_t", "XXXX XXXX", "Str_s", "b", "Field_i", "8")
+        .add("id", "3", "Text_t", "XXXX XXXX", "Str_s", "a", "Field_i", "20")
+        .add("id", "4", "Text_t", "XXXX XXXX", "Str_s", "b", "Field_i", "11")
+        .add("id", "5", "Text_t", "XXXX XXXX", "Str_s", "c", "Field_i", "30")
+        .add("id", "6", "Text_t", "XXXX XXXX", "Str_s", "c", "Field_i", "40")
+        .add("id", "7", "Text_t", "XXXX XXXX", "Str_s", "c", "Field_i", "50")
+        .add("id", "8", "Text_t", "XXXX XXXX", "Str_s", "c", "Field_i", "60")
+        .commit(cluster.getSolrClient(), COLLECTIONORALIAS);
 
-    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();
+    String baseUrl = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;
 
     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");
 
-    List<Tuple> tuples = getTuples(sParams);
+    List<Tuple> tuples = getTuples(sParams, baseUrl);
 
     assert (tuples.size() == 8);
 
@@ -588,7 +510,7 @@ public class TestSQLHandler extends AbstractFullDistribZkTestBase {
         "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");
 
-    tuples = getTuples(sParams);
+    tuples = getTuples(sParams, baseUrl);
 
     assert (tuples.size() == 2);
 
@@ -604,7 +526,7 @@ public class TestSQLHandler extends AbstractFullDistribZkTestBase {
         "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");
 
-    tuples = getTuples(sParams);
+    tuples = getTuples(sParams, baseUrl);
 
     assert (tuples.size() == 2);
 
@@ -618,602 +540,166 @@ public class TestSQLHandler extends AbstractFullDistribZkTestBase {
 
   }
 
-  private void testSQLException() throws Exception {
+  @Test
+  public void testSelectDistinctFacets() throws Exception {
 
-    CloudJettyRunner jetty = this.cloudJettys.get(0);
+    new UpdateRequest()
+        .add("id", "1", "text_t", "XXXX XXXX", "str_s", "a", "field_i", "1")
+        .add("id", "2", "text_t", "XXXX XXXX", "str_s", "b", "field_i", "2")
+        .add("id", "3", "text_t", "XXXX XXXX", "str_s", "a", "field_i", "20")
+        .add("id", "4", "text_t", "XXXX XXXX", "str_s", "b", "field_i", "2")
+        .add("id", "5", "text_t", "XXXX XXXX", "str_s", "c", "field_i", "30")
+        .add("id", "6", "text_t", "XXXX XXXX", "str_s", "c", "field_i", "30")
+        .add("id", "7", "text_t", "XXXX XXXX", "str_s", "c", "field_i", "50")
+        .add("id", "8", "text_t", "XXXX XXXX", "str_s", "c", "field_i", "60")
+        .commit(cluster.getSolrClient(), COLLECTIONORALIAS);
 
-    del("*:*");
+    String baseUrl = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;
 
-    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", "facet",
+        "stmt", "select distinct str_s, field_i from collection1 order by str_s asc, field_i asc");
 
-    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");
+    List<Tuple> tuples = getTuples(sParams, baseUrl);
 
-    solrStream = new SolrStream(jetty.url, sParams);
-    tuple = getTuple(new ExceptionStream(solrStream));
-    assert (tuple.EOF);
-    assert (tuple.EXCEPTION);
+    // assert(false);
+    assert (tuples.size() == 6);
 
-    assert (tuple.getException().contains("Column 'field_iff' not found in any table"));
+    Tuple tuple;
 
-    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))");
+    tuple = tuples.get(0);
+    assert (tuple.get("str_s").equals("a"));
+    assert (tuple.getLong("field_i") == 1);
 
-    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"));
+    tuple = tuples.get(1);
+    assert (tuple.get("str_s").equals("a"));
+    assert (tuple.getLong("field_i") == 20);
 
-    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))");
+    tuple = tuples.get(2);
+    assert (tuple.get("str_s").equals("b"));
+    assert (tuple.getLong("field_i") == 2);
 
-    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"));
+    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);
 
-  private void testBasicGrouping() throws Exception {
+    tuple = tuples.get(5);
+    assert (tuple.get("str_s").equals("c"));
+    assert (tuple.getLong("field_i") == 60);
 
-    del("*:*");
+    // 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");
 
-    commit();
+    tuples = getTuples(sParams, baseUrl);
 
-    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();
+    assert (tuples.size() == 6);
 
-    SolrParams sParams = mapParams(CommonParams.QT, "/sql", "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");
+    tuple = tuples.get(0);
+    assert (tuple.get("str_s").equals("c"));
+    assert (tuple.getLong("field_i") == 60);
 
-    List<Tuple> tuples = getTuples(sParams);
+    tuple = tuples.get(1);
+    assert (tuple.get("str_s").equals("c"));
+    assert (tuple.getLong("field_i") == 50);
 
-    // Only two results because of the limit.
-    assert (tuples.size() == 2);
-    Tuple tuple;
+    tuple = tuples.get(2);
+    assert (tuple.get("str_s").equals("c"));
+    assert (tuple.getLong("field_i") == 30);
 
-    tuple = tuples.get(0);
+    tuple = tuples.get(3);
     assert (tuple.get("str_s").equals("b"));
-    assert (tuple.getDouble("EXPR$1") == 2); // count(*)
-    assert (tuple.getDouble("EXPR$2") == 19); // sum(field_i)
-    assert (tuple.getDouble("EXPR$3") == 8); // min(field_i)
-    assert (tuple.getDouble("EXPR$4") == 11); // max(field_i)
-    assert (tuple.getDouble("EXPR$5") == 10); // avg(field_i)
+    assert (tuple.getLong("field_i") == 2);
 
-    tuple = tuples.get(1);
+    tuple = tuples.get(4);
     assert (tuple.get("str_s").equals("a"));
-    assert (tuple.getDouble("EXPR$1") == 2); // count(*)
-    assert (tuple.getDouble("EXPR$2") == 27); // sum(field_i)
-    assert (tuple.getDouble("EXPR$3") == 7); // min(field_i)
-    assert (tuple.getDouble("EXPR$4") == 20); // max(field_i)
-    assert (tuple.getDouble("EXPR$5") == 14); // avg(field_i)
+    assert (tuple.getLong("field_i") == 20);
 
-    sParams = mapParams(CommonParams.QT, "/sql", "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) as blah from collection1 where text='XXXX' group by str_s order by sum(field_i) asc limit 2");
+    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");
 
-    tuples = getTuples(sParams);
+    tuples = getTuples(sParams, baseUrl);
 
-    // Only two results because of the limit.
-    assert (tuples.size() == 2);
+    assert (tuples.size() == 6);
 
     tuple = tuples.get(0);
-    assert (tuple.get("str_s").equals("b"));
-    assert (tuple.getDouble("EXPR$1") == 2); // count(*)
-    assert (tuple.getDouble("EXPR$2") == 19); // sum(field_i)
-    assert (tuple.getDouble("EXPR$3") == 8); // min(field_i)
-    assert (tuple.getDouble("EXPR$4") == 11); // max(field_i)
-    assert (tuple.getDouble("blah") == 9.5); // avg(field_i)
+    assert (tuple.get("myString").equals("c"));
+    assert (tuple.getLong("myInt") == 60);
 
     tuple = tuples.get(1);
-    assert (tuple.get("str_s").equals("a"));
-    assert (tuple.getDouble("EXPR$1") == 2); // count(*)
-    assert (tuple.getDouble("EXPR$2") == 27); // sum(field_i)
-    assert (tuple.getDouble("EXPR$3") == 7); // min(field_i)
-    assert (tuple.getDouble("EXPR$4") == 20); // max(field_i)
-    assert (tuple.getDouble("blah") == 13.5); // avg(field_i)
-
-    sParams = mapParams(CommonParams.QT, "/sql", "aggregationMode", "map_reduce",
-        "stmt",
-        "select str_s as myString, 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");
-
-    tuples = getTuples(sParams);
+    assert (tuple.get("myString").equals("c"));
+    assert (tuple.getLong("myInt") == 50);
 
-    // Only two results because of the limit.
-    assert (tuples.size() == 2);
+    tuple = tuples.get(2);
+    assert (tuple.get("myString").equals("c"));
+    assert (tuple.getLong("myInt") == 30);
 
-    tuple = tuples.get(0);
+    tuple = tuples.get(3);
     assert (tuple.get("myString").equals("b"));
-    assert (tuple.getDouble("EXPR$1") == 2); // count(*)
-    assert (tuple.getDouble("mySum") == 19);
-    assert (tuple.getDouble("EXPR$3") == 8); // min(field_i)
-    assert (tuple.getDouble("EXPR$4") == 11); // max(field_i)
-    assert (tuple.getDouble("EXPR$5") == 10); // avg(field_i)
+    assert (tuple.getLong("myInt") == 2);
 
-    tuple = tuples.get(1);
+    tuple = tuples.get(4);
     assert (tuple.get("myString").equals("a"));
-    assert (tuple.getDouble("EXPR$1") == 2); // count(*)
-    assert (tuple.getDouble("mySum") == 27);
-    assert (tuple.getDouble("EXPR$3") == 7); // min(field_i)
-    assert (tuple.getDouble("EXPR$4") == 20); // max(field_i)
-    assert (tuple.getDouble("EXPR$5") == 14); // avg(field_i)
+    assert (tuple.getLong("myInt") == 20);
 
-    sParams = mapParams(CommonParams.QT, "/sql", "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' AND NOT ((text='XXXY') AND (text='XXXY' OR text='XXXY'))) "
-            + "group by str_s order by str_s desc");
+    tuple = tuples.get(5);
+    assert (tuple.get("myString").equals("a"));
+    assert (tuple.getLong("myInt") == 1);
 
-    tuples = getTuples(sParams);
+    // 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");
 
-    // The sort by and order by match and no limit is applied. All the Tuples should be returned in
-    // this scenario.
+    tuples = getTuples(sParams, baseUrl);
 
-    assert (tuples.size() == 3);
+    assert (tuples.size() == 2);
 
     tuple = tuples.get(0);
     assert (tuple.get("str_s").equals("c"));
-    assert (tuple.getDouble("EXPR$1") == 4); // count(*)
-    assert (tuple.getDouble("EXPR$2") == 180); // sum(field_i)
-    assert (tuple.getDouble("EXPR$3") == 30); // min(field_i)
-    assert (tuple.getDouble("EXPR$4") == 60); // max(field_i)
-    assert (tuple.getDouble("EXPR$5") == 45); // avg(field_i)
+    assert (tuple.getLong("field_i") == 60);
 
     tuple = tuples.get(1);
-    assert (tuple.get("str_s").equals("b"));
-    assert (tuple.getDouble("EXPR$1") == 2); // count(*)
-    assert (tuple.getDouble("EXPR$2") == 19); // sum(field_i)
-    assert (tuple.getDouble("EXPR$3") == 8); // min(field_i)
-    assert (tuple.getDouble("EXPR$4") == 11); // max(field_i)
-    assert (tuple.getDouble("EXPR$5") == 10D); // avg(field_i)
-
-    tuple = tuples.get(2);
-    assert (tuple.get("str_s").equals("a"));
-    assert (tuple.getDouble("EXPR$1") == 2); // count(*)
-    assert (tuple.getDouble("EXPR$2") == 27); // sum(field_i)
-    assert (tuple.getDouble("EXPR$3") == 7); // min(field_i)
-    assert (tuple.getDouble("EXPR$4") == 20); // max(field_i)
-
-    assert (tuple.getDouble("EXPR$5") == 14); // avg(field_i)
-
-    sParams = mapParams(CommonParams.QT, "/sql", "aggregationMode", "map_reduce",
-        "stmt", "select str_s as myString, count(*) as myCount, sum(field_i) as mySum, min(field_i) as myMin, "
-            + "max(field_i) as myMax, avg(field_i) as myAvg from collection1 "
-            + "where (text='XXXX' AND NOT (text='XXXY')) group by str_s order by str_s desc");
+    assert (tuple.get("str_s").equals("c"));
+    assert (tuple.getLong("field_i") == 50);
 
-    tuples = getTuples(sParams);
+    // 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");
 
-    // The sort by and order by match and no limit is applied. All the Tuples should be returned in
-    // this scenario.
+    tuples = getTuples(sParams, baseUrl);
 
-    assert (tuples.size() == 3);
+    assert (tuples.size() == 6);
 
     tuple = tuples.get(0);
-    assert (tuple.get("myString").equals("c"));
-    assert (tuple.getDouble("myCount") == 4);
-    assert (tuple.getDouble("mySum") == 180);
-    assert (tuple.getDouble("myMin") == 30);
-    assert (tuple.getDouble("myMax") == 60);
-    assert (tuple.getDouble("myAvg") == 45);
+    assert (tuple.get("str_s").equals("a"));
+    assert (tuple.getLong("field_i") == 1);
 
     tuple = tuples.get(1);
-    assert (tuple.get("myString").equals("b"));
-    assert (tuple.getDouble("myCount") == 2);
-    assert (tuple.getDouble("mySum") == 19);
-    assert (tuple.getDouble("myMin") == 8);
-    assert (tuple.getDouble("myMax") == 11);
-    assert (tuple.getDouble("myAvg") == 10);
-
-    tuple = tuples.get(2);
-    assert (tuple.get("myString").equals("a"));
-    assert (tuple.getDouble("myCount") == 2);
-    assert (tuple.getDouble("mySum") == 27);
-    assert (tuple.getDouble("myMin") == 7);
-    assert (tuple.getDouble("myMax") == 20);
-    assert (tuple.getDouble("myAvg") == 14);
-
-    sParams = mapParams(CommonParams.QT, "/sql", "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");
 
-    tuples = getTuples(sParams);
+    assert (tuple.get("str_s").equals("a"));
+    assert (tuple.getLong("field_i") == 20);
 
-    assert (tuples.size() == 1);
+    tuple = tuples.get(2);
 
-    tuple = tuples.get(0);
     assert (tuple.get("str_s").equals("b"));
-    assert (tuple.getDouble("EXPR$1") == 2); // count(*)
-    assert (tuple.getDouble("EXPR$2") == 19); // sum(field_i)
-    assert (tuple.getDouble("EXPR$3") == 8); // min(field_i)
-    assert (tuple.getDouble("EXPR$4") == 11); // max(field_i)
-    assert (tuple.getDouble("EXPR$5") == 10); // avg(field_i)
+    assert (tuple.getLong("field_i") == 2);
 
-    sParams = mapParams(CommonParams.QT, "/sql", "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))");
+    tuple = tuples.get(3);
 
-    tuples = getTuples(sParams);
+    assert (tuple.get("str_s").equals("c"));
+    assert (tuple.getLong("field_i") == 30);
 
-    assert (tuples.size() == 1);
-
-    tuple = tuples.get(0);
-    assert (tuple.get("str_s").equals("b"));
-    assert (tuple.getDouble("EXPR$1") == 2); // count(*)
-    assert (tuple.getDouble("EXPR$2") == 19); // sum(field_i)
-    assert (tuple.getDouble("EXPR$3") == 8); // min(field_i)
-    assert (tuple.getDouble("EXPR$4") == 11); // max(field_i)
-    assert (tuple.getDouble("EXPR$5") == 10); // avg(field_i)
-
-    sParams = mapParams(CommonParams.QT, "/sql", "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 " +
-            "having ((sum(field_i) = 19) AND (min(field_i) = 8))");
-
-    tuples = getTuples(sParams);
-
-    assert (tuples.size() == 1);
-
-    tuple = tuples.get(0);
-    assert (tuple.get("str_s").equals("b"));
-    assert (tuple.getDouble("EXPR$1") == 2); // count(*)
-    assert (tuple.getDouble("mySum") == 19);
-    assert (tuple.getDouble("EXPR$3") == 8); // min(field_i)
-    assert (tuple.getDouble("EXPR$4") == 11); // max(field_i)
-    assert (tuple.getDouble("EXPR$5") == 10); // avg(field_i)
-
-    sParams = mapParams(CommonParams.QT, "/sql", "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))");
-
-    tuples = getTuples(sParams);
-
-    assert (tuples.size() == 0);
-
-  }
-
-  private void testBasicGroupingTint() throws Exception {
-
-    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");
-
-    List<Tuple> tuples = getTuples(sParams);
-
-    // Only two results because of the limit.
-    assert (tuples.size() == 2);
-    Tuple tuple;
-
-    tuple = tuples.get(0);
-    assert (tuple.get("str_s").equals("b"));
-    assert (tuple.getDouble("EXPR$1") == 2); // count(*)
-    assert (tuple.getDouble("EXPR$2") == 19); // sum(field_i)
-    assert (tuple.getDouble("EXPR$3") == 8); // min(field_i)
-    assert (tuple.getDouble("EXPR$4") == 11); // max(field_i)
-    assert (tuple.getDouble("EXPR$5") == 10); // avg(field_i)
-
-    tuple = tuples.get(1);
-    assert (tuple.get("str_s").equals("a"));
-    assert (tuple.getDouble("EXPR$1") == 2); // count(*)
-    assert (tuple.getDouble("EXPR$2") == 27); // sum(field_i)
-    assert (tuple.getDouble("EXPR$3") == 7); // min(field_i)
-    assert (tuple.getDouble("EXPR$4") == 20); // max(field_i)
-    assert (tuple.getDouble("EXPR$5") == 14); // avg(field_i)
-
-  }
-
-  private void testBasicGroupingIntLongPoints() throws Exception {
-
-    Random random = random();
-    int r = random.nextInt(2);
-    String[] intOrLong = {"field_i_p", "field_l_p"};
-    String[] facetOrMap = {"facet", "map_reduce"};
-    String field = intOrLong[r];
-    r = random.nextInt(2);
-    String mode = facetOrMap[r];
-
-    del("*:*");
-
-    commit();
-
-    indexr("id", "1", "text", "XXXX XXXX", "str_s", "a", field, "7");
-    indexr("id", "2", "text", "XXXX XXXX", "str_s", "b", field, "8");
-    indexr("id", "3", "text", "XXXX XXXX", "str_s", "a", field, "20");
-    indexr("id", "4", "text", "XXXX XXXX", "str_s", "b", field, "11");
-    indexr("id", "5", "text", "XXXX XXXX", "str_s", "c", field, "30");
-    indexr("id", "6", "text", "XXXX XXXX", "str_s", "c", field, "40");
-    indexr("id", "7", "text", "XXXX XXXX", "str_s", "c", field, "50");
-    indexr("id", "8", "text", "XXXX XXXX", "str_s", "c", field, "60");
-    indexr("id", "9", "text", "XXXX XXXY", "str_s", "d", field, "70");
-    commit();
-
-    SolrParams sParams = mapParams(CommonParams.QT, "/sql", "aggregationMode", mode,
-        "stmt", "select str_s, count(*), sum(" + field + "), min(" + field + "), max(" + field + "), avg(" + field
-            + ") from collection1 where text='XXXX' group by str_s order by sum(" + field + ") asc limit 2");
-
-    List<Tuple> tuples = getTuples(sParams);
-
-    // Only two results because of the limit.
-    assert (tuples.size() == 2);
-    Tuple tuple;
-
-    tuple = tuples.get(0);
-    assert (tuple.get("str_s").equals("b"));
-    assert (tuple.getDouble("EXPR$1") == 2); // count(*)
-    assert (tuple.getDouble("EXPR$2") == 19); // sum(field_i)
-    assert (tuple.getDouble("EXPR$3") == 8); // min(field_i)
-    assert (tuple.getDouble("EXPR$4") == 11); // max(field_i)
-    assert (tuple.getDouble("EXPR$5") == 10); // avg(field_i)
-
-    tuple = tuples.get(1);
-    assert (tuple.get("str_s").equals("a"));
-    assert (tuple.getDouble("EXPR$1") == 2); // count(*)
-    assert (tuple.getDouble("EXPR$2") == 27); // sum(field_i)
-    assert (tuple.getDouble("EXPR$3") == 7); // min(field_i)
-    assert (tuple.getDouble("EXPR$4") == 20); // max(field_i)
-    assert (tuple.getDouble("EXPR$5") == 14); // avg(field_i)
-
-  }
-
-  private void testBasicGroupingFloatDoublePoints() throws Exception {
-
-    Random random = random();
-    int r = random.nextInt(2);
-    String[] intOrLong = {"field_f_p", "field_d_p"};
-    String[] facetOrMap = {"facet", "map_reduce"};
-    String field = intOrLong[r];
-    r = random.nextInt(2);
-    String mode = facetOrMap[r];
-
-    del("*:*");
-
-    commit();
-
-    indexr("id", "1", "text", "XXXX XXXX", "str_s", "a", field, "7.0");
-    indexr("id", "2", "text", "XXXX XXXX", "str_s", "b", field, "8.0");
-    indexr("id", "3", "text", "XXXX XXXX", "str_s", "a", field, "20.0");
-    indexr("id", "4", "text", "XXXX XXXX", "str_s", "b", field, "11.0");
-    indexr("id", "5", "text", "XXXX XXXX", "str_s", "c", field, "30.0");
-    indexr("id", "6", "text", "XXXX XXXX", "str_s", "c", field, "40.0");
-    indexr("id", "7", "text", "XXXX XXXX", "str_s", "c", field, "50.0");
-    indexr("id", "8", "text", "XXXX XXXX", "str_s", "c", field, "60.0");
-    indexr("id", "9", "text", "XXXX XXXY", "str_s", "d", field, "70.0");
-    commit();
-
-    SolrParams sParams = mapParams(CommonParams.QT, "/sql", "aggregationMode", mode,
-        "stmt", "select str_s, count(*), sum(" + field + "), min(" + field + "), max(" + field + "), avg(" + field
-            + ") from collection1 where text='XXXX' group by str_s order by sum(" + field + ") asc limit 2");
-
-    List<Tuple> tuples = getTuples(sParams);
-
-    // Only two results because of the limit.
-    assert (tuples.size() == 2);
-    Tuple tuple;
-
-    tuple = tuples.get(0);
-    assert (tuple.get("str_s").equals("b"));
-    assertEquals(tuple.getDouble("EXPR$1"), 2, 0.0); // count(*)
-    assertEquals(tuple.getDouble("EXPR$2"), 19, 0.0); // sum(field_i)
-    assertEquals(tuple.getDouble("EXPR$3"), 8, 0.0); // min(field_i)
-    assertEquals(tuple.getDouble("EXPR$4"), 11, 0.0); // max(field_i)
-    assertEquals(tuple.getDouble("EXPR$5"), 9.5, 0.0); // avg(field_i)
-
-    tuple = tuples.get(1);
-    assert (tuple.get("str_s").equals("a"));
-    assertEquals(tuple.getDouble("EXPR$1"), 2, 0.0); // count(*)
-    assertEquals(tuple.getDouble("EXPR$2"), 27, 0.0); // sum(field_i)
-    assertEquals(tuple.getDouble("EXPR$3"), 7, 0.0); // min(field_i)
-    assertEquals(tuple.getDouble("EXPR$4"), 20, 0.0); // max(field_i)
-    assertEquals(tuple.getDouble("EXPR$5"), 13.5, 0.0); // avg(field_i)
-
-  }
-
-  private void testSelectDistinctFacets() throws Exception {
-
-    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 #######");
-
-    List<Tuple> tuples = getTuples(sParams);
-
-    // 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");
-
-    tuples = getTuples(sParams);
-
-    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");
-
-    tuples = getTuples(sParams);
-
-    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");
-
-    tuples = getTuples(sParams);
-
-    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");
-
-    tuples = getTuples(sParams);
-
-    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);
+    tuple = tuples.get(4);
 
     assert (tuple.get("str_s").equals("c"));
     assert (tuple.getLong("field_i") == 50);
@@ -1227,7 +713,7 @@ public class TestSQLHandler extends AbstractFullDistribZkTestBase {
     sParams = mapParams(CommonParams.QT, "/sql", "aggregationMode", "facet",
         "stmt", "select distinct str_s, field_i from collection1 where str_s = 'a'");
 
-    tuples = getTuples(sParams);
+    tuples = getTuples(sParams, baseUrl);
 
     assert (tuples.size() == 2);
 
@@ -1241,28 +727,27 @@ public class TestSQLHandler extends AbstractFullDistribZkTestBase {
 
   }
 
-  private void testSelectDistinct() throws Exception {
 
-    del("*:*");
+  @Test
+  public void testSelectDistinct() throws Exception {
 
-    commit();
+    new UpdateRequest()
+        .add("id", "1", "text_t", "XXXX XXXX", "str_s", "a", "field_i", "1")
+        .add("id", "2", "text_t", "XXXX XXXX", "str_s", "b", "field_i", "2")
+        .add("id", "3", "text_t", "XXXX XXXX", "str_s", "a", "field_i", "20")
+        .add("id", "4", "text_t", "XXXX XXXX", "str_s", "b", "field_i", "2")
+        .add("id", "5", "text_t", "XXXX XXXX", "str_s", "c", "field_i", "30")
+        .add("id", "6", "text_t", "XXXX XXXX", "str_s", "c", "field_i", "30")
+        .add("id", "7", "text_t", "XXXX XXXX", "str_s", "c", "field_i", "50")
+        .add("id", "8", "text_t", "XXXX XXXX", "str_s", "c", "field_i", "60")
+        .commit(cluster.getSolrClient(), COLLECTIONORALIAS);
 
-    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();
+    String baseUrl = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;
 
     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()");
-
-    List<Tuple> tuples = getTuples(sParams);
+    List<Tuple> tuples = getTuples(sParams, baseUrl);
 
     assert (tuples.size() == 6);
     Tuple tuple = tuples.get(0);
@@ -1293,7 +778,7 @@ public class TestSQLHandler extends AbstractFullDistribZkTestBase {
     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");
 
-    tuples = getTuples(sParams);
+    tuples = getTuples(sParams, baseUrl);
 
     assert (tuples.size() == 6);
 
@@ -1324,7 +809,7 @@ public class TestSQLHandler extends AbstractFullDistribZkTestBase {
     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");
 
-    tuples = getTuples(sParams);
+    tuples = getTuples(sParams, baseUrl);
 
     assert (tuples.size() == 6);
 
@@ -1356,7 +841,7 @@ public class TestSQLHandler extends AbstractFullDistribZkTestBase {
     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");
 
-    tuples = getTuples(sParams);
+    tuples = getTuples(sParams, baseUrl);
 
     assert (tuples.size() == 2);
 
@@ -1372,7 +857,7 @@ public class TestSQLHandler extends AbstractFullDistribZkTestBase {
     sParams = mapParams(CommonParams.QT, "/sql", "aggregationMode", "map_reduce",
         "stmt", "select distinct str_s, field_i from collection1");
 
-    tuples = getTuples(sParams);
+    tuples = getTuples(sParams, baseUrl);
 
     assert (tuples.size() == 6);
 
@@ -1404,7 +889,7 @@ public class TestSQLHandler extends AbstractFullDistribZkTestBase {
     sParams = mapParams(CommonParams.QT, "/sql", "aggregationMode", "map_reduce",
         "stmt", "select distinct str_s, field_i from collection1 where str_s = 'a'");
 
-    tuples = getTuples(sParams);
+    tuples = getTuples(sParams, baseUrl);
 
     assert (tuples.size() == 2);
 
@@ -1418,25 +903,25 @@ public class TestSQLHandler extends AbstractFullDistribZkTestBase {
 
   }
 
-  private void testParallelSelectDistinct() throws Exception {
-
-    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();
+  @Test
+  public void testParallelSelectDistinct() throws Exception {
+
+    new UpdateRequest()
+        .add("id", "1", "text_t", "XXXX XXXX", "str_s", "a", "field_i", "1")
+        .add("id", "2", "text_t", "XXXX XXXX", "str_s", "b", "field_i", "2")
+        .add("id", "3", "text_t", "XXXX XXXX", "str_s", "a", "field_i", "20")
+        .add("id", "4", "text_t", "XXXX XXXX", "str_s", "b", "field_i", "2")
+        .add("id", "5", "text_t", "XXXX XXXX", "str_s", "c", "field_i", "30")
+        .add("id", "6", "text_t", "XXXX XXXX", "str_s", "c", "field_i", "30")
+        .add("id", "7", "text_t", "XXXX XXXX", "str_s", "c", "field_i", "50")
+        .add("id", "8", "text_t", "XXXX XXXX", "str_s", "c", "field_i", "60")
+        .commit(cluster.getSolrClient(), COLLECTIONORALIAS);
+
+    String baseUrl = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;
     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");
 
-    List<Tuple> tuples = getTuples(sParams);
+    List<Tuple> tuples = getTuples(sParams, baseUrl);
 
     assert (tuples.size() == 6);
 
@@ -1470,7 +955,7 @@ public class TestSQLHandler extends AbstractFullDistribZkTestBase {
     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");
 
-    tuples = getTuples(sParams);
+    tuples = getTuples(sParams, baseUrl);
 
     assert (tuples.size() == 6);
 
@@ -1502,7 +987,7 @@ public class TestSQLHandler extends AbstractFullDistribZkTestBase {
     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");
 
-    tuples = getTuples(sParams);
+    tuples = getTuples(sParams, baseUrl);
 
     assert (tuples.size() == 6);
 
@@ -1522,306 +1007,103 @@ public class TestSQLHandler extends AbstractFullDistribZkTestBase {
     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");
-
-    tuples = getTuples(sParams);
-
-    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");
-
-    tuples = getTuples(sParams);
-
-    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'");
-
-    tuples = getTuples(sParams);
-
-    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);
-
-  }
-
-  private void testBasicGroupingFacets() throws Exception {
-
-    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");
-
-    List<Tuple> tuples = getTuples(sParams);
-
-    // Only two results because of the limit.
-    assert (tuples.size() == 2);
-
-    Tuple tuple;
-
-    tuple = tuples.get(0);
-    assert (tuple.get("str_s").equals("b"));
-    assert (tuple.getDouble("EXPR$1") == 2); // count(*)
-    assert (tuple.getDouble("EXPR$2") == 19); // sum(field_i)
-    assert (tuple.getDouble("EXPR$3") == 8); // min(field_i)
-    assert (tuple.getDouble("EXPR$4") == 11); // max(field_i)
-    assert (tuple.getDouble("EXPR$5") == 9.5D); // avg(field_i)
-
-    tuple = tuples.get(1);
-    assert (tuple.get("str_s").equals("a"));
-    assert (tuple.getDouble("EXPR$1") == 2); // count(*)
-    assert (tuple.getDouble("EXPR$2") == 27); // sum(field_i)
-    assert (tuple.getDouble("EXPR$3") == 7); // min(field_i)
-    assert (tuple.getDouble("EXPR$4") == 20); // max(field_i)
-    assert (tuple.getDouble("EXPR$5") == 13.5D); // avg(field_i)
-
-    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");
-
-    tuples = getTuples(sParams);
-
-    // Only two results because of the limit.
-    assert (tuples.size() == 2);
-
-    tuple = tuples.get(0);
-    assert (tuple.get("str_s").equals("b"));
-    assert (tuple.getDouble("EXPR$1") == 2); // count(*)
-    assert (tuple.getDouble("EXPR$2") == 19); // sum(field_i)
-    assert (tuple.getDouble("EXPR$3") == 8); // min(field_i)
-    assert (tuple.getDouble("EXPR$4") == 11); // max(field_i)
-    assert (tuple.getDouble("EXPR$5") == 10); // avg(field_i)
-
-    tuple = tuples.get(1);
-    assert (tuple.get("str_s").equals("a"));
-    assert (tuple.getDouble("EXPR$1") == 2); // count(*)
-    assert (tuple.getDouble("EXPR$2") == 27); // sum(field_i)
-    assert (tuple.getDouble("EXPR$3") == 7); // min(field_i)
-    assert (tuple.getDouble("EXPR$4") == 20); // max(field_i)
-    assert (tuple.getDouble("EXPR$5") == 14); // avg(field_i)
-
-    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");
-
-    tuples = getTuples(sParams);
-
-    // The sort by and order by match and no limit is applied. All the Tuples should be returned in
-    // this scenario.
-
-    assert (tuples.size() == 3);
-
-    tuple = tuples.get(0);
-    assert (tuple.get("str_s").equals("c"));
-    assert (tuple.getDouble("EXPR$1") == 4); // count(*)
-    assert (tuple.getDouble("EXPR$2") == 180); // sum(field_i)
-    assert (tuple.getDouble("EXPR$3") == 30); // min(field_i)
-    assert (tuple.getDouble("EXPR$4") == 60); // max(field_i)
-    assert (tuple.getDouble("EXPR$5") == 45); // avg(field_i)
-
-    tuple = tuples.get(1);
-    assert (tuple.get("str_s").equals("b"));
-    assert (tuple.getDouble("EXPR$1") == 2); // count(*)
-    assert (tuple.getDouble("EXPR$2") == 19); // sum(field_i)
-    assert (tuple.getDouble("EXPR$3") == 8); // min(field_i)
-    assert (tuple.getDouble("EXPR$4") == 11); // max(field_i)
-    assert (tuple.getDouble("EXPR$5") == 9.5D); // avg(field_i)
-
-    tuple = tuples.get(2);
-    assert (tuple.get("str_s").equals("a"));
-    assert (tuple.getDouble("EXPR$1") == 2); // count(*)
-    assert (tuple.getDouble("EXPR$2") == 27); // sum(field_i)
-    assert (tuple.getDouble("EXPR$3") == 7); // min(field_i)
-    assert (tuple.getDouble("EXPR$4") == 20); // max(field_i)
-    assert (tuple.getDouble("EXPR$5") == 13.5D); // avg(field_i)
-
-    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");
-
-    tuples = getTuples(sParams);
-
-    // The sort by and order by match and no limit is applied. All the Tuples should be returned in
-    // this scenario.
-
-    assert (tuples.size() == 3);
-
-    tuple = tuples.get(0);
-    assert (tuple.get("myString").equals("c"));
-    assert (tuple.getDouble("EXPR$1") == 4); // count(*)
-    assert (tuple.getDouble("mySum") == 180);
-    assert (tuple.getDouble("EXPR$3") == 30); // min(field_i)
-    assert (tuple.getDouble("EXPR$4") == 60); // max(field_i)
-    assert (tuple.getDouble("EXPR$5") == 45); // avg(field_i)
-
-    tuple = tuples.get(1);
-    assert (tuple.get("myString").equals("b"));
-    assert (tuple.getDouble("EXPR$1") == 2); // count(*)
-    assert (tuple.getDouble("mySum") == 19);
-    assert (tuple.getDouble("EXPR$3") == 8); // min(field_i)
-    assert (tuple.getDouble("EXPR$4") == 11); // max(field_i)
-    assert (tuple.getDouble("EXPR$5") == 9.5D); // avg(field_i)
-
-    tuple = tuples.get(2);
+    tuple = tuples.get(4);
     assert (tuple.get("myString").equals("a"));
-    assert (tuple.getDouble("EXPR$1") == 2); // count(*)
-    assert (tuple.getDouble("mySum") == 27);
-    assert (tuple.getDouble("EXPR$3") == 7); // min(field_i)
-    assert (tuple.getDouble("EXPR$4") == 20); // max(field_i)
-    assert (tuple.getDouble("EXPR$5") == 13.5D); // avg(field_i)
+    assert (tuple.getLong("field_i") == 20);
 
-    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");
+    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");
 
-    tuples = getTuples(sParams);
+    tuples = getTuples(sParams, baseUrl);
 
-    assert (tuples.size() == 1);
+    assert (tuples.size() == 2);
 
     tuple = tuples.get(0);
-    assert (tuple.get("str_s").equals("b"));
-    assert (tuple.getDouble("EXPR$1") == 2); // count(*)
-    assert (tuple.getDouble("EXPR$2") == 19); // sum(field_i)
-    assert (tuple.getDouble("EXPR$3") == 8); // min(field_i)
-    assert (tuple.getDouble("EXPR$4") == 11); // max(field_i)
-    assert (tuple.getDouble("EXPR$5") == 9.5D); // avg(field_i)
+    assert (tuple.get("str_s").equals("c"));
+    assert (tuple.getLong("field_i") == 60);
 
-    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))");
+    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");
 
-    tuples = getTuples(sParams);
+    tuples = getTuples(sParams, baseUrl);
 
-    assert (tuples.size() == 1);
+    assert (tuples.size() == 6);
 
     tuple = tuples.get(0);
-    assert (tuple.get("str_s").equals("b"));
-    assert (tuple.getDouble("EXPR$1") == 2); // count(*)
-    assert (tuple.getDouble("EXPR$2") == 19); // sum(field_i)
-    assert (tuple.getDouble("EXPR$3") == 8); // min(field_i)
-    assert (tuple.getDouble("EXPR$4") == 11); // max(field_i)
-    assert (tuple.getDouble("EXPR$5") == 9.5D); // avg(field_i)
+    assert (tuple.get("str_s").equals("a"));
+    assert (tuple.getLong("field_i") == 1);
 
-    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))");
+    tuple = tuples.get(1);
+    assert (tuple.get("str_s").equals("a"));
+    assert (tuple.getLong("field_i") == 20);
 
-    tuples = getTuples(sParams);
+    tuple = tuples.get(2);
+    assert (tuple.get("str_s").equals("b"));
+    assert (tuple.getLong("field_i") == 2);
 
-    assert (tuples.size() == 1);
+    tuple = tuples.get(3);
+    assert (tuple.get("str_s").equals("c"));
+    assert (tuple.getLong("field_i") == 30);
 
-    tuple = tuples.get(0);
-    assert (tuple.get("str_s").equals("b"));
-    assert (tuple.getDouble("EXPR$1") == 2); // count(*)
-    assert (tuple.getDouble("mySum") == 19);
-    assert (tuple.getDouble("EXPR$3") == 8); // min(field_i)
-    assert (tuple.getDouble("EXPR$4") == 11); // max(field_i)
-    assert (tuple.getDouble("EXPR$5") == 9.5D); // avg(field_i)
+    tuple = tuples.get(4);
+    assert (tuple.get("str_s").equals("c"));
+    assert (tuple.getLong("field_i") == 50);
 
-    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))");
+    tuple = tuples.get(5);
+    assert (tuple.get("str_s").equals("c"));
+    assert (tuple.getLong("field_i") == 60);
 
-    tuples = getTuples(sParams);
+    // 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'");
 
-    assert (tuples.size() == 0);
+    tuples = getTuples(sParams, baseUrl);
 
-  }
+    assert (tuples.size() == 2);
 
-  private void testParallelBasicGrouping() throws Exception {
+    tuple = tuples.get(0);
+    assert (tuple.get("str_s").equals("a"));
+    assert (tuple.getLong("field_i") == 1);
 
-    del("*:*");
+    tuple = tuples.get(1);
+    assert (tuple.get("str_s").equals("a"));
+    assert (tuple.getLong("field_i") == 20);
 
-    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();
+  @Test
+  public void testBasicGroupingFacets() throws Exception {
+
+    new UpdateRequest()
+        .add("id", "1", "text_t", "XXXX XXXX", "str_s", "a", "field_i", "7")
+        .add("id", "2", "text_t", "XXXX XXXX", "str_s", "b", "field_i", "8")
+        .add("id", "3", "text_t", "XXXX XXXX", "str_s", "a", "field_i", "20")
+        .add("id", "4", "text_t", "XXXX XXXX", "str_s", "b", "field_i", "11")
+        .add("id", "5", "text_t", "XXXX XXXX", "str_s", "c", "field_i", "30")
+        .add("id", "6", "text_t", "XXXX XXXX", "str_s", "c", "field_i", "40")
+        .add("id", "7", "text_t", "XXXX XXXX", "str_s", "c", "field_i", "50")
+        .add("id", "8", "text_t", "XXXX XXXX", "str_s", "c", "field_i", "60")
+        .add("id", "9", "text_t", "XXXX XXXY", "str_s", "d", "field_i", "70")
+        .commit(cluster.getSolrClient(), COLLECTIONORALIAS);
+
+    String baseUrl = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;
 
-    SolrParams sParams = mapParams(CommonParams.QT, "/sql", "numWorkers", "2", "aggregationMode", "map_reduce",
+    SolrParams 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 " +
+            "cast(avg(1.0 * field_i) as float) from collection1 where text_t='XXXX' group by str_s " +
             "order by sum(field_i) asc limit 2");
 
-    List<Tuple> tuples = getTuples(sParams);
+    List<Tuple> tuples = getTuples(sParams, baseUrl);
 
     // Only two results because of the limit.
     assert (tuples.size() == 2);
@@ -1834,7 +1116,7 @@ public class TestSQLHandler extends AbstractFullDistribZkTestBase {
     assert (tuple.getDouble("EXPR$2") == 19); // sum(field_i)
     assert (tuple.getDouble("EXPR$3") == 8); // min(field_i)
     assert (tuple.getDouble("EXPR$4") == 11); // max(field_i)
-    assert (tuple.getDouble("EXPR$5") == 10); // avg(field_i)
+    assert (tuple.getDouble("EXPR$5") == 9.5D); // avg(field_i)
 
     tuple = tuples.get(1);
     assert (tuple.get("str_s").equals("a"));
@@ -1842,14 +1124,14 @@ public class TestSQLHandler extends AbstractFullDistribZkTestBase {
     assert (tuple.getDouble("EXPR$2") == 27); // sum(field_i)
     assert (tuple.getDouble("EXPR$3") == 7); // min(field_i)
     assert (tuple.getDouble("EXPR$4") == 20); // max(field_i)
-    assert (tuple.getDouble("EXPR$5") == 14); // avg(field_i)
+    assert (tuple.getDouble("EXPR$5") == 13.5D); // avg(field_i)
 
-    sParams = mapParams(CommonParams.QT, "/sql", "numWorkers", "2", "aggregationMode", "map_reduce",
+    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 " +
+            "avg(field_i) from collection1 where text_t='XXXX' group by str_s " +
             "order by sum(field_i) asc limit 2");
 
-    tuples = getTuples(sParams);
+    tuples = getTuples(sParams, baseUrl);
 
     // Only two results because of the limit.
     assert (tuples.size() == 2);
@@ -1860,46 +1142,22 @@ public class TestSQLHandler extends AbstractFullDistribZkTestBase {
     assert (tuple.getDouble("EXPR$2") == 19); // sum(field_i)
     assert (tuple.getDouble("EXPR$3") == 8); // min(field_i)
     assert (tuple.getDouble("EXPR$4") == 11); // max(field_i)
-    assert (tuple.getDouble("EXPR$5") == 9.5); // avg(field_i)
-
-    tuple = tuples.get(1);
-    assert (tuple.get("str_s").equals("a"));
-    assert (tuple.getDouble("EXPR$1") == 2); // count(*)
-    assert (tuple.getDouble("EXPR$2") == 27); // sum(field_i)
-    assert (tuple.getDouble("EXPR$3") == 7); // min(field_i)
-    assert (tuple.getDouble("EXPR$4") == 20); // max(field_i)
-    assert (tuple.getDouble("EXPR$5") == 13.5); // avg(field_i)
-
-    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");
-
-    tuples = getTuples(sParams);
-
-    // Only two results because of the limit.
-    assert (tuples.size() == 2);
-
-    tuple = tuples.get(0);
-    assert (tuple.get("str_s").equals("b"));
-    assert (tuple.getDouble("EXPR$1") == 2); // count(*)
-    assert (tuple.getDouble("mySum") == 19);
-    assert (tuple.getDouble("EXPR$3") == 8); // min(field_i)
-    assert (tuple.getDouble("EXPR$4") == 11); // max(field_i)
     assert (tuple.getDouble("EXPR$5") == 10); // avg(field_i)
 
     tuple = tuples.get(1);
     assert (tuple.get("str_s").equals("a"));
     assert (tuple.getDouble("EXPR$1") == 2); // count(*)
-    assert (tuple.getDouble("mySum") == 27);
+    assert (tuple.getDouble("EXPR$2") == 27); // sum(field_i)
     assert (tuple.getDouble("EXPR$3") == 7); // min(field_i)
     assert (tuple.getDouble("EXPR$4") == 20); // max(field_i)
     assert (tuple.getDouble("EXPR$5") == 14); // avg(field_i)
 
-    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");
+    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_t='XXXX' AND NOT (text_t='XXXY')) "
+            + "group by str_s order by str_s desc");
 
-    tuples = getTuples(sParams);
+    tuples = getTuples(sParams, baseUrl);
 
     // The sort by and order by match and no limit is applied. All the Tuples should be returned in
     // this scenario.
@@ -1920,7 +1178,7 @@ public class TestSQLHandler extends AbstractFullDistribZkTestBase {
     assert (tuple.getDouble("EXPR$2") == 19); // sum(field_i)
     assert (tuple.getDouble("EXPR$3") == 8); // min(field_i)
     assert (tuple.getDouble("EXPR$4") == 11); // max(field_i)
-    assert (tuple.getDouble("EXPR$5") == 10); // avg(field_i)
+    assert (tuple.getDouble("EXPR$5") == 9.5D); // avg(field_i)
 
     tuple = tuples.get(2);
     assert (tuple.get("str_s").equals("a"));
@@ -1928,13 +1186,14 @@ public class TestSQLHandler extends AbstractFullDistribZkTestBase {
     assert (tuple.getDouble("EXPR$2") == 27); // sum(field_i)
     assert (tuple.getDouble("EXPR$3") == 7); // min(field_i)
     assert (tuple.getDouble("EXPR$4") == 20); // max(field_i)
-    assert (tuple.getDouble("EXPR$5") == 14); // avg(field_i)
+    assert (tuple.getDouble("EXPR$5") == 13.5D); // avg(field_i)
 
-    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");
+    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_t='XXXX' AND NOT (text_t='XXXY')) "
+            + "group by str_s order by myString desc");
 
-    tuples = getTuples(sParams);
+    tuples = getTuples(sParams, baseUrl);
 
     // The sort by and order by match and no limit is applied. All the Tuples should be returned in
     // this scenario.
@@ -1944,7 +1203,7 @@ public class TestSQLHandler extends AbstractFullDistribZkTestBase {
     tuple = tuples.get(0);
     assert (tuple.get("myString").equals("c"));
     assert (tuple.getDouble("EXPR$1") == 4); // count(*)
-    assert (tuple.getDouble("EXPR$2") == 180); // sum(field_i)
+    assert (tuple.getDouble("mySum") == 180);
     assert (tuple.getDouble("EXPR$3") == 30); // min(field_i)
     assert (tuple.getDouble("EXPR$4") == 60); // max(field_i)
     assert (tuple.getDouble("EXPR$5") == 45); // avg(field_i)
@@ -1952,24 +1211,24 @@ public class TestSQLHandler extends AbstractFullDistribZkTestBase {
     tuple = tuples.get(1);
     assert (tuple.get("myString").equals("b"));
     assert (tuple.getDouble("EXPR$1") == 2); // count(*)
-    assert (tuple.getDouble("EXPR$2") == 19); // sum(field_i)
+    assert (tuple.getDouble("mySum") == 19);
     assert (tuple.getDouble("EXPR$3") == 8); // min(field_i)
     assert (tuple.getDouble("EXPR$4") == 11); // max(field_i)
-    assert (tuple.getDouble("EXPR$5") == 10); // avg(field_i)
+    assert (tuple.getDouble("EXPR$5") == 9.5D); // avg(field_i)
 
     tuple = tuples.get(2);
     assert (tuple.get("myString").equals("a"));
     assert (tuple.getDouble("EXPR$1") == 2); // count(*)
-    assert (tuple.getDouble("EXPR$2") == 27); // sum(field_i)
+    assert (tuple.getDouble("mySum") == 27);
     assert (tuple.getDouble("EXPR$3") == 7); // min(field_i)
     assert (tuple.getDouble("EXPR$4") == 20); // max(field_i)
-    assert (tuple.getDouble("EXPR$5") == 14); // avg(field_i)
+    assert (tuple.getDouble("EXPR$5") == 13.5D); // avg(field_i)
 
-    sParams = mapParams(CommonParams.QT, "/sql", "numWorkers", "2", "aggregationMode", "map_reduce",
+    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 having sum(field_i) = 19");
+            "cast(avg(1.0 * field_i) as float) from collection1 where text_t='XXXX' group by str_s having sum(field_i) = 19");
 
-    tuples = getTuples(sParams);
+    tuples = getTuples(sParams, baseUrl);
 
     assert (tuples.size() == 1);
 
@@ -1979,14 +1238,14 @@ public class TestSQLHandler extends AbstractFullDistribZkTestBase {
     assert (tuple.getDouble("EXPR$2") == 19); // sum(field_i)
     assert (tuple.getDouble("EXPR$3") == 8); // min(field_i)
     assert (tuple.getDouble("EXPR$4") == 11); // max(field_i)
-    assert (tuple.getDouble("EXPR$5") == 10); // avg(field_i)
+    assert (tuple.getDouble("EXPR$5") == 9.5D); // avg(field_i)
 
-    sParams = mapParams(CommonParams.QT, "/sql", "numWorkers", "2", "aggregationMode", "map_reduce",
+    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 " +
+            "cast(avg(1.0 * field_i) as float) from collection1 where text_t='XXXX' group by str_s " +
             "having ((sum(field_i) = 19) AND (min(field_i) = 8))");
 
-    tuples = getTuples(sParams);
+    tuples = getTuples(sParams, baseUrl);
 
     assert (tuples.size() == 1);
 
@@ -1996,43 +1255,60 @@ public class TestSQLHandler extends AbstractFullDistribZkTestBase {
     assert (tuple.getDouble("EXPR$2") == 19); // sum(field_i)
     assert (tuple.getDouble("EXPR$3") == 8); // min(field_i)
     assert (tuple.getDouble("EXPR$4") == 11); // max(field_i)
-    assert (tuple.getDouble("EXPR$5") == 10); // avg(field_i)
+    assert (tuple.getDouble("EXPR$5") == 9.5D); // avg(field_i)
 
-    sParams = mapParams(CommonParams.QT, "/sql", "numWorkers", "2", "aggregationMode", "map_reduce",
+    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_t='XXXX' group by str_s " +
+            "having ((sum(field_i) = 19) AND (min(field_i) = 8))");
+
+    tuples = getTuples(sParams, baseUrl);
+
+    assert (tuples.size() == 1);
+
+    tuple = tuples.get(0);
+    assert (tuple.get("str_s").equals("b"));
+    assert (tuple.getDouble("EXPR$1") == 2); // count(*)
+    assert (tuple.getDouble("mySum") == 19);
+    assert (tuple.getDouble("EXPR$3") == 8); // min(field_i)
+    assert (tuple.getDouble("EXPR$4") == 11); // max(field_i)
+    assert (tuple.getDouble("EXPR$5") == 9.5D); // avg(field_i)
+
+    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 " +
+            "cast(avg(1.0 * field_i) as float) from collection1 where text_t='XXXX' group by str_s " +
             "having ((sum(field_i) = 19) AND (min(field_i) = 100))");
 
-    tuples = getTuples(sParams);
+    tuples = getTuples(sParams, baseUrl);
 
     assert (tuples.size() == 0);
 
   }
 
-  private void testAggregatesWithoutGrouping() throws Exception {
-    del("*:*");
-
-    commit();
-
-    indexr(id, "0", "a_s", "hello0", "a_i", "0", "a_f", "1");
-    indexr(id, "2", "a_s", "hello0", "a_i", "2", "a_f", "2");
-    indexr(id, "3", "a_s", "hello3", "a_i", "3", "a_f", "3");
-    indexr(id, "4", "a_s", "hello4", "a_i", "4", "a_f", "4");
-    indexr(id, "1", "a_s", "hello0", "a_i", "1", "a_f", "5");
-    indexr(id, "5", "a_s", "hello3", "a_i", "10", "a_f", "6");
-    indexr(id, "6", "a_s", "hello4", "a_i", "11", "a_f", "7");
-    indexr(id, "7", "a_s", "hello3", "a_i", "12", "a_f", "8");
-    indexr(id, "8", "a_s", "hello3", "a_i", "13", "a_f", "9");
-    indexr(id, "9", "a_s", "hello0", "a_i", "14", "a_f", "10");
-
-    commit();
+  @Test
+  public void testAggregatesWithoutGrouping() 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);
+
+    String baseUrl = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;
 
     SolrParams sParams = mapParams(CommonParams.QT, "/sql", "stmt",
         "select count(*), sum(a_i), min(a_i), max(a_i), cast(avg(1.0 * a_i) as float), sum(a_f), " +
             "min(a_f), max(a_f), avg(a_f) from collection1");
 
-    
-    List<Tuple> tuples = getTuples(sParams);
+
+    List<Tuple> tuples = getTuples(sParams, baseUrl);
 
     assert (tuples.size() == 1);
 
@@ -2064,8 +1340,8 @@ public class TestSQLHandler extends AbstractFullDistribZkTestBase {
         "stmt", "select count(*) as myCount, sum(a_i) as mySum, min(a_i) as myMin, max(a_i) as myMax, " +
             "cast(avg(1.0 * a_i) as float) as myAvg, sum(a_f), min(a_f), max(a_f), avg(a_f) from collection1");
 
-    
-    tuples = getTuples(sParams);
+
+    tuples = getTuples(sParams, baseUrl);
 
     assert (tuples.size() == 1);
 
@@ -2098,8 +1374,8 @@ public class TestSQLHandler extends AbstractFullDistribZkTestBase {
         "stmt", "select count(*) as myCount, sum(a_i) as mySum, min(a_i) as myMin, max(a_i) as myMax, " +
             "avg(a_i) as myAvg, sum(a_f), min(a_f), max(a_f), avg(a_f) from collection1");
 
-    
-    tuples = getTuples(sParams);
+
+    tuples = getTuples(sParams, baseUrl);
 
     assert (tuples.size() == 1);
 
@@ -2133,8 +1409,8 @@ public class TestSQLHandler extends AbstractFullDistribZkTestBase {
         "stmt", "select count(*), sum(a_i), min(a_i), max(a_i), cast(avg(1.0 * a_i) as float), sum(a_f), " +
             "min(a_f), max(a_f), avg(a_f) from collection1 where id = 2");
 
-    
-    tuples = getTuples(sParams);
+
+    tuples = getTuples(sParams, baseUrl);
 
     assert (tuples.size() == 1);
 
@@ -2165,8 +1441,8 @@ public class TestSQLHandler extends AbstractFullDistribZkTestBase {
         "stmt", "select count(*), sum(a_i), min(a_i), max(a_i), cast(avg(1.0 * a_i) as float), sum(a_f), " +
             "min(a_f), max(a_f), avg(a_f) from collection1 where a_s = 'blah'");
 
-    
-    tuples = getTuples(sParams);
+
+    tuples = getTuples(sParams, baseUrl);
 
     assert (tuples.size() == 1);
 
@@ -2192,31 +1468,30 @@ public class TestSQLHandler extends AbstractFullDistribZkTestBase {
     assertTrue(maxf == null);
     assertTrue(avgf == null);
 
-    del("*:*");
-    commit();
   }
 
-  private void testTimeSeriesGrouping() throws Exception {
+  @Test
+  public void testTimeSeriesGrouping() throws Exception {
 
-    del("*:*");
 
-    commit();
+    new UpdateRequest()
+        .add(id, "1", "year_i", "2015", "month_i", "11", "day_i", "7", "item_i", "5")
+        .add(id, "2", "year_i", "2015", "month_i", "11", "day_i", "7", "item_i", "10")
+        .add(id, "3", "year_i", "2015", "month_i", "11", "day_i", "8", "item_i", "30")
+        .add(id, "4", "year_i", "2015", "month_i", "11", "day_i", "8", "item_i", "12")
+        .add(id, "5", "year_i", "2015", "month_i", "10", "day_i", "1", "item_i", "4")
+        .add(id, "6", "year_i", "2015", "month_i", "10", "day_i", "3", "item_i", "5")
+        .add(id, "7", "year_i", "2014", "month_i", "4", "day_i", "4", "item_i", "6")
+        .add(id, "8", "year_i", "2014", "month_i", "4", "day_i", "2", "item_i", "1")
 
-    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(cluster.getSolrClient(), COLLECTIONORALIAS);
 
-    commit();
+    String baseUrl = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;
 
-    SolrParams sParams = mapParams(CommonParams.QT, "/sql",
+    SolrParams sParams = mapParams(CommonParams.QT, "/sql", "aggregationMode", "map_reduce",
         "stmt", "select year_i, sum(item_i) from collection1 group by year_i order by year_i desc");
 
-    List<Tuple> tuples = getTuples(sParams);
+    List<Tuple> tuples = getTuples(sParams, baseUrl);
 
     assert (tuples.size() == 2);
 
@@ -2234,7 +1509,7 @@ public class TestSQLHandler extends AbstractFullDistribZkTestBase {
         "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");
 
-    tuples = getTuples(sParams);
+    tuples = getTuples(sParams, baseUrl);
 
     assert (tuples.size() == 3);
 
@@ -2257,7 +1532,7 @@ public class TestSQLHandler extends AbstractFullDistribZkTestBase {
         "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");
 
-    tuples = getTuples(sParams);
+    tuples = getTuples(sParams, baseUrl);
 
     assert (tuples.size() == 6);
 
@@ -2299,26 +1574,85 @@ public class TestSQLHandler extends AbstractFullDistribZkTestBase {
 
   }
 
-  private void testTimeSeriesGroupingFacet() throws Exception {
+  @Test
+  public void testSQLException() throws Exception {
+
+    new UpdateRequest()
+        .add(id, "1", "text_t", "XXXX XXXX", "str_s", "a", "field_i", "7")
+        .add(id, "2", "text_t", "XXXX XXXX", "str_s", "b", "field_i", "8")
+        .add(id, "3", "text_t", "XXXX XXXX", "str_s", "a", "field_i", "20")
+        .add(id, "4", "text_t", "XXXX XXXX", "str_s", "b", "field_i", "11")
+        .add(id, "5", "text_t", "XXXX XXXX", "str_s", "c", "field_i", "30")
+        .add(id, "6", "text_t", "XXXX XXXX", "str_s", "c", "field_i", "40")
+        .add(id, "7", "text_t", "XXXX XXXX", "str_s", "c", "field_i", "50")
+        .add(id, "8", "text_t", "XXXX XXXX", "str_s", "c", "field_i", "60")
+
+        .commit(cluster.getSolrClient(), COLLECTIONORALIAS);
+
+    String baseUrl = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;
+
+    SolrParams sParams = mapParams(CommonParams.QT, "/sql", "aggregationMode", "map_reduce",
+        "stmt", "select id, str_s from collection1 where text_t='XXXX' order by field_iff desc");
+
+    SolrStream solrStream = new SolrStream(baseUrl, 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_t='XXXX' order by field_iff desc");
+
+    solrStream = new SolrStream(baseUrl, 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_t='XXXX' group by str_s having ((sum(field_iff) = 19) AND (min(field_i) = 8))");
+
+    solrStream = new SolrStream(baseUrl, 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_t='XXXX' group by str_s having ((sum(field_i) = 19) AND (min(field_i) = 8))");
+
+    solrStream = new SolrStream(baseUrl, sParams);
+    tuple = getTuple(new ExceptionStream(solrStream));
+    assert (tuple.EOF);
+    assert (tuple.EXCEPTION);
+    assert (tuple.getException().contains("No match found for function signature blah"));
+  }
+
+
+  @Test
+  public void testTimeSeriesGroupingFacet() throws Exception {
 
-    del("*:*");
+    new UpdateRequest()
+        .add(id, "1", "year_i", "2015", "month_i", "11", "day_i", "7", "item_i", "5")
+        .add(id, "2", "year_i", "2015", "month_i", "11", "day_i", "7", "item_i", "10")
+        .add(id, "3", "year_i", "2015", "month_i", "11", "day_i", "8", "item_i", "30")
+        .add(id, "4", "year_i", "2015", "month_i", "11", "day_i", "8", "item_i", "12")
+        .add(id, "5", "year_i", "2015", "month_i", "10", "day_i", "1", "item_i", "4")
+        .add(id, "6", "year_i", "2015", "month_i", "10", "day_i", "3", "item_i", "5")
+        .add(id, "7", "year_i", "2014", "month_i", "4", "day_i", "4", "item_i", "6")
+        .add(id, "8", "year_i", "2014", "month_i", "4", "day_i", "2", "item_i", "1")
 
-    commit();
+        .commit(cluster.getSolrClient(), COLLECTIONORALIAS);
 
-    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");
+    String baseUrl = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;
 
-    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");
 
-    List<Tuple> tuples = getTuples(sParams);
+    List<Tuple> tuples = getTuples(sParams, baseUrl);
 
     assert (tuples.size() == 2);
 
@@ -2336,7 +1670,7 @@ public class TestSQLHandler extends AbstractFullDistribZkTestBase {
         "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");
 
-    tuples = getTuples(sParams);
+    tuples = getTuples(sParams, baseUrl);
 
     assert (tuples.size() == 3);
 
@@ -2359,7 +1693,7 @@ public class TestSQLHandler extends AbstractFullDistribZkTestBase {
         "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");
 
-    tuples = getTuples(sParams);
+    tuples = getTuples(sParams, baseUrl);
 
     assert (tuples.size() == 6);
 
@@ -2401,26 +1735,27 @@ public class TestSQLHandler extends AbstractFullDistribZkTestBase {
 
   }
 
-  private void testParallelTimeSeriesGrouping() throws Exception {
+  @Test
+  public void testParallelTimeSeriesGrouping() throws Exception {
 
-    del("*:*");
+    new UpdateRequest()
+        .add(id, "1", "year_i", "2015", "month_i", "11", "day_i", "7", "item_i", "5")
+        .add(id, "2", "year_i", "2015", "month_i", "11", "day_i", "7", "item_i", "10")
+        .add(id, "3", "year_i", "2015", "month_i", "11", "day_i", "8", "item_i", "30")
+        .add(id, "4", "year_i", "2015", "month_i", "11", "day_i", "8", "item_i", "12")
+        .add(id, "5", "year_i", "2015", "month_i", "10", "day_i", "1", "item_i", "4")
+        .add(id, "6", "year_i", "2015", "month_i", "10", "day_i", "3", "item_i", "5")
+        .add(id, "7", "year_i", "2014", "month_i", "4", "day_i", "4", "item_i", "6")
+        .add(id, "8", "year_i", "2014", "month_i", "4", "day_i", "2", "item_i", "1")
 
-    commit();
+        .commit(cluster.getSolrClient(), COLLECTIONORALIAS);
 
-    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");
+    String baseUrl = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;
 
-    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");
 
-    List<Tuple> tuples = getTuples(sParams);
+    List<Tuple> tuples = getTuples(sParams, baseUrl);
 
     assert (tuples.size() == 2);
 
@@ -2429,7 +1764,7 @@ public class TestSQLHandler extends AbstractFullDistribZkTestBase {
     tuple = tuples.get(0);
     assert (tuple.getLong("year_i") == 2015);
     assert (tuple.get("year_i") instanceof Long); // SOLR-8601, This tests that the bucket is actually a Long and not
-                                                  // parsed from a String.
+    // parsed from a String.
     assert (tuple.getDouble("EXPR$1") == 66); // sum(item_i)
 
     tuple = tuples.get(1);
@@ -2440,7 +1775,7 @@ public class TestSQLHandler extends AbstractFullDistribZkTestBase {
         "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");
 
-    tuples = getTuples(sParams);
+    tuples = getTuples(sParams, baseUrl);
 
     assert (tuples.size() == 3);
 
@@ -2465,7 +1800,7 @@ public class TestSQLHandler extends AbstractFullDistribZkTestBase {
         "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");
 
-    tuples = getTuples(sParams);
+    tuples = getTuples(sParams, baseUrl);
 
     assert (tuples.size() == 6);
 
@@ -2507,15 +1842,63 @@ public class TestSQLHandler extends AbstractFullDistribZkTestBase {
 
   }
 
-  protected List<Tuple> getTuples(final SolrParams params) throws IOException {
-    log.info("Tuples from params: {}", params);
-    TupleStream tupleStream = new SolrStream(this.cloudJettys.get(0).url, params);
-    
+
+  public boolean assertLong(Tuple tuple, String fieldName, long l) throws Exception {
+    long lv = (long)tuple.get(fieldName);
+    if(lv != l) {
+      throw new Exception("Longs not equal:"+l+" : "+lv);
+    }
+
+    return true;
+  }
+
+  public boolean assertString(Tuple tuple, String fieldName, String expected) throws Exception {
+    String actual = (String)tuple.get(fieldName);
+
+    if( (null == expected && null != actual) ||
+        (null != expected && null == actual) ||
+        (null != expected && !expected.equals(actual))){
+      throw new Exception("Longs not equal:"+expected+" : "+actual);
+    }
+
+    return true;
+  }
+
+  public boolean assertDouble(Tuple tuple, String fieldName, double d) throws Exception {
+    double dv = tuple.getDouble(fieldName);
+    if(dv != d) {
+      throw new Exception("Doubles not equal:"+d+" : "+dv);
+    }
+
+    return true;
+  }
+
+  protected boolean assertMaps(List<Map> maps, int... ids) throws Exception {
+    if(maps.size() != ids.length) {
+      throw new Exception("Expected id count != actual map count:"+ids.length+":"+maps.size());
+    }
+
+    int i=0;
+    for(int val : ids) {
+      Map t = maps.get(i);
+      String tip = (String)t.get("id");
+      if(!tip.equals(Integer.toString(val))) {
+        throw new Exception("Found value:"+tip+" expecting:"+val);
+      }
+      ++i;
+    }
+    return true;
+  }
+
+  protected List<Tuple> getTuples(final SolrParams params, String baseUrl) throws IOException {
+    //log.info("Tuples from params: {}", params);
+    TupleStream tupleStream = new SolrStream(baseUrl, params);
+
     tupleStream.open();
     List<Tuple> tuples = new ArrayList<>();
     for (;;) {
       Tuple t = tupleStream.read();
-      log.info(" ... {}", t.fields);
+      //log.info(" ... {}", t.fields);
       if (t.EOF) {
         break;
       } else {
@@ -2526,13 +1909,6 @@ public class TestSQLHandler extends AbstractFullDistribZkTestBase {
     return tuples;
   }
 
-  protected Tuple getTuple(TupleStream tupleStream) throws IOException {
-    tupleStream.open();
-    Tuple t = tupleStream.read();
-    tupleStream.close();
-    return t;
-  }
-
   public static SolrParams mapParams(String... vals) {
     ModifiableSolrParams params = new ModifiableSolrParams();
     assertEquals("Parameters passed in here must be in pairs!", 0, (vals.length % 2));
@@ -2543,25 +1919,11 @@ public class TestSQLHandler extends AbstractFullDistribZkTestBase {
     return params;
   }
 
-  public void assertResponseContains(SolrClient server, SolrParams requestParams, String json)
-      throws IOException, SolrServerException {
-    String p = requestParams.get("qt");
-    ModifiableSolrParams modifiableSolrParams = (ModifiableSolrParams) requestParams;
-    modifiableSolrParams.set("indent", modifiableSolrParams.get("indent", "off"));
-    if (p != null) {
-      modifiableSolrParams.remove("qt");
-    }
-
-    QueryRequest query = new QueryRequest(modifiableSolrParams);
-    query.setPath(p);
-    query.setResponseParser(new InputStreamResponseParser("json"));
-    query.setMethod(SolrRequest.METHOD.POST);
-    NamedList<Object> genericResponse = server.request(query);
-    InputStream stream = (InputStream) genericResponse.get("stream");
-    InputStreamReader reader = new InputStreamReader(stream, "UTF-8");
-    BufferedReader bufferedReader = new BufferedReader(reader);
-    String response = bufferedReader.readLine();
-    assertTrue(response.contains(json));
+  protected Tuple getTuple(TupleStream tupleStream) throws IOException {
+    tupleStream.open();
+    Tuple t = tupleStream.read();
+    tupleStream.close();
+    return t;
   }
 
 }