You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by bl...@apache.org on 2018/02/15 10:05:15 UTC

[1/4] cassandra git commit: Fix wildcard GROUP BY queries

Repository: cassandra
Updated Branches:
  refs/heads/cassandra-3.11 630c18eb3 -> 515f07b5a
  refs/heads/trunk 65440409b -> f74b0ea75


Fix wildcard GROUP BY queries

patch by Benjamin Lerer; reviewed by Andrés de la Peña for CASSANDRA-14209


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/515f07b5
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/515f07b5
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/515f07b5

Branch: refs/heads/cassandra-3.11
Commit: 515f07b5ac75b15015401e89c379b29c788ba5a3
Parents: 630c18e
Author: Benjamin Lerer <b....@gmail.com>
Authored: Thu Feb 15 10:59:28 2018 +0100
Committer: Benjamin Lerer <b....@gmail.com>
Committed: Thu Feb 15 10:59:28 2018 +0100

----------------------------------------------------------------------
 CHANGES.txt                                     |   1 +
 .../cassandra/cql3/selection/Selection.java     |  12 +
 .../cql3/statements/SelectStatement.java        |  21 +-
 .../cql3/validation/entities/JsonTest.java      |  25 ++
 .../operations/SelectGroupByTest.java           | 345 +++++++++++++++++++
 5 files changed, 401 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/515f07b5/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index fdf045d..e858781 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 3.11.3
+ * Fix wildcard GROUP BY queries (CASSANDRA-14209)
 Merged from 2.1
  * CVE-2017-5929 Security vulnerability in Logback warning in NEWS.txt (CASSANDRA-14183)
 

http://git-wip-us.apache.org/repos/asf/cassandra/blob/515f07b5/src/java/org/apache/cassandra/cql3/selection/Selection.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/selection/Selection.java b/src/java/org/apache/cassandra/cql3/selection/Selection.java
index 5e7c6e3..93a71b8 100644
--- a/src/java/org/apache/cassandra/cql3/selection/Selection.java
+++ b/src/java/org/apache/cassandra/cql3/selection/Selection.java
@@ -147,6 +147,18 @@ public abstract class Selection
         return new SimpleSelection(cfm, all, true);
     }
 
+    public static Selection wildcardWithGroupBy(CFMetaData cfm, VariableSpecifications boundNames)
+    {
+        List<RawSelector> rawSelectors = new ArrayList<>(cfm.allColumns().size());
+        Iterator<ColumnDefinition> iter = cfm.allColumnsInSelectOrder();
+        while (iter.hasNext())
+        {
+            ColumnDefinition.Raw raw = ColumnDefinition.Raw.forColumn(iter.next());
+            rawSelectors.add(new RawSelector(raw, null));
+        }
+        return fromSelectors(cfm, rawSelectors, boundNames, true);
+    }
+
     public static Selection forColumns(CFMetaData cfm, List<ColumnDefinition> columns)
     {
         return new SimpleSelection(cfm, columns, false);

http://git-wip-us.apache.org/repos/asf/cassandra/blob/515f07b5/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java b/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
index d86a47d..a7ba6aa 100644
--- a/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
@@ -958,9 +958,7 @@ public class SelectStatement implements CQLStatement
             CFMetaData cfm = ThriftValidation.validateColumnFamilyWithCompactMode(keyspace(), columnFamily(), clientState.isNoCompactMode());
             VariableSpecifications boundNames = getBoundVariables();
 
-            Selection selection = selectClause.isEmpty()
-                                  ? Selection.wildcard(cfm)
-                                  : Selection.fromSelectors(cfm, selectClause, boundNames, !parameters.groups.isEmpty());
+            Selection selection = prepareSelection(cfm, boundNames);
 
             StatementRestrictions restrictions = prepareRestrictions(cfm, boundNames, selection, forView);
 
@@ -1008,6 +1006,23 @@ public class SelectStatement implements CQLStatement
         }
 
         /**
+         * Prepares the selection to use for the statement.
+         *
+         * @param cfm the table metadata
+         * @param boundNames the bound names
+         * @return the selection to use for the statement
+         */
+        private Selection prepareSelection(CFMetaData cfm, VariableSpecifications boundNames)
+        {
+            boolean hasGroupBy = !parameters.groups.isEmpty();
+
+            if (selectClause.isEmpty())
+                return hasGroupBy ? Selection.wildcardWithGroupBy(cfm, boundNames) : Selection.wildcard(cfm);
+
+            return Selection.fromSelectors(cfm, selectClause, boundNames, hasGroupBy);
+        }
+
+        /**
          * Prepares the restrictions.
          *
          * @param cfm the column family meta data

http://git-wip-us.apache.org/repos/asf/cassandra/blob/515f07b5/test/unit/org/apache/cassandra/cql3/validation/entities/JsonTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/validation/entities/JsonTest.java b/test/unit/org/apache/cassandra/cql3/validation/entities/JsonTest.java
index 2bd95be..2728237 100644
--- a/test/unit/org/apache/cassandra/cql3/validation/entities/JsonTest.java
+++ b/test/unit/org/apache/cassandra/cql3/validation/entities/JsonTest.java
@@ -935,6 +935,31 @@ public class JsonTest extends CQLTester
     }
 
     @Test
+    public void testJsonWithGroupBy() throws Throwable
+    {
+        // tests SELECT JSON statements
+        createTable("CREATE TABLE %s (k int, c int, v int, PRIMARY KEY (k, c))");
+        execute("INSERT INTO %s (k, c, v) VALUES (0, 0, 0)");
+        execute("INSERT INTO %s (k, c, v) VALUES (0, 1, 1)");
+        execute("INSERT INTO %s (k, c, v) VALUES (1, 0, 1)");
+
+        assertRows(execute("SELECT JSON * FROM %s GROUP BY k"),
+                   row("{\"k\": 0, \"c\": 0, \"v\": 0}"),
+                   row("{\"k\": 1, \"c\": 0, \"v\": 1}")
+        );
+
+        assertRows(execute("SELECT JSON k, c, v FROM %s GROUP BY k"),
+                   row("{\"k\": 0, \"c\": 0, \"v\": 0}"),
+                   row("{\"k\": 1, \"c\": 0, \"v\": 1}")
+        );
+
+        assertRows(execute("SELECT JSON count(*) FROM %s GROUP BY k"),
+                row("{\"count\": 2}"),
+                row("{\"count\": 1}")
+        );
+    }
+
+    @Test
     public void testSelectJsonSyntax() throws Throwable
     {
         // tests SELECT JSON statements

http://git-wip-us.apache.org/repos/asf/cassandra/blob/515f07b5/test/unit/org/apache/cassandra/cql3/validation/operations/SelectGroupByTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/validation/operations/SelectGroupByTest.java b/test/unit/org/apache/cassandra/cql3/validation/operations/SelectGroupByTest.java
index b41b81f..5c51494 100644
--- a/test/unit/org/apache/cassandra/cql3/validation/operations/SelectGroupByTest.java
+++ b/test/unit/org/apache/cassandra/cql3/validation/operations/SelectGroupByTest.java
@@ -80,6 +80,22 @@ public class SelectGroupByTest extends CQLTester
                        row(2, 4, 3, 6),
                        row(4, 8, 2, 12));
 
+            // Range queries with wildcard
+            assertRows(execute("SELECT * FROM %s GROUP BY a, b, c"),
+                       row(1, 2, 1, 3, 6),
+                       row(1, 2, 2, 6, 12),
+                       row(1, 4, 2, 6, 12),
+                       row(2, 2, 3, 3, 6),
+                       row(2, 4, 3, 6, 12),
+                       row(4, 8, 2, 12, 24));
+
+            assertRows(execute("SELECT * FROM %s GROUP BY a, b"),
+                       row(1, 2, 1, 3, 6),
+                       row(1, 4, 2, 6, 12),
+                       row(2, 2, 3, 3, 6),
+                       row(2, 4, 3, 6, 12),
+                       row(4, 8, 2, 12, 24));
+
             // Range query with LIMIT
             assertRows(execute("SELECT a, b, e, count(b), max(e) FROM %s GROUP BY a, b LIMIT 2"),
                        row(1, 2, 6, 2L, 12),
@@ -117,6 +133,17 @@ public class SelectGroupByTest extends CQLTester
                        row(1, 4, 2, 6),
                        row(2, 2, 3, 3));
 
+            // Range queries with wildcard and with LIMIT
+            assertRows(execute("SELECT * FROM %s GROUP BY a, b, c LIMIT 3"),
+                       row(1, 2, 1, 3, 6),
+                       row(1, 2, 2, 6, 12),
+                       row(1, 4, 2, 6, 12));
+
+            assertRows(execute("SELECT * FROM %s GROUP BY a, b LIMIT 3"),
+                       row(1, 2, 1, 3, 6),
+                       row(1, 4, 2, 6, 12),
+                       row(2, 2, 3, 3, 6));
+
             // Range queries without aggregates and with PER PARTITION LIMIT
             assertRows(execute("SELECT a, b, c, d FROM %s GROUP BY a, b, c PER PARTITION LIMIT 2"),
                        row(1, 2, 1, 3),
@@ -130,12 +157,31 @@ public class SelectGroupByTest extends CQLTester
                        row(2, 2, 3, 3),
                        row(4, 8, 2, 12));
 
+            // Range queries with wildcard and with PER PARTITION LIMIT
+            assertRows(execute("SELECT * FROM %s GROUP BY a, b, c PER PARTITION LIMIT 2"),
+                       row(1, 2, 1, 3, 6),
+                       row(1, 2, 2, 6, 12),
+                       row(2, 2, 3, 3, 6),
+                       row(2, 4, 3, 6, 12),
+                       row(4, 8, 2, 12, 24));
+
+            assertRows(execute("SELECT * FROM %s GROUP BY a, b PER PARTITION LIMIT 1"),
+                       row(1, 2, 1, 3, 6),
+                       row(2, 2, 3, 3, 6),
+                       row(4, 8, 2, 12, 24));
+
             // Range queries without aggregates, with PER PARTITION LIMIT and LIMIT
             assertRows(execute("SELECT a, b, c, d FROM %s GROUP BY a, b, c PER PARTITION LIMIT 2 LIMIT 3"),
                        row(1, 2, 1, 3),
                        row(1, 2, 2, 6),
                        row(2, 2, 3, 3));
 
+            // Range queries with wildcard, with PER PARTITION LIMIT and LIMIT
+            assertRows(execute("SELECT * FROM %s GROUP BY a, b, c PER PARTITION LIMIT 2 LIMIT 3"),
+                       row(1, 2, 1, 3, 6),
+                       row(1, 2, 2, 6, 12),
+                       row(2, 2, 3, 3, 6));
+
             // Range query with DISTINCT
             assertRows(execute("SELECT DISTINCT a, count(a)FROM %s GROUP BY a"),
                        row(1, 1L),
@@ -200,6 +246,16 @@ public class SelectGroupByTest extends CQLTester
                        row(1, 2, 2, 6),
                        row(1, 4, 2, 6));
 
+            // Single partition queries with wildcard
+            assertRows(execute("SELECT * FROM %s WHERE a = 1 GROUP BY a, b, c"),
+                       row(1, 2, 1, 3, 6),
+                       row(1, 2, 2, 6, 12),
+                       row(1, 4, 2, 6, 12));
+
+            assertRows(execute("SELECT * FROM %s WHERE a = 1 GROUP BY a, b"),
+                       row(1, 2, 1, 3, 6),
+                       row(1, 4, 2, 6, 12));
+
             // Single partition queries with DISTINCT
             assertRows(execute("SELECT DISTINCT a, count(a)FROM %s WHERE a = 1 GROUP BY a"),
                        row(1, 1L));
@@ -245,6 +301,14 @@ public class SelectGroupByTest extends CQLTester
                        row(1, 2, 1, 3),
                        row(1, 2, 2, 6));
 
+            // Single partition queries with wildcard and with LIMIT
+            assertRows(execute("SELECT * FROM %s WHERE a = 1 GROUP BY a, b, c LIMIT 2"),
+                       row(1, 2, 1, 3, 6),
+                       row(1, 2, 2, 6, 12));
+
+            assertRows(execute("SELECT * FROM %s WHERE a = 1 GROUP BY a, b LIMIT 1"),
+                       row(1, 2, 1, 3, 6));
+
             // Single partition queries without aggregates and with PER PARTITION LIMIT
             assertRows(execute("SELECT a, b, c, d FROM %s WHERE a = 1 GROUP BY a, b PER PARTITION LIMIT 2"),
                        row(1, 2, 1, 3),
@@ -257,6 +321,14 @@ public class SelectGroupByTest extends CQLTester
                        row(1, 2, 1, 3),
                        row(1, 2, 2, 6));
 
+            // Single partition queries with wildcard and with PER PARTITION LIMIT
+            assertRows(execute("SELECT * FROM %s WHERE a = 1 GROUP BY a, b, c PER PARTITION LIMIT 2"),
+                       row(1, 2, 1, 3, 6),
+                       row(1, 2, 2, 6, 12));
+
+            assertRows(execute("SELECT * FROM %s WHERE a = 1 GROUP BY a, b PER PARTITION LIMIT 1"),
+                       row(1, 2, 1, 3, 6));
+
             // Single partition queries with ORDER BY
             assertRows(execute("SELECT a, b, e, count(b), max(e) FROM %s WHERE a = 1 GROUP BY a, b, c ORDER BY b DESC, c DESC"),
                        row(1, 4, 24, 2L, 24),
@@ -302,6 +374,22 @@ public class SelectGroupByTest extends CQLTester
                        row(2, 4, 3, 6),
                        row(4, 8, 2, 12));
 
+            // Multi-partitions with wildcard
+            assertRows(execute("SELECT * FROM %s WHERE a IN (1, 2, 4) GROUP BY a, b, c"),
+                       row(1, 2, 1, 3, 6),
+                       row(1, 2, 2, 6, 12),
+                       row(1, 4, 2, 6, 12),
+                       row(2, 2, 3, 3, 6),
+                       row(2, 4, 3, 6, 12),
+                       row(4, 8, 2, 12, 24));
+
+            assertRows(execute("SELECT * FROM %s WHERE a IN (1, 2, 4) GROUP BY a, b"),
+                       row(1, 2, 1, 3, 6),
+                       row(1, 4, 2, 6, 12),
+                       row(2, 2, 3, 3, 6),
+                       row(2, 4, 3, 6, 12),
+                       row(4, 8, 2, 12, 24));
+
             // Multi-partitions query with DISTINCT
             assertRows(execute("SELECT DISTINCT a, count(a)FROM %s WHERE a IN (1, 2, 4) GROUP BY a"),
                        row(1, 1L),
@@ -329,6 +417,19 @@ public class SelectGroupByTest extends CQLTester
                        row(2, 4, 12, 1L, 12),
                        row(4, 8, 24, 1L, 24));
 
+            // Multi-partitions with wildcard and PER PARTITION LIMIT
+            assertRows(execute("SELECT * FROM %s WHERE a IN (1, 2, 4) GROUP BY a, b, c PER PARTITION LIMIT 2"),
+                       row(1, 2, 1, 3, 6),
+                       row(1, 2, 2, 6, 12),
+                       row(2, 2, 3, 3, 6),
+                       row(2, 4, 3, 6, 12),
+                       row(4, 8, 2, 12, 24));
+
+            assertRows(execute("SELECT * FROM %s WHERE a IN (1, 2, 4) GROUP BY a, b PER PARTITION LIMIT 1"),
+                       row(1, 2, 1, 3, 6),
+                       row(2, 2, 3, 3, 6),
+                       row(4, 8, 2, 12, 24));
+
             // Multi-partitions queries with ORDER BY
             assertRows(execute("SELECT a, b, c, count(b), max(e) FROM %s WHERE a IN (1, 2, 4) GROUP BY a, b ORDER BY b DESC, c DESC"),
                        row(4, 8, 2, 1L, 24),
@@ -351,6 +452,12 @@ public class SelectGroupByTest extends CQLTester
                        row(2, 4, 3, 6),
                        row(1, 4, 2, 12));
 
+            // Multi-partitions with wildcard, ORDER BY and LIMIT
+            assertRows(execute("SELECT * FROM %s WHERE a IN (1, 2, 4) GROUP BY a, b, c ORDER BY b DESC, c DESC LIMIT 3"),
+                       row(4, 8, 2, 12, 24),
+                       row(2, 4, 3, 6, 12),
+                       row(1, 4, 2, 12, 24));
+
             // Invalid queries
             assertInvalidMessage("Group by is currently only supported on the columns of the PRIMARY KEY, got e",
                                  "SELECT a, b, d, count(b), max(c) FROM %s WHERE a = 1 GROUP BY a, e");
@@ -538,6 +645,12 @@ public class SelectGroupByTest extends CQLTester
                    row(2, null, 2),
                    row(4, null, 3));
 
+        // Range query with wildcard
+        assertRows(execute("SELECT * FROM %s GROUP BY a, b"),
+                   row(1, null, null, 1, null),
+                   row(2, null, null, 2, null),
+                   row(4, null, null, 3, null ));
+
         // Range query with LIMIT
         assertRows(execute("SELECT a, b, s, count(b), count(s) FROM %s GROUP BY a, b LIMIT 2"),
                    row(1, null, 1, 0L, 1L),
@@ -571,6 +684,10 @@ public class SelectGroupByTest extends CQLTester
         assertRows(execute("SELECT a, b, s FROM %s WHERE a = 1 GROUP BY a, b"),
                    row(1, null, 1));
 
+        // Single partition query with wildcard
+        assertRows(execute("SELECT * FROM %s WHERE a = 1 GROUP BY a, b"),
+                   row(1, null, null, 1, null));
+
         // Single partition query with LIMIT
         assertRows(execute("SELECT a, b, s, count(b), count(s) FROM %s WHERE a = 1 GROUP BY a, b LIMIT 2"),
                    row(1, null, 1, 0L, 1L));
@@ -600,6 +717,12 @@ public class SelectGroupByTest extends CQLTester
                    row(2, null, 2),
                    row(4, null, 3));
 
+        // Multi-partitions query with wildcard
+        assertRows(execute("SELECT * FROM %s WHERE a IN (1, 2, 3, 4) GROUP BY a, b"),
+                   row(1, null, null, 1, null),
+                   row(2, null, null, 2, null),
+                   row(4, null, null, 3, null ));
+
         // Multi-partitions query with LIMIT
         assertRows(execute("SELECT a, b, s, count(b), count(s) FROM %s WHERE a IN (1, 2, 3, 4) GROUP BY a, b LIMIT 2"),
                    row(1, null, 1, 0L, 1L),
@@ -676,6 +799,21 @@ public class SelectGroupByTest extends CQLTester
                    row(4, 8, null),
                    row(3, null, 3));
 
+        // Range queries with wildcard
+        assertRows(execute("SELECT * FROM %s GROUP BY a"),
+                   row(1, 2, 1, 1, 3),
+                   row(2, 2, 3, 2, 3),
+                   row(4, 8, 2, null, 12),
+                   row(3, null, null, 3, null));
+
+        assertRows(execute("SELECT * FROM %s GROUP BY a, b"),
+                   row(1, 2, 1, 1, 3),
+                   row(1, 4, 2, 1, 12),
+                   row(2, 2, 3, 2, 3),
+                   row(2, 4, 3, 2, 6),
+                   row(4, 8, 2, null, 12),
+                   row(3, null, null, 3, null));
+
         // Range query with LIMIT
         assertRows(execute("SELECT a, b, s, count(b), count(s) FROM %s GROUP BY a LIMIT 2"),
                    row(1, 2, 1, 4L, 4L),
@@ -707,6 +845,19 @@ public class SelectGroupByTest extends CQLTester
                    row(4, 8, null),
                    row(3, null, 3));
 
+        // Range queries with wildcard and with LIMIT
+        assertRows(execute("SELECT * FROM %s GROUP BY a LIMIT 2"),
+                   row(1, 2, 1, 1, 3),
+                   row(2, 2, 3, 2, 3));
+
+        assertRows(execute("SELECT * FROM %s GROUP BY a, b LIMIT 10"),
+                   row(1, 2, 1, 1, 3),
+                   row(1, 4, 2, 1, 12),
+                   row(2, 2, 3, 2, 3),
+                   row(2, 4, 3, 2, 6),
+                   row(4, 8, 2, null, 12),
+                   row(3, null, null, 3, null));
+
         // Range queries without aggregates and with PER PARTITION LIMIT
         assertRows(execute("SELECT a, b, s FROM %s GROUP BY a, b PER PARTITION LIMIT 1"),
                    row(1, 2, 1),
@@ -714,11 +865,23 @@ public class SelectGroupByTest extends CQLTester
                    row(4, 8, null),
                    row(3, null, 3));
 
+        // Range queries with wildcard and with PER PARTITION LIMIT
+        assertRows(execute("SELECT * FROM %s GROUP BY a, b PER PARTITION LIMIT 1"),
+                   row(1, 2, 1, 1, 3),
+                   row(2, 2, 3, 2, 3),
+                   row(4, 8, 2, null, 12),
+                   row(3, null, null, 3, null));
+
         // Range queries without aggregates, with PER PARTITION LIMIT and with LIMIT
         assertRows(execute("SELECT a, b, s FROM %s GROUP BY a, b PER PARTITION LIMIT 1 LIMIT 2"),
                    row(1, 2, 1),
                    row(2, 2, 2));
 
+        // Range queries with wildcard, PER PARTITION LIMIT and LIMIT
+        assertRows(execute("SELECT * FROM %s GROUP BY a, b PER PARTITION LIMIT 1 LIMIT 2"),
+                   row(1, 2, 1, 1, 3),
+                   row(2, 2, 3, 2, 3));
+
         // Range query with DISTINCT
         assertRows(execute("SELECT DISTINCT a, s, count(a), count(s) FROM %s GROUP BY a"),
                    row(1, 1, 1L, 1L),
@@ -752,6 +915,13 @@ public class SelectGroupByTest extends CQLTester
         assertRows(execute("SELECT a, b, s FROM %s WHERE a = 4 GROUP BY a, b"),
                    row(4, 8, null));
 
+        // Single partition queries with wildcard
+        assertRows(execute("SELECT * FROM %s WHERE a = 1 GROUP BY a"),
+                   row(1, 2, 1, 1, 3));
+
+        assertRows(execute("SELECT * FROM %s WHERE a = 4 GROUP BY a, b"),
+                   row(4, 8, 2, null, 12));
+
         // Single partition query with LIMIT
         assertRows(execute("SELECT a, b, s, count(b), count(s) FROM %s WHERE a = 2 GROUP BY a, b LIMIT 1"),
                    row(2, 2, 2, 1L, 1L));
@@ -822,6 +992,21 @@ public class SelectGroupByTest extends CQLTester
                    row(3, null, 3),
                    row(4, 8, null));
 
+        // Multi-partitions queries with wildcard
+        assertRows(execute("SELECT * FROM %s WHERE a IN (1, 2, 3, 4) GROUP BY a"),
+                   row(1, 2, 1, 1, 3),
+                   row(2, 2, 3, 2, 3),
+                   row(3, null, null, 3, null),
+                   row(4, 8, 2, null, 12));
+
+        assertRows(execute("SELECT * FROM %s WHERE a IN (1, 2, 3, 4) GROUP BY a, b"),
+                   row(1, 2, 1, 1, 3),
+                   row(1, 4, 2, 1, 12),
+                   row(2, 2, 3, 2, 3),
+                   row(2, 4, 3, 2, 6),
+                   row(3, null, null, 3, null),
+                   row(4, 8, 2, null, 12));
+
         // Multi-partitions query with LIMIT
         assertRows(execute("SELECT a, b, s, count(b), count(s) FROM %s WHERE a IN (1, 2, 3, 4) GROUP BY a LIMIT 2"),
                    row(1, 2, 1, 4L, 4L),
@@ -957,6 +1142,22 @@ public class SelectGroupByTest extends CQLTester
                               row(2, 4, 3, 6),
                               row(4, 8, 2, 12));
 
+                // Range queries with wildcard
+                assertRowsNet(executeNetWithPaging("SELECT * FROM %s GROUP BY a, b, c", pageSize),
+                              row(1, 2, 1, 3, 6),
+                              row(1, 2, 2, 6, 12),
+                              row(1, 4, 2, 6, 12),
+                              row(2, 2, 3, 3, 6),
+                              row(2, 4, 3, 6, 12),
+                              row(4, 8, 2, 12, 24));
+
+                assertRowsNet(executeNetWithPaging("SELECT * FROM %s GROUP BY a, b", pageSize),
+                              row(1, 2, 1, 3, 6),
+                              row(1, 4, 2, 6, 12),
+                              row(2, 2, 3, 3, 6),
+                              row(2, 4, 3, 6, 12),
+                              row(4, 8, 2, 12, 24));
+
                 // Range query with LIMIT
                 assertRowsNet(executeNetWithPaging("SELECT a, b, e, count(b), max(e) FROM %s GROUP BY a, b LIMIT 2",
                                                    pageSize),
@@ -993,6 +1194,30 @@ public class SelectGroupByTest extends CQLTester
                               row(2, 4, 3, 6),
                               row(4, 8, 2, 12));
 
+                // Range queries with wildcard and with LIMIT
+                assertRowsNet(executeNetWithPaging("SELECT * FROM %s GROUP BY a, b, c LIMIT 3", pageSize),
+                              row(1, 2, 1, 3, 6),
+                              row(1, 2, 2, 6, 12),
+                              row(1, 4, 2, 6, 12));
+
+                assertRowsNet(executeNetWithPaging("SELECT * FROM %s GROUP BY a, b LIMIT 3", pageSize),
+                              row(1, 2, 1, 3, 6),
+                              row(1, 4, 2, 6, 12),
+                              row(2, 2, 3, 3, 6));
+
+                // Range queries with wildcard and with PER PARTITION LIMIT
+                assertRowsNet(executeNetWithPaging("SELECT * FROM %s GROUP BY a, b, c PER PARTITION LIMIT 2", pageSize),
+                              row(1, 2, 1, 3, 6),
+                              row(1, 2, 2, 6, 12),
+                              row(2, 2, 3, 3, 6),
+                              row(2, 4, 3, 6, 12),
+                              row(4, 8, 2, 12, 24));
+
+                assertRowsNet(executeNetWithPaging("SELECT * FROM %s GROUP BY a, b PER PARTITION LIMIT 1", pageSize),
+                              row(1, 2, 1, 3, 6),
+                              row(2, 2, 3, 3, 6),
+                              row(4, 8, 2, 12, 24));
+
                 // Range queries without aggregates and with LIMIT
                 assertRowsNet(executeNetWithPaging("SELECT a, b, c, d FROM %s GROUP BY a, b, c LIMIT 3", pageSize),
                               row(1, 2, 1, 3),
@@ -1010,6 +1235,12 @@ public class SelectGroupByTest extends CQLTester
                               row(1, 2, 2, 6),
                               row(2, 2, 3, 3));
 
+                // Range queries with wildcard, with PER PARTITION LIMIT and LIMIT
+                assertRowsNet(executeNetWithPaging("SELECT * FROM %s GROUP BY a, b, c PER PARTITION LIMIT 2 LIMIT 3", pageSize),
+                              row(1, 2, 1, 3, 6),
+                              row(1, 2, 2, 6, 12),
+                              row(2, 2, 3, 3, 6));
+
                 // Range query with DISTINCT
                 assertRowsNet(executeNetWithPaging("SELECT DISTINCT a, count(a)FROM %s GROUP BY a", pageSize),
                               row(1, 1L),
@@ -1060,6 +1291,16 @@ public class SelectGroupByTest extends CQLTester
                               row(1, 2, 2, 6),
                               row(1, 4, 2, 6));
 
+                // Single partition queries with wildcard
+                assertRowsNet(executeNetWithPaging("SELECT * FROM %s WHERE a = 1 GROUP BY a, b, c", pageSize),
+                           row(1, 2, 1, 3, 6),
+                           row(1, 2, 2, 6, 12),
+                           row(1, 4, 2, 6, 12));
+
+                assertRowsNet(executeNetWithPaging("SELECT * FROM %s WHERE a = 1 GROUP BY a, b", pageSize),
+                           row(1, 2, 1, 3, 6),
+                           row(1, 4, 2, 6, 12));
+
                 // Single partition query with DISTINCT
                 assertRowsNet(executeNetWithPaging("SELECT DISTINCT a, count(a)FROM %s WHERE a = 1 GROUP BY a",
                                                    pageSize),
@@ -1089,6 +1330,22 @@ public class SelectGroupByTest extends CQLTester
                                                    pageSize),
                               row(1L, 6));
 
+                // Single partition queries with wildcard and with LIMIT
+                assertRowsNet(executeNetWithPaging("SELECT * FROM %s WHERE a = 1 GROUP BY a, b, c LIMIT 2", pageSize),
+                           row(1, 2, 1, 3, 6),
+                           row(1, 2, 2, 6, 12));
+
+                assertRowsNet(executeNetWithPaging("SELECT * FROM %s WHERE a = 1 GROUP BY a, b LIMIT 1", pageSize),
+                           row(1, 2, 1, 3, 6));
+
+                // Single partition queries with wildcard and with PER PARTITION LIMIT
+                assertRowsNet(executeNetWithPaging("SELECT * FROM %s WHERE a = 1 GROUP BY a, b, c PER PARTITION LIMIT 2", pageSize),
+                           row(1, 2, 1, 3, 6),
+                           row(1, 2, 2, 6, 12));
+
+                assertRowsNet(executeNetWithPaging("SELECT * FROM %s WHERE a = 1 GROUP BY a, b PER PARTITION LIMIT 1", pageSize),
+                           row(1, 2, 1, 3, 6));
+
                 // Single partition query with PER PARTITION LIMIT
                 assertRowsNet(executeNetWithPaging("SELECT a, b, e, count(b), max(e) FROM %s WHERE a = 1 GROUP BY a, b, c PER PARTITION LIMIT 2",
                                                    pageSize),
@@ -1194,6 +1451,22 @@ public class SelectGroupByTest extends CQLTester
                               row(2, 4, 3, 6),
                               row(4, 8, 2, 12));
 
+                // Multi-partitions with wildcard
+                assertRowsNet(executeNetWithPaging("SELECT * FROM %s WHERE a IN (1, 2, 4) GROUP BY a, b, c", pageSize),
+                           row(1, 2, 1, 3, 6),
+                           row(1, 2, 2, 6, 12),
+                           row(1, 4, 2, 6, 12),
+                           row(2, 2, 3, 3, 6),
+                           row(2, 4, 3, 6, 12),
+                           row(4, 8, 2, 12, 24));
+
+                assertRowsNet(executeNetWithPaging("SELECT * FROM %s WHERE a IN (1, 2, 4) GROUP BY a, b", pageSize),
+                           row(1, 2, 1, 3, 6),
+                           row(1, 4, 2, 6, 12),
+                           row(2, 2, 3, 3, 6),
+                           row(2, 4, 3, 6, 12),
+                           row(4, 8, 2, 12, 24));
+
                 // Multi-partitions queries with DISTINCT
                 assertRowsNet(executeNetWithPaging("SELECT DISTINCT a, count(a)FROM %s WHERE a IN (1, 2, 4) GROUP BY a",
                                                    pageSize),
@@ -1329,6 +1602,12 @@ public class SelectGroupByTest extends CQLTester
                           row(2, null, 2),
                           row(4, null, 3));
 
+            // Range query with wildcard
+            assertRowsNet(executeNetWithPaging("SELECT * FROM %s GROUP BY a, b", pageSize),
+                       row(1, null, null, 1, null),
+                       row(2, null, null, 2, null),
+                       row(4, null, null, 3, null ));
+
             // Range query with LIMIT
             assertRowsNet(executeNetWithPaging("SELECT a, b, s, count(b), count(s) FROM %s GROUP BY a, b LIMIT 2",
                                                pageSize),
@@ -1382,6 +1661,10 @@ public class SelectGroupByTest extends CQLTester
             assertRowsNet(executeNetWithPaging("SELECT a, b, s FROM %s WHERE a = 1 GROUP BY a, b", pageSize),
                           row(1, null, 1));
 
+            // Single partition query with wildcard
+            assertRowsNet(executeNetWithPaging("SELECT * FROM %s WHERE a = 1 GROUP BY a, b", pageSize),
+                       row(1, null, null, 1, null));
+
             // Single partition queries with LIMIT
             assertRowsNet(executeNetWithPaging("SELECT a, b, s, count(b), count(s) FROM %s WHERE a = 1 GROUP BY a, b LIMIT 2",
                                                pageSize),
@@ -1533,6 +1816,21 @@ public class SelectGroupByTest extends CQLTester
                           row(4, 8, null),
                           row(3, null, 3));
 
+            // Range queries with wildcard
+            assertRowsNet(executeNetWithPaging("SELECT * FROM %s GROUP BY a", pageSize),
+                       row(1, 2, 1, 1, 3),
+                       row(2, 2, 3, 2, 3),
+                       row(4, 8, 2, null, 12),
+                       row(3, null, null, 3, null));
+
+            assertRowsNet(executeNetWithPaging("SELECT * FROM %s GROUP BY a, b", pageSize),
+                       row(1, 2, 1, 1, 3),
+                       row(1, 4, 2, 1, 12),
+                       row(2, 2, 3, 2, 3),
+                       row(2, 4, 3, 2, 6),
+                       row(4, 8, 2, null, 12),
+                       row(3, null, null, 3, null));
+
             // Range query with LIMIT
             assertRowsNet(executeNetWithPaging("SELECT a, b, s, count(b), count(s) FROM %s GROUP BY a LIMIT 2",
                                                pageSize),
@@ -1555,6 +1853,19 @@ public class SelectGroupByTest extends CQLTester
                           row(4, 8, null),
                           row(3, null, 3));
 
+            // Range queries with wildcard and with LIMIT
+            assertRowsNet(executeNetWithPaging("SELECT * FROM %s GROUP BY a LIMIT 2", pageSize),
+                       row(1, 2, 1, 1, 3),
+                       row(2, 2, 3, 2, 3));
+
+            assertRowsNet(executeNetWithPaging("SELECT * FROM %s GROUP BY a, b LIMIT 10", pageSize),
+                       row(1, 2, 1, 1, 3),
+                       row(1, 4, 2, 1, 12),
+                       row(2, 2, 3, 2, 3),
+                       row(2, 4, 3, 2, 6),
+                       row(4, 8, 2, null, 12),
+                       row(3, null, null, 3, null));
+
             // Range queries with PER PARTITION LIMIT
             assertRowsNet(executeNetWithPaging("SELECT a, b, s, count(b), count(s) FROM %s GROUP BY a, b PER PARTITION LIMIT 2", pageSize),
                           row(1, 2, 1, 2L, 2L),
@@ -1570,6 +1881,13 @@ public class SelectGroupByTest extends CQLTester
                           row(4, 8, null, 1L, 0L),
                           row(3, null, 3, 0L, 1L));
 
+            // Range queries with wildcard and PER PARTITION LIMIT
+            assertRowsNet(executeNetWithPaging("SELECT * FROM %s GROUP BY a, b PER PARTITION LIMIT 1", pageSize),
+                       row(1, 2, 1, 1, 3),
+                       row(2, 2, 3, 2, 3),
+                       row(4, 8, 2, null, 12),
+                       row(3, null, null, 3, null));
+
             // Range queries with PER PARTITION LIMIT and LIMIT
             assertRowsNet(executeNetWithPaging("SELECT a, b, s, count(b), count(s) FROM %s GROUP BY a, b PER PARTITION LIMIT 2 LIMIT 3", pageSize),
                           row(1, 2, 1, 2L, 2L),
@@ -1581,6 +1899,11 @@ public class SelectGroupByTest extends CQLTester
                           row(2, 2, 2, 1L, 1L),
                           row(4, 8, null, 1L, 0L));
 
+            // Range queries with wildcard, PER PARTITION LIMIT and LIMIT
+            assertRowsNet(executeNetWithPaging("SELECT * FROM %s GROUP BY a, b PER PARTITION LIMIT 1 LIMIT 2", pageSize),
+                       row(1, 2, 1, 1, 3),
+                       row(2, 2, 3, 2, 3));
+
             // Range query without aggregates and with PER PARTITION LIMIT
             assertRowsNet(executeNetWithPaging("SELECT a, b, s FROM %s GROUP BY a, b PER PARTITION LIMIT 1", pageSize),
                           row(1, 2, 1),
@@ -1635,6 +1958,13 @@ public class SelectGroupByTest extends CQLTester
             assertRowsNet(executeNetWithPaging("SELECT a, b, s FROM %s WHERE a = 4 GROUP BY a, b", pageSize),
                           row(4, 8, null));
 
+            // Single partition queries with wildcard
+            assertRowsNet(executeNetWithPaging("SELECT * FROM %s WHERE a = 1 GROUP BY a", pageSize),
+                       row(1, 2, 1, 1, 3));
+
+            assertRowsNet(executeNetWithPaging("SELECT * FROM %s WHERE a = 4 GROUP BY a, b", pageSize),
+                       row(4, 8, 2, null, 12));
+
             // Single partition queries with LIMIT
             assertRowsNet(executeNetWithPaging("SELECT a, b, s, count(b), count(s) FROM %s WHERE a = 2 GROUP BY a, b LIMIT 1",
                                                pageSize),
@@ -1726,6 +2056,21 @@ public class SelectGroupByTest extends CQLTester
                           row(3, null, 3),
                           row(4, 8, null));
 
+            // Multi-partitions queries with wildcard
+            assertRowsNet(executeNetWithPaging("SELECT * FROM %s WHERE a IN (1, 2, 3, 4) GROUP BY a", pageSize),
+                       row(1, 2, 1, 1, 3),
+                       row(2, 2, 3, 2, 3),
+                       row(3, null, null, 3, null),
+                       row(4, 8, 2, null, 12));
+
+            assertRowsNet(executeNetWithPaging("SELECT * FROM %s WHERE a IN (1, 2, 3, 4) GROUP BY a, b", pageSize),
+                       row(1, 2, 1, 1, 3),
+                       row(1, 4, 2, 1, 12),
+                       row(2, 2, 3, 2, 3),
+                       row(2, 4, 3, 2, 6),
+                       row(3, null, null, 3, null),
+                       row(4, 8, 2, null, 12));
+
             // Multi-partitions queries with LIMIT
             assertRowsNet(executeNetWithPaging("SELECT a, b, s, count(b), count(s) FROM %s WHERE a IN (1, 2, 3, 4) GROUP BY a LIMIT 2",
                                                pageSize),


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org
For additional commands, e-mail: commits-help@cassandra.apache.org


[3/4] cassandra git commit: Merge branch cassandra-3.11 into trunk

Posted by bl...@apache.org.
http://git-wip-us.apache.org/repos/asf/cassandra/blob/f74b0ea7/test/unit/org/apache/cassandra/cql3/validation/operations/SelectGroupByTest.java
----------------------------------------------------------------------
diff --cc test/unit/org/apache/cassandra/cql3/validation/operations/SelectGroupByTest.java
index c941070,5c51494..17d06ac
--- a/test/unit/org/apache/cassandra/cql3/validation/operations/SelectGroupByTest.java
+++ b/test/unit/org/apache/cassandra/cql3/validation/operations/SelectGroupByTest.java
@@@ -26,378 -26,489 +26,485 @@@ public class SelectGroupByTest extends 
      @Test
      public void testGroupByWithoutPaging() throws Throwable
      {
 -        for (String compactOption : new String[] { "", " WITH COMPACT STORAGE" })
 -        {
 -            createTable("CREATE TABLE %s (a int, b int, c int, d int, e int, primary key (a, b, c, d))"
 -                    + compactOption);
 -
 -            execute("INSERT INTO %s (a, b, c, d, e) VALUES (1, 2, 1, 3, 6)");
 -            execute("INSERT INTO %s (a, b, c, d, e) VALUES (1, 2, 2, 6, 12)");
 -            execute("INSERT INTO %s (a, b, c, d, e) VALUES (1, 3, 2, 12, 24)");
 -            execute("INSERT INTO %s (a, b, c, d, e) VALUES (1, 4, 2, 12, 24)");
 -            execute("INSERT INTO %s (a, b, c, d, e) VALUES (1, 4, 2, 6, 12)");
 -            execute("INSERT INTO %s (a, b, c, d, e) VALUES (2, 2, 3, 3, 6)");
 -            execute("INSERT INTO %s (a, b, c, d, e) VALUES (2, 4, 3, 6, 12)");
 -            execute("INSERT INTO %s (a, b, c, d, e) VALUES (3, 3, 2, 12, 24)");
 -            execute("INSERT INTO %s (a, b, c, d, e) VALUES (4, 8, 2, 12, 24)");
 -
 -            // Makes sure that we have some tombstones
 -            execute("DELETE FROM %s WHERE a = 1 AND b = 3 AND c = 2 AND d = 12");
 -            execute("DELETE FROM %s WHERE a = 3");
 -
 -            // Range queries
 -            assertRows(execute("SELECT a, b, e, count(b), max(e) FROM %s GROUP BY a"),
 -                       row(1, 2, 6, 4L, 24),
 -                       row(2, 2, 6, 2L, 12),
 -                       row(4, 8, 24, 1L, 24));
 -
 -            assertRows(execute("SELECT a, b, e, count(b), max(e) FROM %s GROUP BY a, b"),
 -                       row(1, 2, 6, 2L, 12),
 -                       row(1, 4, 12, 2L, 24),
 -                       row(2, 2, 6, 1L, 6),
 -                       row(2, 4, 12, 1L, 12),
 -                       row(4, 8, 24, 1L, 24));
 -
 -            assertRows(execute("SELECT a, b, e, count(b), max(e) FROM %s WHERE b = 2 GROUP BY a, b ALLOW FILTERING"),
 -                       row(1, 2, 6, 2L, 12),
 -                       row(2, 2, 6, 1L, 6));
 -
 -            assertEmpty(execute("SELECT a, b, e, count(b), max(e) FROM %s WHERE b IN () GROUP BY a, b ALLOW FILTERING"));
 -
 -            // Range queries without aggregates
 -            assertRows(execute("SELECT a, b, c, d FROM %s GROUP BY a, b, c"),
 -                       row(1, 2, 1, 3),
 -                       row(1, 2, 2, 6),
 -                       row(1, 4, 2, 6),
 -                       row(2, 2, 3, 3),
 -                       row(2, 4, 3, 6),
 -                       row(4, 8, 2, 12));
 -
 -            assertRows(execute("SELECT a, b, c, d FROM %s GROUP BY a, b"),
 -                       row(1, 2, 1, 3),
 -                       row(1, 4, 2, 6),
 -                       row(2, 2, 3, 3),
 -                       row(2, 4, 3, 6),
 -                       row(4, 8, 2, 12));
 -
 -            // Range queries with wildcard
 -            assertRows(execute("SELECT * FROM %s GROUP BY a, b, c"),
 -                       row(1, 2, 1, 3, 6),
 -                       row(1, 2, 2, 6, 12),
 -                       row(1, 4, 2, 6, 12),
 -                       row(2, 2, 3, 3, 6),
 -                       row(2, 4, 3, 6, 12),
 -                       row(4, 8, 2, 12, 24));
 -
 -            assertRows(execute("SELECT * FROM %s GROUP BY a, b"),
 -                       row(1, 2, 1, 3, 6),
 -                       row(1, 4, 2, 6, 12),
 -                       row(2, 2, 3, 3, 6),
 -                       row(2, 4, 3, 6, 12),
 -                       row(4, 8, 2, 12, 24));
 -
 -            // Range query with LIMIT
 -            assertRows(execute("SELECT a, b, e, count(b), max(e) FROM %s GROUP BY a, b LIMIT 2"),
 -                       row(1, 2, 6, 2L, 12),
 -                       row(1, 4, 12, 2L, 24));
 -
 -            // Range queries with PER PARTITION LIMIT
 -            assertRows(execute("SELECT a, b, e, count(b), max(e) FROM %s GROUP BY a, b PER PARTITION LIMIT 1"),
 -                       row(1, 2, 6, 2L, 12),
 -                       row(2, 2, 6, 1L, 6),
 -                       row(4, 8, 24, 1L, 24));
 -
 -            assertRows(execute("SELECT a, b, e, count(b), max(e) FROM %s GROUP BY a PER PARTITION LIMIT 2"),
 -                       row(1, 2, 6, 4L, 24),
 -                       row(2, 2, 6, 2L, 12),
 -                       row(4, 8, 24, 1L, 24));
 -
 -            // Range query with PER PARTITION LIMIT and LIMIT
 -            assertRows(execute("SELECT a, b, e, count(b), max(e) FROM %s GROUP BY a, b PER PARTITION LIMIT 1 LIMIT 2"),
 -                       row(1, 2, 6, 2L, 12),
 -                       row(2, 2, 6, 1L, 6));
 -
 -            assertRows(execute("SELECT a, b, e, count(b), max(e) FROM %s GROUP BY a PER PARTITION LIMIT 2"),
 -                       row(1, 2, 6, 4L, 24),
 -                       row(2, 2, 6, 2L, 12),
 -                       row(4, 8, 24, 1L, 24));
 -
 -            // Range queries without aggregates and with LIMIT
 -            assertRows(execute("SELECT a, b, c, d FROM %s GROUP BY a, b, c LIMIT 3"),
 -                       row(1, 2, 1, 3),
 -                       row(1, 2, 2, 6),
 -                       row(1, 4, 2, 6));
 -
 -            assertRows(execute("SELECT a, b, c, d FROM %s GROUP BY a, b LIMIT 3"),
 -                       row(1, 2, 1, 3),
 -                       row(1, 4, 2, 6),
 -                       row(2, 2, 3, 3));
 -
 -            // Range queries with wildcard and with LIMIT
 -            assertRows(execute("SELECT * FROM %s GROUP BY a, b, c LIMIT 3"),
 -                       row(1, 2, 1, 3, 6),
 -                       row(1, 2, 2, 6, 12),
 -                       row(1, 4, 2, 6, 12));
 +        createTable("CREATE TABLE %s (a int, b int, c int, d int, e int, primary key (a, b, c, d))");
 +
 +        execute("INSERT INTO %s (a, b, c, d, e) VALUES (1, 2, 1, 3, 6)");
 +        execute("INSERT INTO %s (a, b, c, d, e) VALUES (1, 2, 2, 6, 12)");
 +        execute("INSERT INTO %s (a, b, c, d, e) VALUES (1, 3, 2, 12, 24)");
 +        execute("INSERT INTO %s (a, b, c, d, e) VALUES (1, 4, 2, 12, 24)");
 +        execute("INSERT INTO %s (a, b, c, d, e) VALUES (1, 4, 2, 6, 12)");
 +        execute("INSERT INTO %s (a, b, c, d, e) VALUES (2, 2, 3, 3, 6)");
 +        execute("INSERT INTO %s (a, b, c, d, e) VALUES (2, 4, 3, 6, 12)");
 +        execute("INSERT INTO %s (a, b, c, d, e) VALUES (3, 3, 2, 12, 24)");
 +        execute("INSERT INTO %s (a, b, c, d, e) VALUES (4, 8, 2, 12, 24)");
  
 -            assertRows(execute("SELECT * FROM %s GROUP BY a, b LIMIT 3"),
 -                       row(1, 2, 1, 3, 6),
 -                       row(1, 4, 2, 6, 12),
 -                       row(2, 2, 3, 3, 6));
 -
 -            // Range queries without aggregates and with PER PARTITION LIMIT
 -            assertRows(execute("SELECT a, b, c, d FROM %s GROUP BY a, b, c PER PARTITION LIMIT 2"),
 -                       row(1, 2, 1, 3),
 -                       row(1, 2, 2, 6),
 -                       row(2, 2, 3, 3),
 -                       row(2, 4, 3, 6),
 -                       row(4, 8, 2, 12));
 -
 -            assertRows(execute("SELECT a, b, c, d FROM %s GROUP BY a, b PER PARTITION LIMIT 1"),
 -                       row(1, 2, 1, 3),
 -                       row(2, 2, 3, 3),
 -                       row(4, 8, 2, 12));
 -
 -            // Range queries with wildcard and with PER PARTITION LIMIT
 -            assertRows(execute("SELECT * FROM %s GROUP BY a, b, c PER PARTITION LIMIT 2"),
 -                       row(1, 2, 1, 3, 6),
 -                       row(1, 2, 2, 6, 12),
 -                       row(2, 2, 3, 3, 6),
 -                       row(2, 4, 3, 6, 12),
 -                       row(4, 8, 2, 12, 24));
 -
 -            assertRows(execute("SELECT * FROM %s GROUP BY a, b PER PARTITION LIMIT 1"),
 -                       row(1, 2, 1, 3, 6),
 -                       row(2, 2, 3, 3, 6),
 -                       row(4, 8, 2, 12, 24));
 -
 -            // Range queries without aggregates, with PER PARTITION LIMIT and LIMIT
 -            assertRows(execute("SELECT a, b, c, d FROM %s GROUP BY a, b, c PER PARTITION LIMIT 2 LIMIT 3"),
 -                       row(1, 2, 1, 3),
 -                       row(1, 2, 2, 6),
 -                       row(2, 2, 3, 3));
 -
 -            // Range queries with wildcard, with PER PARTITION LIMIT and LIMIT
 -            assertRows(execute("SELECT * FROM %s GROUP BY a, b, c PER PARTITION LIMIT 2 LIMIT 3"),
 -                       row(1, 2, 1, 3, 6),
 -                       row(1, 2, 2, 6, 12),
 -                       row(2, 2, 3, 3, 6));
 -
 -            // Range query with DISTINCT
 -            assertRows(execute("SELECT DISTINCT a, count(a)FROM %s GROUP BY a"),
 -                       row(1, 1L),
 -                       row(2, 1L),
 -                       row(4, 1L));
 +        // Makes sure that we have some tombstones
 +        execute("DELETE FROM %s WHERE a = 1 AND b = 3 AND c = 2 AND d = 12");
 +        execute("DELETE FROM %s WHERE a = 3");
  
 -            assertInvalidMessage("Grouping on clustering columns is not allowed for SELECT DISTINCT queries",
 -                                 "SELECT DISTINCT a, count(a)FROM %s GROUP BY a, b");
 +        // Range queries
 +        assertRows(execute("SELECT a, b, e, count(b), max(e) FROM %s GROUP BY a"),
 +                   row(1, 2, 6, 4L, 24),
 +                   row(2, 2, 6, 2L, 12),
 +                   row(4, 8, 24, 1L, 24));
  
 -            // Range query with DISTINCT and LIMIT
 -            assertRows(execute("SELECT DISTINCT a, count(a)FROM %s GROUP BY a LIMIT 2"),
 -                       row(1, 1L),
 -                       row(2, 1L));
 +        assertRows(execute("SELECT a, b, e, count(b), max(e) FROM %s GROUP BY a, b"),
 +                   row(1, 2, 6, 2L, 12),
 +                   row(1, 4, 12, 2L, 24),
 +                   row(2, 2, 6, 1L, 6),
 +                   row(2, 4, 12, 1L, 12),
 +                   row(4, 8, 24, 1L, 24));
  
 -            assertInvalidMessage("Grouping on clustering columns is not allowed for SELECT DISTINCT queries",
 -                                 "SELECT DISTINCT a, count(a)FROM %s GROUP BY a, b LIMIT 2");
 +        assertRows(execute("SELECT a, b, e, count(b), max(e) FROM %s WHERE b = 2 GROUP BY a, b ALLOW FILTERING"),
 +                   row(1, 2, 6, 2L, 12),
 +                   row(2, 2, 6, 1L, 6));
  
 -            // Range query with ORDER BY
 -            assertInvalidMessage("ORDER BY is only supported when the partition key is restricted by an EQ or an IN",
 -                                 "SELECT a, b, c, count(b), max(e) FROM %s GROUP BY a, b ORDER BY b DESC, c DESC");
 +        assertEmpty(execute("SELECT a, b, e, count(b), max(e) FROM %s WHERE b IN () GROUP BY a, b ALLOW FILTERING"));
  
 -            // Single partition queries
 -            assertRows(execute("SELECT a, b, e, count(b), max(e) FROM %s WHERE a = 1 GROUP BY a, b, c"),
 -                       row(1, 2, 6, 1L, 6),
 -                       row(1, 2, 12, 1L, 12),
 -                       row(1, 4, 12, 2L, 24));
 +        // Range queries without aggregates
 +        assertRows(execute("SELECT a, b, c, d FROM %s GROUP BY a, b, c"),
 +                   row(1, 2, 1, 3),
 +                   row(1, 2, 2, 6),
 +                   row(1, 4, 2, 6),
 +                   row(2, 2, 3, 3),
 +                   row(2, 4, 3, 6),
 +                   row(4, 8, 2, 12));
 +
 +        assertRows(execute("SELECT a, b, c, d FROM %s GROUP BY a, b"),
 +                   row(1, 2, 1, 3),
 +                   row(1, 4, 2, 6),
 +                   row(2, 2, 3, 3),
 +                   row(2, 4, 3, 6),
 +                   row(4, 8, 2, 12));
  
 -            assertRows(execute("SELECT a, b, e, count(b), max(e) FROM %s WHERE a = 1 GROUP BY b, c"),
 -                       row(1, 2, 6, 1L, 6),
 -                       row(1, 2, 12, 1L, 12),
 -                       row(1, 4, 12, 2L, 24));
++        // Range queries with wildcard
++        assertRows(execute("SELECT * FROM %s GROUP BY a, b, c"),
++                   row(1, 2, 1, 3, 6),
++                   row(1, 2, 2, 6, 12),
++                   row(1, 4, 2, 6, 12),
++                   row(2, 2, 3, 3, 6),
++                   row(2, 4, 3, 6, 12),
++                   row(4, 8, 2, 12, 24));
+ 
 -            assertRows(execute("SELECT a, b, e, count(b), max(e) FROM %s WHERE a = 1 AND b = 2 GROUP BY a, b, c"),
 -                       row(1, 2, 6, 1L, 6),
 -                       row(1, 2, 12, 1L, 12));
++        assertRows(execute("SELECT * FROM %s GROUP BY a, b"),
++                   row(1, 2, 1, 3, 6),
++                   row(1, 4, 2, 6, 12),
++                   row(2, 2, 3, 3, 6),
++                   row(2, 4, 3, 6, 12),
++                   row(4, 8, 2, 12, 24));
+ 
 -            assertRows(execute("SELECT a, b, e, count(b), max(e) FROM %s WHERE a = 1 AND b = 2 GROUP BY a, c"),
 -                       row(1, 2, 6, 1L, 6),
 -                       row(1, 2, 12, 1L, 12));
 +        // Range query with LIMIT
 +        assertRows(execute("SELECT a, b, e, count(b), max(e) FROM %s GROUP BY a, b LIMIT 2"),
 +                   row(1, 2, 6, 2L, 12),
 +                   row(1, 4, 12, 2L, 24));
  
 -            assertRows(execute("SELECT a, b, e, count(b), max(e) FROM %s WHERE a = 1 AND b = 2 GROUP BY c"),
 -                       row(1, 2, 6, 1L, 6),
 -                       row(1, 2, 12, 1L, 12));
 +        // Range queries with PER PARTITION LIMIT
 +        assertRows(execute("SELECT a, b, e, count(b), max(e) FROM %s GROUP BY a, b PER PARTITION LIMIT 1"),
 +                   row(1, 2, 6, 2L, 12),
 +                   row(2, 2, 6, 1L, 6),
 +                   row(4, 8, 24, 1L, 24));
  
 -            // Single partition queries without aggregates
 -            assertRows(execute("SELECT a, b, c, d FROM %s WHERE a = 1 GROUP BY a, b"),
 -                       row(1, 2, 1, 3),
 -                       row(1, 4, 2, 6));
 +        assertRows(execute("SELECT a, b, e, count(b), max(e) FROM %s GROUP BY a PER PARTITION LIMIT 2"),
 +                   row(1, 2, 6, 4L, 24),
 +                   row(2, 2, 6, 2L, 12),
 +                   row(4, 8, 24, 1L, 24));
  
 -            assertRows(execute("SELECT a, b, c, d FROM %s WHERE a = 1 GROUP BY a, b, c"),
 -                       row(1, 2, 1, 3),
 -                       row(1, 2, 2, 6),
 -                       row(1, 4, 2, 6));
 +        // Range query with PER PARTITION LIMIT and LIMIT
 +        assertRows(execute("SELECT a, b, e, count(b), max(e) FROM %s GROUP BY a, b PER PARTITION LIMIT 1 LIMIT 2"),
 +                   row(1, 2, 6, 2L, 12),
 +                   row(2, 2, 6, 1L, 6));
  
 -            assertRows(execute("SELECT a, b, c, d FROM %s WHERE a = 1 GROUP BY b, c"),
 -                       row(1, 2, 1, 3),
 -                       row(1, 2, 2, 6),
 -                       row(1, 4, 2, 6));
 +        assertRows(execute("SELECT a, b, e, count(b), max(e) FROM %s GROUP BY a PER PARTITION LIMIT 2"),
 +                   row(1, 2, 6, 4L, 24),
 +                   row(2, 2, 6, 2L, 12),
 +                   row(4, 8, 24, 1L, 24));
  
 -            assertRows(execute("SELECT a, b, c, d FROM %s WHERE a = 1 and token(a) = token(1) GROUP BY b, c"),
 -                       row(1, 2, 1, 3),
 -                       row(1, 2, 2, 6),
 -                       row(1, 4, 2, 6));
 +        // Range queries without aggregates and with LIMIT
 +        assertRows(execute("SELECT a, b, c, d FROM %s GROUP BY a, b, c LIMIT 3"),
 +                   row(1, 2, 1, 3),
 +                   row(1, 2, 2, 6),
 +                   row(1, 4, 2, 6));
  
 -            // Single partition queries with wildcard
 -            assertRows(execute("SELECT * FROM %s WHERE a = 1 GROUP BY a, b, c"),
 -                       row(1, 2, 1, 3, 6),
 -                       row(1, 2, 2, 6, 12),
 -                       row(1, 4, 2, 6, 12));
 +        assertRows(execute("SELECT a, b, c, d FROM %s GROUP BY a, b LIMIT 3"),
 +                   row(1, 2, 1, 3),
 +                   row(1, 4, 2, 6),
 +                   row(2, 2, 3, 3));
  
 -            assertRows(execute("SELECT * FROM %s WHERE a = 1 GROUP BY a, b"),
 -                       row(1, 2, 1, 3, 6),
 -                       row(1, 4, 2, 6, 12));
++        // Range queries with wildcard and with LIMIT
++        assertRows(execute("SELECT * FROM %s GROUP BY a, b, c LIMIT 3"),
++                   row(1, 2, 1, 3, 6),
++                   row(1, 2, 2, 6, 12),
++                   row(1, 4, 2, 6, 12));
+ 
 -            // Single partition queries with DISTINCT
 -            assertRows(execute("SELECT DISTINCT a, count(a)FROM %s WHERE a = 1 GROUP BY a"),
 -                       row(1, 1L));
++        assertRows(execute("SELECT * FROM %s GROUP BY a, b LIMIT 3"),
++                   row(1, 2, 1, 3, 6),
++                   row(1, 4, 2, 6, 12),
++                   row(2, 2, 3, 3, 6));
+ 
 -            assertInvalidMessage("Grouping on clustering columns is not allowed for SELECT DISTINCT queries",
 -                                 "SELECT DISTINCT a, count(a)FROM %s WHERE a = 1 GROUP BY a, b");
 +        // Range queries without aggregates and with PER PARTITION LIMIT
 +        assertRows(execute("SELECT a, b, c, d FROM %s GROUP BY a, b, c PER PARTITION LIMIT 2"),
 +                   row(1, 2, 1, 3),
 +                   row(1, 2, 2, 6),
 +                   row(2, 2, 3, 3),
 +                   row(2, 4, 3, 6),
 +                   row(4, 8, 2, 12));
 +
 +        assertRows(execute("SELECT a, b, c, d FROM %s GROUP BY a, b PER PARTITION LIMIT 1"),
 +                   row(1, 2, 1, 3),
 +                   row(2, 2, 3, 3),
 +                   row(4, 8, 2, 12));
  
 -            // Single partition queries with LIMIT
 -            assertRows(execute("SELECT a, b, e, count(b), max(e) FROM %s WHERE a = 1 GROUP BY a, b, c LIMIT 10"),
 -                       row(1, 2, 6, 1L, 6),
 -                       row(1, 2, 12, 1L, 12),
 -                       row(1, 4, 12, 2L, 24));
++        // Range queries with wildcard and with PER PARTITION LIMIT
++        assertRows(execute("SELECT * FROM %s GROUP BY a, b, c PER PARTITION LIMIT 2"),
++                   row(1, 2, 1, 3, 6),
++                   row(1, 2, 2, 6, 12),
++                   row(2, 2, 3, 3, 6),
++                   row(2, 4, 3, 6, 12),
++                   row(4, 8, 2, 12, 24));
+ 
 -            assertRows(execute("SELECT a, b, e, count(b), max(e) FROM %s WHERE a = 1 GROUP BY a, b, c LIMIT 2"),
 -                       row(1, 2, 6, 1L, 6),
 -                       row(1, 2, 12, 1L, 12));
++        assertRows(execute("SELECT * FROM %s GROUP BY a, b PER PARTITION LIMIT 1"),
++                   row(1, 2, 1, 3, 6),
++                   row(2, 2, 3, 3, 6),
++                   row(4, 8, 2, 12, 24));
++
 +        // Range queries without aggregates, with PER PARTITION LIMIT and LIMIT
 +        assertRows(execute("SELECT a, b, c, d FROM %s GROUP BY a, b, c PER PARTITION LIMIT 2 LIMIT 3"),
 +                   row(1, 2, 1, 3),
 +                   row(1, 2, 2, 6),
 +                   row(2, 2, 3, 3));
 +
++        // Range queries with wildcard, with PER PARTITION LIMIT and LIMIT
++        assertRows(execute("SELECT * FROM %s GROUP BY a, b, c PER PARTITION LIMIT 2 LIMIT 3"),
++                   row(1, 2, 1, 3, 6),
++                   row(1, 2, 2, 6, 12),
++                   row(2, 2, 3, 3, 6));
+ 
 -            assertRows(execute("SELECT count(b), max(e) FROM %s WHERE a = 1 GROUP BY a, b, c LIMIT 1"),
 -                       row(1L, 6));
 +        // Range query with DISTINCT
 +        assertRows(execute("SELECT DISTINCT a, count(a)FROM %s GROUP BY a"),
 +                   row(1, 1L),
 +                   row(2, 1L),
 +                   row(4, 1L));
  
 -            // Single partition queries with PER PARTITION LIMIT
 -            assertRows(execute("SELECT a, b, e, count(b), max(e) FROM %s WHERE a = 1 GROUP BY a, b, c PER PARTITION LIMIT 10"),
 -                       row(1, 2, 6, 1L, 6),
 -                       row(1, 2, 12, 1L, 12),
 -                       row(1, 4, 12, 2L, 24));
 +        assertInvalidMessage("Grouping on clustering columns is not allowed for SELECT DISTINCT queries",
 +                             "SELECT DISTINCT a, count(a)FROM %s GROUP BY a, b");
  
 -            assertRows(execute("SELECT a, b, e, count(b), max(e) FROM %s WHERE a = 1 GROUP BY a, b, c PER PARTITION LIMIT 2"),
 -                       row(1, 2, 6, 1L, 6),
 -                       row(1, 2, 12, 1L, 12));
 +        // Range query with DISTINCT and LIMIT
 +        assertRows(execute("SELECT DISTINCT a, count(a)FROM %s GROUP BY a LIMIT 2"),
 +                   row(1, 1L),
 +                   row(2, 1L));
  
 -            assertRows(execute("SELECT count(b), max(e) FROM %s WHERE a = 1 GROUP BY a, b, c PER PARTITION LIMIT 1"),
 -                       row(1L, 6));
 +        assertInvalidMessage("Grouping on clustering columns is not allowed for SELECT DISTINCT queries",
 +                             "SELECT DISTINCT a, count(a)FROM %s GROUP BY a, b LIMIT 2");
  
 -            // Single partition queries without aggregates and with LIMIT
 -            assertRows(execute("SELECT a, b, c, d FROM %s WHERE a = 1 GROUP BY a, b LIMIT 2"),
 -                       row(1, 2, 1, 3),
 -                       row(1, 4, 2, 6));
 +        // Range query with ORDER BY
 +        assertInvalidMessage("ORDER BY is only supported when the partition key is restricted by an EQ or an IN",
 +                             "SELECT a, b, c, count(b), max(e) FROM %s GROUP BY a, b ORDER BY b DESC, c DESC");
  
 -            assertRows(execute("SELECT a, b, c, d FROM %s WHERE a = 1 GROUP BY a, b LIMIT 1"),
 -                       row(1, 2, 1, 3));
 +        // Single partition queries
 +        assertRows(execute("SELECT a, b, e, count(b), max(e) FROM %s WHERE a = 1 GROUP BY a, b, c"),
 +                   row(1, 2, 6, 1L, 6),
 +                   row(1, 2, 12, 1L, 12),
 +                   row(1, 4, 12, 2L, 24));
  
 -            assertRows(execute("SELECT a, b, c, d FROM %s WHERE a = 1 GROUP BY a, b, c LIMIT 2"),
 -                       row(1, 2, 1, 3),
 -                       row(1, 2, 2, 6));
 +        assertRows(execute("SELECT a, b, e, count(b), max(e) FROM %s WHERE a = 1 GROUP BY b, c"),
 +                   row(1, 2, 6, 1L, 6),
 +                   row(1, 2, 12, 1L, 12),
 +                   row(1, 4, 12, 2L, 24));
  
 -            // Single partition queries with wildcard and with LIMIT
 -            assertRows(execute("SELECT * FROM %s WHERE a = 1 GROUP BY a, b, c LIMIT 2"),
 -                       row(1, 2, 1, 3, 6),
 -                       row(1, 2, 2, 6, 12));
 +        assertRows(execute("SELECT a, b, e, count(b), max(e) FROM %s WHERE a = 1 AND b = 2 GROUP BY a, b, c"),
 +                   row(1, 2, 6, 1L, 6),
 +                   row(1, 2, 12, 1L, 12));
  
 -            assertRows(execute("SELECT * FROM %s WHERE a = 1 GROUP BY a, b LIMIT 1"),
 -                       row(1, 2, 1, 3, 6));
 +        assertRows(execute("SELECT a, b, e, count(b), max(e) FROM %s WHERE a = 1 AND b = 2 GROUP BY a, c"),
 +                   row(1, 2, 6, 1L, 6),
 +                   row(1, 2, 12, 1L, 12));
  
 -            // Single partition queries without aggregates and with PER PARTITION LIMIT
 -            assertRows(execute("SELECT a, b, c, d FROM %s WHERE a = 1 GROUP BY a, b PER PARTITION LIMIT 2"),
 -                       row(1, 2, 1, 3),
 -                       row(1, 4, 2, 6));
 +        assertRows(execute("SELECT a, b, e, count(b), max(e) FROM %s WHERE a = 1 AND b = 2 GROUP BY c"),
 +                   row(1, 2, 6, 1L, 6),
 +                   row(1, 2, 12, 1L, 12));
  
 -            assertRows(execute("SELECT a, b, c, d FROM %s WHERE a = 1 GROUP BY a, b PER PARTITION LIMIT 1"),
 -                       row(1, 2, 1, 3));
 +        // Single partition queries without aggregates
 +        assertRows(execute("SELECT a, b, c, d FROM %s WHERE a = 1 GROUP BY a, b"),
 +                   row(1, 2, 1, 3),
 +                   row(1, 4, 2, 6));
  
 -            assertRows(execute("SELECT a, b, c, d FROM %s WHERE a = 1 GROUP BY a, b, c PER PARTITION LIMIT 2"),
 -                       row(1, 2, 1, 3),
 -                       row(1, 2, 2, 6));
 +        assertRows(execute("SELECT a, b, c, d FROM %s WHERE a = 1 GROUP BY a, b, c"),
 +                   row(1, 2, 1, 3),
 +                   row(1, 2, 2, 6),
 +                   row(1, 4, 2, 6));
  
 -            // Single partition queries with wildcard and with PER PARTITION LIMIT
 -            assertRows(execute("SELECT * FROM %s WHERE a = 1 GROUP BY a, b, c PER PARTITION LIMIT 2"),
 -                       row(1, 2, 1, 3, 6),
 -                       row(1, 2, 2, 6, 12));
 +        assertRows(execute("SELECT a, b, c, d FROM %s WHERE a = 1 GROUP BY b, c"),
 +                   row(1, 2, 1, 3),
 +                   row(1, 2, 2, 6),
 +                   row(1, 4, 2, 6));
  
 -            assertRows(execute("SELECT * FROM %s WHERE a = 1 GROUP BY a, b PER PARTITION LIMIT 1"),
 -                       row(1, 2, 1, 3, 6));
 +        assertRows(execute("SELECT a, b, c, d FROM %s WHERE a = 1 and token(a) = token(1) GROUP BY b, c"),
 +                   row(1, 2, 1, 3),
 +                   row(1, 2, 2, 6),
 +                   row(1, 4, 2, 6));
  
 -            // Single partition queries with ORDER BY
 -            assertRows(execute("SELECT a, b, e, count(b), max(e) FROM %s WHERE a = 1 GROUP BY a, b, c ORDER BY b DESC, c DESC"),
 -                       row(1, 4, 24, 2L, 24),
 -                       row(1, 2, 12, 1L, 12),
 -                       row(1, 2, 6, 1L, 6));
++        // Single partition queries with wildcard
++        assertRows(execute("SELECT * FROM %s WHERE a = 1 GROUP BY a, b, c"),
++                   row(1, 2, 1, 3, 6),
++                   row(1, 2, 2, 6, 12),
++                   row(1, 4, 2, 6, 12));
+ 
 -            // Single partition queries with ORDER BY and PER PARTITION LIMIT
 -            assertRows(execute("SELECT a, b, e, count(b), max(e) FROM %s WHERE a = 1 GROUP BY a, b, c ORDER BY b DESC, c DESC PER PARTITION LIMIT 1"),
 -                       row(1, 4, 24, 2L, 24));
++        assertRows(execute("SELECT * FROM %s WHERE a = 1 GROUP BY a, b"),
++                   row(1, 2, 1, 3, 6),
++                   row(1, 4, 2, 6, 12));
+ 
 -            // Single partition queries with ORDER BY and LIMIT
 -            assertRows(execute("SELECT a, b, e, count(b), max(e) FROM %s WHERE a = 1 GROUP BY a, b, c ORDER BY b DESC, c DESC LIMIT 2"),
 -                       row(1, 4, 24, 2L, 24),
 -                       row(1, 2, 12, 1L, 12));
 +        // Single partition queries with DISTINCT
 +        assertRows(execute("SELECT DISTINCT a, count(a)FROM %s WHERE a = 1 GROUP BY a"),
 +                   row(1, 1L));
  
 -            // Multi-partitions queries
 -            assertRows(execute("SELECT a, b, e, count(b), max(e) FROM %s WHERE a IN (1, 2, 4) GROUP BY a, b, c"),
 -                       row(1, 2, 6, 1L, 6),
 -                       row(1, 2, 12, 1L, 12),
 -                       row(1, 4, 12, 2L, 24),
 -                       row(2, 2, 6, 1L, 6),
 -                       row(2, 4, 12, 1L, 12),
 -                       row(4, 8, 24, 1L, 24));
 -
 -            assertRows(execute("SELECT a, b, e, count(b), max(e) FROM %s WHERE a IN (1, 2, 4) AND b = 2 GROUP BY a, b, c"),
 -                       row(1, 2, 6, 1L, 6),
 -                       row(1, 2, 12, 1L, 12),
 -                       row(2, 2, 6, 1L, 6));
 +        assertInvalidMessage("Grouping on clustering columns is not allowed for SELECT DISTINCT queries",
 +                             "SELECT DISTINCT a, count(a)FROM %s WHERE a = 1 GROUP BY a, b");
  
 -            // Multi-partitions queries without aggregates
 -            assertRows(execute("SELECT a, b, c, d FROM %s WHERE a IN (1, 2, 4) GROUP BY a, b"),
 -                       row(1, 2, 1, 3),
 -                       row(1, 4, 2, 6),
 -                       row(2, 2, 3, 3),
 -                       row(2, 4, 3, 6),
 -                       row(4, 8, 2, 12));
 -
 -            assertRows(execute("SELECT a, b, c, d FROM %s WHERE a IN (1, 2, 4) GROUP BY a, b, c"),
 -                       row(1, 2, 1, 3),
 -                       row(1, 2, 2, 6),
 -                       row(1, 4, 2, 6),
 -                       row(2, 2, 3, 3),
 -                       row(2, 4, 3, 6),
 -                       row(4, 8, 2, 12));
 +        // Single partition queries with LIMIT
 +        assertRows(execute("SELECT a, b, e, count(b), max(e) FROM %s WHERE a = 1 GROUP BY a, b, c LIMIT 10"),
 +                   row(1, 2, 6, 1L, 6),
 +                   row(1, 2, 12, 1L, 12),
 +                   row(1, 4, 12, 2L, 24));
  
 -            // Multi-partitions with wildcard
 -            assertRows(execute("SELECT * FROM %s WHERE a IN (1, 2, 4) GROUP BY a, b, c"),
 -                       row(1, 2, 1, 3, 6),
 -                       row(1, 2, 2, 6, 12),
 -                       row(1, 4, 2, 6, 12),
 -                       row(2, 2, 3, 3, 6),
 -                       row(2, 4, 3, 6, 12),
 -                       row(4, 8, 2, 12, 24));
 +        assertRows(execute("SELECT a, b, e, count(b), max(e) FROM %s WHERE a = 1 GROUP BY a, b, c LIMIT 2"),
 +                   row(1, 2, 6, 1L, 6),
 +                   row(1, 2, 12, 1L, 12));
  
 -            assertRows(execute("SELECT * FROM %s WHERE a IN (1, 2, 4) GROUP BY a, b"),
 -                       row(1, 2, 1, 3, 6),
 -                       row(1, 4, 2, 6, 12),
 -                       row(2, 2, 3, 3, 6),
 -                       row(2, 4, 3, 6, 12),
 -                       row(4, 8, 2, 12, 24));
 +        assertRows(execute("SELECT count(b), max(e) FROM %s WHERE a = 1 GROUP BY a, b, c LIMIT 1"),
 +                   row(1L, 6));
  
 -            // Multi-partitions query with DISTINCT
 -            assertRows(execute("SELECT DISTINCT a, count(a)FROM %s WHERE a IN (1, 2, 4) GROUP BY a"),
 -                       row(1, 1L),
 -                       row(2, 1L),
 -                       row(4, 1L));
 +        // Single partition queries with PER PARTITION LIMIT
 +        assertRows(execute("SELECT a, b, e, count(b), max(e) FROM %s WHERE a = 1 GROUP BY a, b, c PER PARTITION LIMIT 10"),
 +                   row(1, 2, 6, 1L, 6),
 +                   row(1, 2, 12, 1L, 12),
 +                   row(1, 4, 12, 2L, 24));
  
 -            assertInvalidMessage("Grouping on clustering columns is not allowed for SELECT DISTINCT queries",
 -                                 "SELECT DISTINCT a, count(a)FROM %s WHERE a IN (1, 2, 4) GROUP BY a, b");
 +        assertRows(execute("SELECT a, b, e, count(b), max(e) FROM %s WHERE a = 1 GROUP BY a, b, c PER PARTITION LIMIT 2"),
 +                   row(1, 2, 6, 1L, 6),
 +                   row(1, 2, 12, 1L, 12));
  
 -            // Multi-partitions query with DISTINCT and LIMIT
 -            assertRows(execute("SELECT DISTINCT a, count(a)FROM %s WHERE a IN (1, 2, 4) GROUP BY a LIMIT 2"),
 -                       row(1, 1L),
 -                       row(2, 1L));
 +        assertRows(execute("SELECT count(b), max(e) FROM %s WHERE a = 1 GROUP BY a, b, c PER PARTITION LIMIT 1"),
 +                   row(1L, 6));
  
 -            // Multi-partitions queries with PER PARTITION LIMIT
 -            assertRows(execute("SELECT a, b, e, count(b), max(e) FROM %s WHERE a IN (1, 2, 4) GROUP BY a, b, c PER PARTITION LIMIT 1"),
 -                       row(1, 2, 6, 1L, 6),
 -                       row(2, 2, 6, 1L, 6),
 -                       row(4, 8, 24, 1L, 24));
 -
 -            assertRows(execute("SELECT a, b, e, count(b), max(e) FROM %s WHERE a IN (1, 2, 4) GROUP BY a, b, c PER PARTITION LIMIT 2"),
 -                       row(1, 2, 6, 1L, 6),
 -                       row(1, 2, 12, 1L, 12),
 -                       row(2, 2, 6, 1L, 6),
 -                       row(2, 4, 12, 1L, 12),
 -                       row(4, 8, 24, 1L, 24));
 -
 -            // Multi-partitions with wildcard and PER PARTITION LIMIT
 -            assertRows(execute("SELECT * FROM %s WHERE a IN (1, 2, 4) GROUP BY a, b, c PER PARTITION LIMIT 2"),
 -                       row(1, 2, 1, 3, 6),
 -                       row(1, 2, 2, 6, 12),
 -                       row(2, 2, 3, 3, 6),
 -                       row(2, 4, 3, 6, 12),
 -                       row(4, 8, 2, 12, 24));
 +        // Single partition queries without aggregates and with LIMIT
 +        assertRows(execute("SELECT a, b, c, d FROM %s WHERE a = 1 GROUP BY a, b LIMIT 2"),
 +                   row(1, 2, 1, 3),
 +                   row(1, 4, 2, 6));
  
 -            assertRows(execute("SELECT * FROM %s WHERE a IN (1, 2, 4) GROUP BY a, b PER PARTITION LIMIT 1"),
 -                       row(1, 2, 1, 3, 6),
 -                       row(2, 2, 3, 3, 6),
 -                       row(4, 8, 2, 12, 24));
 +        assertRows(execute("SELECT a, b, c, d FROM %s WHERE a = 1 GROUP BY a, b LIMIT 1"),
 +                   row(1, 2, 1, 3));
  
 -            // Multi-partitions queries with ORDER BY
 -            assertRows(execute("SELECT a, b, c, count(b), max(e) FROM %s WHERE a IN (1, 2, 4) GROUP BY a, b ORDER BY b DESC, c DESC"),
 -                       row(4, 8, 2, 1L, 24),
 -                       row(2, 4, 3, 1L, 12),
 -                       row(1, 4, 2, 2L, 24),
 -                       row(2, 2, 3, 1L, 6),
 -                       row(1, 2, 2, 2L, 12));
 -
 -            assertRows(execute("SELECT a, b, c, d FROM %s WHERE a IN (1, 2, 4) GROUP BY a, b, c ORDER BY b DESC, c DESC"),
 -                       row(4, 8, 2, 12),
 -                       row(2, 4, 3, 6),
 -                       row(1, 4, 2, 12),
 -                       row(2, 2, 3, 3),
 -                       row(1, 2, 2, 6),
 -                       row(1, 2, 1, 3));
 -
 -            // Multi-partitions queries with ORDER BY and LIMIT
 -            assertRows(execute("SELECT a, b, c, d FROM %s WHERE a IN (1, 2, 4) GROUP BY a, b ORDER BY b DESC, c DESC LIMIT 3"),
 -                       row(4, 8, 2, 12),
 -                       row(2, 4, 3, 6),
 -                       row(1, 4, 2, 12));
 -
 -            // Multi-partitions with wildcard, ORDER BY and LIMIT
 -            assertRows(execute("SELECT * FROM %s WHERE a IN (1, 2, 4) GROUP BY a, b, c ORDER BY b DESC, c DESC LIMIT 3"),
 -                       row(4, 8, 2, 12, 24),
 -                       row(2, 4, 3, 6, 12),
 -                       row(1, 4, 2, 12, 24));
 +        assertRows(execute("SELECT a, b, c, d FROM %s WHERE a = 1 GROUP BY a, b, c LIMIT 2"),
 +                   row(1, 2, 1, 3),
 +                   row(1, 2, 2, 6));
  
 -            // Invalid queries
 -            assertInvalidMessage("Group by is currently only supported on the columns of the PRIMARY KEY, got e",
 -                                 "SELECT a, b, d, count(b), max(c) FROM %s WHERE a = 1 GROUP BY a, e");
++        // Single partition queries with wildcard and with LIMIT
++        assertRows(execute("SELECT * FROM %s WHERE a = 1 GROUP BY a, b, c LIMIT 2"),
++                   row(1, 2, 1, 3, 6),
++                   row(1, 2, 2, 6, 12));
+ 
 -            assertInvalidMessage("Group by currently only support groups of columns following their declared order in the PRIMARY KEY",
 -                                 "SELECT a, b, d, count(b), max(c) FROM %s WHERE a = 1 GROUP BY c");
++        assertRows(execute("SELECT * FROM %s WHERE a = 1 GROUP BY a, b LIMIT 1"),
++                   row(1, 2, 1, 3, 6));
+ 
 -            assertInvalidMessage("Group by currently only support groups of columns following their declared order in the PRIMARY KEY",
 -                                 "SELECT a, b, d, count(b), max(c) FROM %s WHERE a = 1 GROUP BY a, c, b");
 +        // Single partition queries without aggregates and with PER PARTITION LIMIT
 +        assertRows(execute("SELECT a, b, c, d FROM %s WHERE a = 1 GROUP BY a, b PER PARTITION LIMIT 2"),
 +                   row(1, 2, 1, 3),
 +                   row(1, 4, 2, 6));
  
 -            assertInvalidMessage("Group by currently only support groups of columns following their declared order in the PRIMARY KEY",
 -                                 "SELECT a, b, d, count(b), max(c) FROM %s WHERE a = 1 GROUP BY a, a");
 +        assertRows(execute("SELECT a, b, c, d FROM %s WHERE a = 1 GROUP BY a, b PER PARTITION LIMIT 1"),
 +                   row(1, 2, 1, 3));
  
 -            assertInvalidMessage("Group by currently only support groups of columns following their declared order in the PRIMARY KEY",
 -                                 "SELECT a, b, c, d FROM %s WHERE token(a) = token(1) GROUP BY b, c");
 +        assertRows(execute("SELECT a, b, c, d FROM %s WHERE a = 1 GROUP BY a, b, c PER PARTITION LIMIT 2"),
 +                   row(1, 2, 1, 3),
 +                   row(1, 2, 2, 6));
  
 -            assertInvalidMessage("Undefined column name clustering1",
 -                                 "SELECT a, b as clustering1, max(c) FROM %s WHERE a = 1 GROUP BY a, clustering1");
++        // Single partition queries with wildcard and with PER PARTITION LIMIT
++        assertRows(execute("SELECT * FROM %s WHERE a = 1 GROUP BY a, b, c PER PARTITION LIMIT 2"),
++                   row(1, 2, 1, 3, 6),
++                   row(1, 2, 2, 6, 12));
+ 
 -            assertInvalidMessage("Undefined column name z",
 -                                 "SELECT a, b, max(c) FROM %s WHERE a = 1 GROUP BY a, b, z");
++        assertRows(execute("SELECT * FROM %s WHERE a = 1 GROUP BY a, b PER PARTITION LIMIT 1"),
++                   row(1, 2, 1, 3, 6));
+ 
 -            // Test with composite partition key
 -            createTable("CREATE TABLE %s (a int, b int, c int, d int, e int, primary key ((a, b), c, d))" + compactOption);
 +        // Single partition queries with ORDER BY
 +        assertRows(execute("SELECT a, b, e, count(b), max(e) FROM %s WHERE a = 1 GROUP BY a, b, c ORDER BY b DESC, c DESC"),
 +                   row(1, 4, 24, 2L, 24),
 +                   row(1, 2, 12, 1L, 12),
 +                   row(1, 2, 6, 1L, 6));
  
 -            execute("INSERT INTO %s (a, b, c, d, e) VALUES (1, 1, 1, 3, 6)");
 -            execute("INSERT INTO %s (a, b, c, d, e) VALUES (1, 1, 2, 6, 12)");
 -            execute("INSERT INTO %s (a, b, c, d, e) VALUES (1, 1, 3, 12, 24)");
 -            execute("INSERT INTO %s (a, b, c, d, e) VALUES (1, 2, 1, 12, 24)");
 -            execute("INSERT INTO %s (a, b, c, d, e) VALUES (1, 2, 2, 6, 12)");
 +        // Single partition queries with ORDER BY and PER PARTITION LIMIT
 +        assertRows(execute("SELECT a, b, e, count(b), max(e) FROM %s WHERE a = 1 GROUP BY a, b, c ORDER BY b DESC, c DESC PER PARTITION LIMIT 1"),
 +                   row(1, 4, 24, 2L, 24));
  
 -            assertInvalidMessage("Group by is not supported on only a part of the partition key",
 -                                 "SELECT a, b, max(d) FROM %s GROUP BY a");
 +        // Single partition queries with ORDER BY and LIMIT
 +        assertRows(execute("SELECT a, b, e, count(b), max(e) FROM %s WHERE a = 1 GROUP BY a, b, c ORDER BY b DESC, c DESC LIMIT 2"),
 +                   row(1, 4, 24, 2L, 24),
 +                   row(1, 2, 12, 1L, 12));
  
 -            assertRows(execute("SELECT a, b, max(d) FROM %s GROUP BY a, b"),
 -                       row(1, 2, 12),
 -                       row(1, 1, 12));
 +        // Multi-partitions queries
 +        assertRows(execute("SELECT a, b, e, count(b), max(e) FROM %s WHERE a IN (1, 2, 4) GROUP BY a, b, c"),
 +                   row(1, 2, 6, 1L, 6),
 +                   row(1, 2, 12, 1L, 12),
 +                   row(1, 4, 12, 2L, 24),
 +                   row(2, 2, 6, 1L, 6),
 +                   row(2, 4, 12, 1L, 12),
 +                   row(4, 8, 24, 1L, 24));
 +
 +        assertRows(execute("SELECT a, b, e, count(b), max(e) FROM %s WHERE a IN (1, 2, 4) AND b = 2 GROUP BY a, b, c"),
 +                   row(1, 2, 6, 1L, 6),
 +                   row(1, 2, 12, 1L, 12),
 +                   row(2, 2, 6, 1L, 6));
  
 -            assertRows(execute("SELECT a, b, max(d) FROM %s WHERE a = 1 AND b = 1 GROUP BY b"),
 -                       row(1, 1, 12));
 +        // Multi-partitions queries without aggregates
 +        assertRows(execute("SELECT a, b, c, d FROM %s WHERE a IN (1, 2, 4) GROUP BY a, b"),
 +                   row(1, 2, 1, 3),
 +                   row(1, 4, 2, 6),
 +                   row(2, 2, 3, 3),
 +                   row(2, 4, 3, 6),
 +                   row(4, 8, 2, 12));
 +
 +        assertRows(execute("SELECT a, b, c, d FROM %s WHERE a IN (1, 2, 4) GROUP BY a, b, c"),
 +                   row(1, 2, 1, 3),
 +                   row(1, 2, 2, 6),
 +                   row(1, 4, 2, 6),
 +                   row(2, 2, 3, 3),
 +                   row(2, 4, 3, 6),
 +                   row(4, 8, 2, 12));
 +
++        // Multi-partitions with wildcard
++        assertRows(execute("SELECT * FROM %s WHERE a IN (1, 2, 4) GROUP BY a, b, c"),
++                   row(1, 2, 1, 3, 6),
++                   row(1, 2, 2, 6, 12),
++                   row(1, 4, 2, 6, 12),
++                   row(2, 2, 3, 3, 6),
++                   row(2, 4, 3, 6, 12),
++                   row(4, 8, 2, 12, 24));
++
++        assertRows(execute("SELECT * FROM %s WHERE a IN (1, 2, 4) GROUP BY a, b"),
++                   row(1, 2, 1, 3, 6),
++                   row(1, 4, 2, 6, 12),
++                   row(2, 2, 3, 3, 6),
++                   row(2, 4, 3, 6, 12),
++                   row(4, 8, 2, 12, 24));
+ 
 -            // Test with table without clustering key
 -            createTable("CREATE TABLE %s (a int primary key, b int, c int)" + compactOption);
 +        // Multi-partitions query with DISTINCT
 +        assertRows(execute("SELECT DISTINCT a, count(a)FROM %s WHERE a IN (1, 2, 4) GROUP BY a"),
 +                   row(1, 1L),
 +                   row(2, 1L),
 +                   row(4, 1L));
  
 -            execute("INSERT INTO %s (a, b, c) VALUES (1, 3, 6)");
 -            execute("INSERT INTO %s (a, b, c) VALUES (2, 6, 12)");
 -            execute("INSERT INTO %s (a, b, c) VALUES (3, 12, 24)");
 +        assertInvalidMessage("Grouping on clustering columns is not allowed for SELECT DISTINCT queries",
 +                             "SELECT DISTINCT a, count(a)FROM %s WHERE a IN (1, 2, 4) GROUP BY a, b");
  
 -            assertInvalidMessage("Group by currently only support groups of columns following their declared order in the PRIMARY KEY",
 -                    "SELECT a, max(c) FROM %s WHERE a = 1 GROUP BY a, a");
 -        }
 +        // Multi-partitions query with DISTINCT and LIMIT
 +        assertRows(execute("SELECT DISTINCT a, count(a)FROM %s WHERE a IN (1, 2, 4) GROUP BY a LIMIT 2"),
 +                   row(1, 1L),
 +                   row(2, 1L));
 +
 +        // Multi-partitions queries with PER PARTITION LIMIT
 +        assertRows(execute("SELECT a, b, e, count(b), max(e) FROM %s WHERE a IN (1, 2, 4) GROUP BY a, b, c PER PARTITION LIMIT 1"),
 +                   row(1, 2, 6, 1L, 6),
 +                   row(2, 2, 6, 1L, 6),
 +                   row(4, 8, 24, 1L, 24));
 +
 +        assertRows(execute("SELECT a, b, e, count(b), max(e) FROM %s WHERE a IN (1, 2, 4) GROUP BY a, b, c PER PARTITION LIMIT 2"),
 +                   row(1, 2, 6, 1L, 6),
 +                   row(1, 2, 12, 1L, 12),
 +                   row(2, 2, 6, 1L, 6),
 +                   row(2, 4, 12, 1L, 12),
 +                   row(4, 8, 24, 1L, 24));
 +
++        // Multi-partitions with wildcard and PER PARTITION LIMIT
++        assertRows(execute("SELECT * FROM %s WHERE a IN (1, 2, 4) GROUP BY a, b, c PER PARTITION LIMIT 2"),
++                   row(1, 2, 1, 3, 6),
++                   row(1, 2, 2, 6, 12),
++                   row(2, 2, 3, 3, 6),
++                   row(2, 4, 3, 6, 12),
++                   row(4, 8, 2, 12, 24));
++
++        assertRows(execute("SELECT * FROM %s WHERE a IN (1, 2, 4) GROUP BY a, b PER PARTITION LIMIT 1"),
++                   row(1, 2, 1, 3, 6),
++                   row(2, 2, 3, 3, 6),
++                   row(4, 8, 2, 12, 24));
++
 +        // Multi-partitions queries with ORDER BY
 +        assertRows(execute("SELECT a, b, c, count(b), max(e) FROM %s WHERE a IN (1, 2, 4) GROUP BY a, b ORDER BY b DESC, c DESC"),
 +                   row(4, 8, 2, 1L, 24),
 +                   row(2, 4, 3, 1L, 12),
 +                   row(1, 4, 2, 2L, 24),
 +                   row(2, 2, 3, 1L, 6),
 +                   row(1, 2, 2, 2L, 12));
 +
 +        assertRows(execute("SELECT a, b, c, d FROM %s WHERE a IN (1, 2, 4) GROUP BY a, b, c ORDER BY b DESC, c DESC"),
 +                   row(4, 8, 2, 12),
 +                   row(2, 4, 3, 6),
 +                   row(1, 4, 2, 12),
 +                   row(2, 2, 3, 3),
 +                   row(1, 2, 2, 6),
 +                   row(1, 2, 1, 3));
 +
 +        // Multi-partitions queries with ORDER BY and LIMIT
 +        assertRows(execute("SELECT a, b, c, d FROM %s WHERE a IN (1, 2, 4) GROUP BY a, b ORDER BY b DESC, c DESC LIMIT 3"),
 +                   row(4, 8, 2, 12),
 +                   row(2, 4, 3, 6),
 +                   row(1, 4, 2, 12));
 +
++        // Multi-partitions with wildcard, ORDER BY and LIMIT
++        assertRows(execute("SELECT * FROM %s WHERE a IN (1, 2, 4) GROUP BY a, b, c ORDER BY b DESC, c DESC LIMIT 3"),
++                   row(4, 8, 2, 12, 24),
++                   row(2, 4, 3, 6, 12),
++                   row(1, 4, 2, 12, 24));
++
 +        // Invalid queries
 +        assertInvalidMessage("Group by is currently only supported on the columns of the PRIMARY KEY, got e",
 +                             "SELECT a, b, d, count(b), max(c) FROM %s WHERE a = 1 GROUP BY a, e");
 +
 +        assertInvalidMessage("Group by currently only support groups of columns following their declared order in the PRIMARY KEY",
 +                             "SELECT a, b, d, count(b), max(c) FROM %s WHERE a = 1 GROUP BY c");
 +
 +        assertInvalidMessage("Group by currently only support groups of columns following their declared order in the PRIMARY KEY",
 +                             "SELECT a, b, d, count(b), max(c) FROM %s WHERE a = 1 GROUP BY a, c, b");
 +
 +        assertInvalidMessage("Group by currently only support groups of columns following their declared order in the PRIMARY KEY",
 +                             "SELECT a, b, d, count(b), max(c) FROM %s WHERE a = 1 GROUP BY a, a");
 +
 +        assertInvalidMessage("Group by currently only support groups of columns following their declared order in the PRIMARY KEY",
 +                             "SELECT a, b, c, d FROM %s WHERE token(a) = token(1) GROUP BY b, c");
 +
 +        assertInvalidMessage("Undefined column name clustering1",
 +                             "SELECT a, b as clustering1, max(c) FROM %s WHERE a = 1 GROUP BY a, clustering1");
 +
 +        assertInvalidMessage("Undefined column name z",
 +                             "SELECT a, b, max(c) FROM %s WHERE a = 1 GROUP BY a, b, z");
 +
 +        // Test with composite partition key
 +        createTable("CREATE TABLE %s (a int, b int, c int, d int, e int, primary key ((a, b), c, d))");
 +
 +        execute("INSERT INTO %s (a, b, c, d, e) VALUES (1, 1, 1, 3, 6)");
 +        execute("INSERT INTO %s (a, b, c, d, e) VALUES (1, 1, 2, 6, 12)");
 +        execute("INSERT INTO %s (a, b, c, d, e) VALUES (1, 1, 3, 12, 24)");
 +        execute("INSERT INTO %s (a, b, c, d, e) VALUES (1, 2, 1, 12, 24)");
 +        execute("INSERT INTO %s (a, b, c, d, e) VALUES (1, 2, 2, 6, 12)");
 +
 +        assertInvalidMessage("Group by is not supported on only a part of the partition key",
 +                             "SELECT a, b, max(d) FROM %s GROUP BY a");
 +
 +        assertRows(execute("SELECT a, b, max(d) FROM %s GROUP BY a, b"),
 +                   row(1, 2, 12),
 +                   row(1, 1, 12));
 +
 +        assertRows(execute("SELECT a, b, max(d) FROM %s WHERE a = 1 AND b = 1 GROUP BY b"),
 +                   row(1, 1, 12));
 +
 +        // Test with table without clustering key
 +        createTable("CREATE TABLE %s (a int primary key, b int, c int)");
 +
 +        execute("INSERT INTO %s (a, b, c) VALUES (1, 3, 6)");
 +        execute("INSERT INTO %s (a, b, c) VALUES (2, 6, 12)");
 +        execute("INSERT INTO %s (a, b, c) VALUES (3, 12, 24)");
 +
 +        assertInvalidMessage("Group by currently only support groups of columns following their declared order in the PRIMARY KEY",
 +                             "SELECT a, max(c) FROM %s WHERE a = 1 GROUP BY a, a");
      }
  
      @Test
@@@ -883,322 -1080,414 +1068,410 @@@
      @Test
      public void testGroupByWithPaging() throws Throwable
      {
 -        for (String compactOption : new String[] { "", " WITH COMPACT STORAGE" })
 +        createTable("CREATE TABLE %s (a int, b int, c int, d int, e int, primary key (a, b, c, d))");
 +
 +        execute("INSERT INTO %s (a, b, c, d, e) VALUES (1, 2, 1, 3, 6)");
 +        execute("INSERT INTO %s (a, b, c, d, e) VALUES (1, 2, 2, 6, 12)");
 +        execute("INSERT INTO %s (a, b, c, d, e) VALUES (1, 3, 2, 12, 24)");
 +        execute("INSERT INTO %s (a, b, c, d, e) VALUES (1, 4, 2, 12, 24)");
 +        execute("INSERT INTO %s (a, b, c, d, e) VALUES (1, 4, 2, 6, 12)");
 +        execute("INSERT INTO %s (a, b, c, d, e) VALUES (2, 2, 3, 3, 6)");
 +        execute("INSERT INTO %s (a, b, c, d, e) VALUES (2, 4, 3, 6, 12)");
 +        execute("INSERT INTO %s (a, b, c, d, e) VALUES (3, 3, 2, 12, 24)");
 +        execute("INSERT INTO %s (a, b, c, d, e) VALUES (4, 8, 2, 12, 24)");
 +
 +        // Makes sure that we have some tombstones
 +        execute("DELETE FROM %s WHERE a = 1 AND b = 3 AND c = 2 AND d = 12");
 +        execute("DELETE FROM %s WHERE a = 3");
 +
 +        for (int pageSize = 1; pageSize < 10; pageSize++)
          {
 -            createTable("CREATE TABLE %s (a int, b int, c int, d int, e int, primary key (a, b, c, d))"
 -                    + compactOption);
 -
 -            execute("INSERT INTO %s (a, b, c, d, e) VALUES (1, 2, 1, 3, 6)");
 -            execute("INSERT INTO %s (a, b, c, d, e) VALUES (1, 2, 2, 6, 12)");
 -            execute("INSERT INTO %s (a, b, c, d, e) VALUES (1, 3, 2, 12, 24)");
 -            execute("INSERT INTO %s (a, b, c, d, e) VALUES (1, 4, 2, 12, 24)");
 -            execute("INSERT INTO %s (a, b, c, d, e) VALUES (1, 4, 2, 6, 12)");
 -            execute("INSERT INTO %s (a, b, c, d, e) VALUES (2, 2, 3, 3, 6)");
 -            execute("INSERT INTO %s (a, b, c, d, e) VALUES (2, 4, 3, 6, 12)");
 -            execute("INSERT INTO %s (a, b, c, d, e) VALUES (3, 3, 2, 12, 24)");
 -            execute("INSERT INTO %s (a, b, c, d, e) VALUES (4, 8, 2, 12, 24)");
 -
 -            // Makes sure that we have some tombstones
 -            execute("DELETE FROM %s WHERE a = 1 AND b = 3 AND c = 2 AND d = 12");
 -            execute("DELETE FROM %s WHERE a = 3");
 -
 -            for (int pageSize = 1; pageSize < 10; pageSize++)
 -            {
 -                // Range queries
 -                assertRowsNet(executeNetWithPaging("SELECT a, b, e, count(b), max(e) FROM %s GROUP BY a", pageSize),
 -                              row(1, 2, 6, 4L, 24),
 -                              row(2, 2, 6, 2L, 12),
 -                              row(4, 8, 24, 1L, 24));
 -
 -                assertRowsNet(executeNetWithPaging("SELECT a, b, e, count(b), max(e) FROM %s GROUP BY a, b", pageSize),
 -                              row(1, 2, 6, 2L, 12),
 -                              row(1, 4, 12, 2L, 24),
 -                              row(2, 2, 6, 1L, 6),
 -                              row(2, 4, 12, 1L, 12),
 -                              row(4, 8, 24, 1L, 24));
 -
 -                assertRowsNet(executeNetWithPaging("SELECT a, b, e, count(b), max(e) FROM %s", pageSize),
 -                              row(1, 2, 6, 7L, 24));
 -
 -                assertRowsNet(executeNetWithPaging("SELECT a, b, e, count(b), max(e) FROM %s WHERE b = 2 GROUP BY a, b ALLOW FILTERING",
 -                                                   pageSize),
 -                              row(1, 2, 6, 2L, 12),
 -                              row(2, 2, 6, 1L, 6));
 -
 -                assertRowsNet(executeNetWithPaging("SELECT a, b, e, count(b), max(e) FROM %s WHERE b = 2 ALLOW FILTERING",
 -                                                   pageSize),
 -                              row(1, 2, 6, 3L, 12));
 -
 -                // Range queries without aggregates
 -                assertRowsNet(executeNetWithPaging("SELECT a, b, c, d FROM %s GROUP BY a, b, c", pageSize),
 -                              row(1, 2, 1, 3),
 -                              row(1, 2, 2, 6),
 -                              row(1, 4, 2, 6),
 -                              row(2, 2, 3, 3),
 -                              row(2, 4, 3, 6),
 -                              row(4, 8, 2, 12));
 -
 -                assertRowsNet(executeNetWithPaging("SELECT a, b, c, d FROM %s GROUP BY a, b", pageSize),
 -                              row(1, 2, 1, 3),
 -                              row(1, 4, 2, 6),
 -                              row(2, 2, 3, 3),
 -                              row(2, 4, 3, 6),
 -                              row(4, 8, 2, 12));
 -
 -                // Range queries with wildcard
 -                assertRowsNet(executeNetWithPaging("SELECT * FROM %s GROUP BY a, b, c", pageSize),
 -                              row(1, 2, 1, 3, 6),
 -                              row(1, 2, 2, 6, 12),
 -                              row(1, 4, 2, 6, 12),
 -                              row(2, 2, 3, 3, 6),
 -                              row(2, 4, 3, 6, 12),
 -                              row(4, 8, 2, 12, 24));
 -
 -                assertRowsNet(executeNetWithPaging("SELECT * FROM %s GROUP BY a, b", pageSize),
 -                              row(1, 2, 1, 3, 6),
 -                              row(1, 4, 2, 6, 12),
 -                              row(2, 2, 3, 3, 6),
 -                              row(2, 4, 3, 6, 12),
 -                              row(4, 8, 2, 12, 24));
 -
 -                // Range query with LIMIT
 -                assertRowsNet(executeNetWithPaging("SELECT a, b, e, count(b), max(e) FROM %s GROUP BY a, b LIMIT 2",
 -                                                   pageSize),
 -                              row(1, 2, 6, 2L, 12),
 -                              row(1, 4, 12, 2L, 24));
 -
 -                assertRowsNet(executeNetWithPaging("SELECT a, b, e, count(b), max(e) FROM %s LIMIT 2",
 -                                                   pageSize),
 -                              row(1, 2, 6, 7L, 24));
 -
 -                // Range queries with PER PARTITION LIMIT
 -                assertRowsNet(executeNetWithPaging("SELECT a, b, e, count(b), max(e) FROM %s GROUP BY a, b PER PARTITION LIMIT 3", pageSize),
 -                              row(1, 2, 6, 2L, 12),
 -                              row(1, 4, 12, 2L, 24),
 -                              row(2, 2, 6, 1L, 6),
 -                              row(2, 4, 12, 1L, 12),
 -                              row(4, 8, 24, 1L, 24));
 -
 -                assertRowsNet(executeNetWithPaging("SELECT a, b, e, count(b), max(e) FROM %s GROUP BY a, b PER PARTITION LIMIT 1", pageSize),
 -                              row(1, 2, 6, 2L, 12),
 -                              row(2, 2, 6, 1L, 6),
 -                              row(4, 8, 24, 1L, 24));
 -
 -                // Range query with PER PARTITION LIMIT
 -                assertRowsNet(executeNetWithPaging("SELECT a, b, e, count(b), max(e) FROM %s GROUP BY a, b PER PARTITION LIMIT 1 LIMIT 2", pageSize),
 -                              row(1, 2, 6, 2L, 12),
 -                              row(2, 2, 6, 1L, 6));
 -
 -                // Range query without aggregates and with PER PARTITION LIMIT
 -                assertRowsNet(executeNetWithPaging("SELECT a, b, c, d FROM %s GROUP BY a, b, c PER PARTITION LIMIT 2", pageSize),
 -                              row(1, 2, 1, 3),
 -                              row(1, 2, 2, 6),
 -                              row(2, 2, 3, 3),
 -                              row(2, 4, 3, 6),
 -                              row(4, 8, 2, 12));
 -
 -                // Range queries with wildcard and with LIMIT
 -                assertRowsNet(executeNetWithPaging("SELECT * FROM %s GROUP BY a, b, c LIMIT 3", pageSize),
 -                              row(1, 2, 1, 3, 6),
 -                              row(1, 2, 2, 6, 12),
 -                              row(1, 4, 2, 6, 12));
 -
 -                assertRowsNet(executeNetWithPaging("SELECT * FROM %s GROUP BY a, b LIMIT 3", pageSize),
 -                              row(1, 2, 1, 3, 6),
 -                              row(1, 4, 2, 6, 12),
 -                              row(2, 2, 3, 3, 6));
 -
 -                // Range queries with wildcard and with PER PARTITION LIMIT
 -                assertRowsNet(executeNetWithPaging("SELECT * FROM %s GROUP BY a, b, c PER PARTITION LIMIT 2", pageSize),
 -                              row(1, 2, 1, 3, 6),
 -                              row(1, 2, 2, 6, 12),
 -                              row(2, 2, 3, 3, 6),
 -                              row(2, 4, 3, 6, 12),
 -                              row(4, 8, 2, 12, 24));
 -
 -                assertRowsNet(executeNetWithPaging("SELECT * FROM %s GROUP BY a, b PER PARTITION LIMIT 1", pageSize),
 -                              row(1, 2, 1, 3, 6),
 -                              row(2, 2, 3, 3, 6),
 -                              row(4, 8, 2, 12, 24));
 -
 -                // Range queries without aggregates and with LIMIT
 -                assertRowsNet(executeNetWithPaging("SELECT a, b, c, d FROM %s GROUP BY a, b, c LIMIT 3", pageSize),
 -                              row(1, 2, 1, 3),
 -                              row(1, 2, 2, 6),
 -                              row(1, 4, 2, 6));
 -
 -                assertRowsNet(executeNetWithPaging("SELECT a, b, c, d FROM %s GROUP BY a, b LIMIT 3", pageSize),
 -                              row(1, 2, 1, 3),
 -                              row(1, 4, 2, 6),
 -                              row(2, 2, 3, 3));
 -
 -                // Range query without aggregates, with PER PARTITION LIMIT and with LIMIT
 -                assertRowsNet(executeNetWithPaging("SELECT a, b, c, d FROM %s GROUP BY a, b, c PER PARTITION LIMIT 2 LIMIT 3", pageSize),
 -                              row(1, 2, 1, 3),
 -                              row(1, 2, 2, 6),
 -                              row(2, 2, 3, 3));
 -
 -                // Range queries with wildcard, with PER PARTITION LIMIT and LIMIT
 -                assertRowsNet(executeNetWithPaging("SELECT * FROM %s GROUP BY a, b, c PER PARTITION LIMIT 2 LIMIT 3", pageSize),
 -                              row(1, 2, 1, 3, 6),
 -                              row(1, 2, 2, 6, 12),
 -                              row(2, 2, 3, 3, 6));
 -
 -                // Range query with DISTINCT
 -                assertRowsNet(executeNetWithPaging("SELECT DISTINCT a, count(a)FROM %s GROUP BY a", pageSize),
 -                              row(1, 1L),
 -                              row(2, 1L),
 -                              row(4, 1L));
 -
 -                assertRowsNet(executeNetWithPaging("SELECT DISTINCT a, count(a)FROM %s", pageSize),
 -                              row(1, 3L));
 -
 -                // Range query with DISTINCT and LIMIT
 -                assertRowsNet(executeNetWithPaging("SELECT DISTINCT a, count(a)FROM %s GROUP BY a LIMIT 2", pageSize),
 -                              row(1, 1L),
 -                              row(2, 1L));
 -
 -                assertRowsNet(executeNetWithPaging("SELECT DISTINCT a, count(a)FROM %s LIMIT 2", pageSize),
 -                              row(1, 3L));
 -
 -                // Range query with ORDER BY
 -                assertInvalidMessage("ORDER BY is only supported when the partition key is restricted by an EQ or an IN",
 -                                     "SELECT a, b, c, count(b), max(e) FROM %s GROUP BY a, b ORDER BY b DESC, c DESC");
 -
 -                // Single partition queries
 -                assertRowsNet(executeNetWithPaging("SELECT a, b, e, count(b), max(e) FROM %s WHERE a = 1 GROUP BY a, b, c",
 -                                                   pageSize),
 -                              row(1, 2, 6, 1L, 6),
 -                              row(1, 2, 12, 1L, 12),
 -                              row(1, 4, 12, 2L, 24));
 -
 -                assertRowsNet(executeNetWithPaging("SELECT a, b, e, count(b), max(e) FROM %s WHERE a = 1", pageSize),
 -                              row(1, 2, 6, 4L, 24));
 -
 -                assertRowsNet(executeNetWithPaging("SELECT a, b, e, count(b), max(e) FROM %s WHERE a = 1 AND b = 2 GROUP BY a, b, c",
 -                                                   pageSize),
 -                              row(1, 2, 6, 1L, 6),
 -                              row(1, 2, 12, 1L, 12));
 -
 -                assertRowsNet(executeNetWithPaging("SELECT a, b, e, count(b), max(e) FROM %s WHERE a = 1 AND b = 2",
 -                                                   pageSize),
 -                              row(1, 2, 6, 2L, 12));
 -
 -                // Single partition queries without aggregates
 -                assertRowsNet(executeNetWithPaging("SELECT a, b, c, d FROM %s WHERE a = 1 GROUP BY a, b", pageSize),
 -                              row(1, 2, 1, 3),
 -                              row(1, 4, 2, 6));
 -
 -                assertRowsNet(executeNetWithPaging("SELECT a, b, c, d FROM %s WHERE a = 1 GROUP BY a, b, c", pageSize),
 -                              row(1, 2, 1, 3),
 -                              row(1, 2, 2, 6),
 -                              row(1, 4, 2, 6));
 -
 -                // Single partition queries with wildcard
 -                assertRowsNet(executeNetWithPaging("SELECT * FROM %s WHERE a = 1 GROUP BY a, b, c", pageSize),
 -                           row(1, 2, 1, 3, 6),
 -                           row(1, 2, 2, 6, 12),
 -                           row(1, 4, 2, 6, 12));
 -
 -                assertRowsNet(executeNetWithPaging("SELECT * FROM %s WHERE a = 1 GROUP BY a, b", pageSize),
 -                           row(1, 2, 1, 3, 6),
 -                           row(1, 4, 2, 6, 12));
 -
 -                // Single partition query with DISTINCT
 -                assertRowsNet(executeNetWithPaging("SELECT DISTINCT a, count(a)FROM %s WHERE a = 1 GROUP BY a",
 -                                                   pageSize),
 -                              row(1, 1L));
 -
 -                assertRowsNet(executeNetWithPaging("SELECT DISTINCT a, count(a)FROM %s WHERE a = 1 GROUP BY a",
 -                                                   pageSize),
 -                              row(1, 1L));
 -
 -                // Single partition queries with LIMIT
 -                assertRowsNet(executeNetWithPaging("SELECT a, b, e, count(b), max(e) FROM %s WHERE a = 1 GROUP BY a, b, c LIMIT 10",
 -                                                   pageSize),
 -                              row(1, 2, 6, 1L, 6),
 -                              row(1, 2, 12, 1L, 12),
 -                              row(1, 4, 12, 2L, 24));
 -
 -                assertRowsNet(executeNetWithPaging("SELECT a, b, e, count(b), max(e) FROM %s WHERE a = 1 GROUP BY a, b, c LIMIT 2",
 -                                                   pageSize),
 -                              row(1, 2, 6, 1L, 6),
 -                              row(1, 2, 12, 1L, 12));
 -
 -                assertRowsNet(executeNetWithPaging("SELECT a, b, e, count(b), max(e) FROM %s WHERE a = 1 LIMIT 2",
 -                                                   pageSize),
 -                              row(1, 2, 6, 4L, 24));
 -
 -                assertRowsNet(executeNetWithPaging("SELECT count(b), max(e) FROM %s WHERE a = 1 GROUP BY a, b, c LIMIT 1",
 -                                                   pageSize),
 -                              row(1L, 6));
 -
 -                // Single partition queries with wildcard and with LIMIT
 -                assertRowsNet(executeNetWithPaging("SELECT * FROM %s WHERE a = 1 GROUP BY a, b, c LIMIT 2", pageSize),
 -                           row(1, 2, 1, 3, 6),
 -                           row(1, 2, 2, 6, 12));
 -
 -                assertRowsNet(executeNetWithPaging("SELECT * FROM %s WHERE a = 1 GROUP BY a, b LIMIT 1", pageSize),
 -                           row(1, 2, 1, 3, 6));
 -
 -                // Single partition queries with wildcard and with PER PARTITION LIMIT
 -                assertRowsNet(executeNetWithPaging("SELECT * FROM %s WHERE a = 1 GROUP BY a, b, c PER PARTITION LIMIT 2", pageSize),
 -                           row(1, 2, 1, 3, 6),
 -                           row(1, 2, 2, 6, 12));
 -
 -                assertRowsNet(executeNetWithPaging("SELECT * FROM %s WHERE a = 1 GROUP BY a, b PER PARTITION LIMIT 1", pageSize),
 -                           row(1, 2, 1, 3, 6));
 -
 -                // Single partition query with PER PARTITION LIMIT
 -                assertRowsNet(executeNetWithPaging("SELECT a, b, e, count(b), max(e) FROM %s WHERE a = 1 GROUP BY a, b, c PER PARTITION LIMIT 2",
 -                                                   pageSize),
 -                              row(1, 2, 6, 1L, 6),
 -                              row(1, 2, 12, 1L, 12));
 -
 -                // Single partition queries without aggregates and with LIMIT
 -                assertRowsNet(executeNetWithPaging("SELECT a, b, c, d FROM %s WHERE a = 1 GROUP BY a, b LIMIT 2",
 -                                                   pageSize),
 -                              row(1, 2, 1, 3),
 -                              row(1, 4, 2, 6));
 -
 -                assertRowsNet(executeNetWithPaging("SELECT a, b, c, d FROM %s WHERE a = 1 GROUP BY a, b LIMIT 1",
 -                                                   pageSize),
 -                              row(1, 2, 1, 3));
 -
 -                assertRowsNet(executeNetWithPaging("SELECT a, b, c, d FROM %s WHERE a = 1 GROUP BY a, b, c LIMIT 2",
 -                                                   pageSize),
 -                              row(1, 2, 1, 3),
 -                              row(1, 2, 2, 6));
 -
 -                // Single partition queries with ORDER BY
 -                assertRowsNet(executeNetWithPaging("SELECT a, b, e, count(b), max(e) FROM %s WHERE a = 1 GROUP BY a, b, c ORDER BY b DESC, c DESC",
 -                                                   pageSize),
 -                              row(1, 4, 24, 2L, 24),
 -                              row(1, 2, 12, 1L, 12),
 -                              row(1, 2, 6, 1L, 6));
 -
 -                assertRowsNet(executeNetWithPaging("SELECT a, b, e, count(b), max(e) FROM %s WHERE a = 1 ORDER BY b DESC, c DESC",
 -                                                   pageSize),
 -                              row(1, 4, 24, 4L, 24));
 -
 -                // Single partition queries with ORDER BY and LIMIT
 -                assertRowsNet(executeNetWithPaging("SELECT a, b, e, count(b), max(e) FROM %s WHERE a = 1 GROUP BY a, b, c ORDER BY b DESC, c DESC LIMIT 2",
 -                                                   pageSize),
 -                              row(1, 4, 24, 2L, 24),
 -                              row(1, 2, 12, 1L, 12));
 -
 -                assertRowsNet(executeNetWithPaging("SELECT a, b, e, count(b), max(e) FROM %s WHERE a = 1 ORDER BY b DESC, c DESC LIMIT 2",
 -                                                   pageSize),
 -                              row(1, 4, 24, 4L, 24));
 -
 -                // Single partition queries with ORDER BY and PER PARTITION LIMIT
 -                assertRowsNet(executeNetWithPaging("SELECT a, b, e, count(b), max(e) FROM %s WHERE a = 1 GROUP BY a, b, c ORDER BY b DESC, c DESC PER PARTITION LIMIT 2",
 -                                                   pageSize),
 -                              row(1, 4, 24, 2L, 24),
 -                              row(1, 2, 12, 1L, 12));
 -
 -                // Multi-partitions queries
 -                assertRowsNet(executeNetWithPaging("SELECT a, b, e, count(b), max(e) FROM %s WHERE a IN (1, 2, 4) GROUP BY a, b, c",
 -                                                   pageSize),
 -                              row(1, 2, 6, 1L, 6),
 -                              row(1, 2, 12, 1L, 12),
 -                              row(1, 4, 12, 2L, 24),
 -                              row(2, 2, 6, 1L, 6),
 -                              row(2, 4, 12, 1L, 12),
 -                              row(4, 8, 24, 1L, 24));
 -
 -                assertRowsNet(executeNetWithPaging("SELECT a, b, e, count(b), max(e) FROM %s WHERE a IN (1, 2, 4)",
 -                                                   pageSize),
 -                              row(1, 2, 6, 7L, 24));
 -
 -                assertRowsNet(executeNetWithPaging("SELECT a, b, e, count(b), max(e) FROM %s WHERE a IN (1, 2, 4) AND b = 2 GROUP BY a, b, c",
 -                                                   pageSize),
 -                              row(1, 2, 6, 1L, 6),
 -                              row(1, 2, 12, 1L, 12),
 -                              row(2, 2, 6, 1L, 6));
 -
 -                assertRowsNet(executeNetWithPaging("SELECT a, b, e, count(b), max(e) FROM %s WHERE a IN (1, 2, 4) AND b = 2",
 -                                                   pageSize),
 -                              row(1, 2, 6, 3L, 12));
 -
 -                // Multi-partitions queries with PER PARTITION LIMIT
 -                assertRowsNet(executeNetWithPaging("SELECT a, b, e, count(b), max(e) FROM %s WHERE a IN (1, 2, 4) GROUP BY a, b, c PER PARTITION LIMIT 2",
 -                                                   pageSize),
 -                              row(1, 2, 6, 1L, 6),
 -                              row(1, 2, 12, 1L, 12),
 -                              row(2, 2, 6, 1L, 6),
 -                              row(2, 4, 12, 1L, 12),
 -                              row(4, 8, 24, 1L, 24));
 -
 -                assertRowsNet(executeNetWithPaging("SELECT a, b, e, count(b), max(e) FROM %s WHERE a IN (1, 2, 4) GROUP BY a, b, c PER PARTITION LIMIT 1",
 -                                                   pageSize),
 -                              row(1, 2, 6, 1L, 6),
 -                              row(2, 2, 6, 1L, 6),
 -                              row(4, 8, 24, 1L, 24));
 -
 -                // Multi-partitions queries without aggregates
 -                assertRowsNet(executeNetWithPaging("SELECT a, b, c, d FROM %s WHERE a IN (1, 2, 4) GROUP BY a, b",
 -                                                   pageSize),
 -                              row(1, 2, 1, 3),
 -                              row(1, 4, 2, 6),
 -                              row(2, 2, 3, 3),
 -                              row(2, 4, 3, 6),
 -                              row(4, 8, 2, 12));
 -
 -                assertRowsNet(executeNetWithPaging("SELECT a, b, c, d FROM %s WHERE a IN (1, 2, 4) GROUP BY a, b, c",
 -                                                   pageSize),
 -                              row(1, 2, 1, 3),
 -                              row(1, 2, 2, 6),
 -                              row(1, 4, 2, 6),
 -                              row(2, 2, 3, 3),
 -                              row(2, 4, 3, 6),
 -                              row(4, 8, 2, 12));
 -
 -                // Multi-partitions with wildcard
 -                assertRowsNet(executeNetWithPaging("SELECT * FROM %s WHERE a IN (1, 2, 4) GROUP BY a, b, c", pageSize),
 -                           row(1, 2, 1, 3, 6),
 -                           row(1, 2, 2, 6, 12),
 -                           row(1, 4, 2, 6, 12),
 -                           row(2, 2, 3, 3, 6),
 -                           row(2, 4, 3, 6, 12),
 -                           row(4, 8, 2, 12, 24));
 -
 -                assertRowsNet(executeNetWithPaging("SELECT * FROM %s WHERE a IN (1, 2, 4) GROUP BY a, b", pageSize),
 -                           row(1, 2, 1, 3, 6),
 -                           row(1, 4, 2, 6, 12),
 -                           row(2, 2, 3, 3, 6),
 -                           row(2, 4, 3, 6, 12),
 -                           row(4, 8, 2, 12, 24));
 -
 -                // Multi-partitions queries with DISTINCT
 -                assertRowsNet(executeNetWithPaging("SELECT DISTINCT a, count(a)FROM %s WHERE a IN (1, 2, 4) GROUP BY a",
 -                                                   pageSize),
 -                              row(1, 1L),
 -                              row(2, 1L),
 -                              row(4, 1L));
 -
 -                assertRowsNet(executeNetWithPaging("SELECT DISTINCT a, count(a)FROM %s WHERE a IN (1, 2, 4)",
 -                                                   pageSize),
 -                              row(1, 3L));
 -
 -                // Multi-partitions query with DISTINCT and LIMIT
 -                assertRowsNet(executeNetWithPaging("SELECT DISTINCT a, count(a)FROM %s WHERE a IN (1, 2, 4) GROUP BY a LIMIT 2",
 -                                                   pageSize),
 -                              row(1, 1L),
 -                              row(2, 1L));
 -
 -                assertRowsNet(executeNetWithPaging("SELECT DISTINCT a, count(a)FROM %s WHERE a IN (1, 2, 4) LIMIT 2",
 -                                                   pageSize),
 -                              row(1, 3L));
 -            }
 +            // Range queries
 +            assertRowsNet(executeNetWithPaging("SELECT a, b, e, count(b), max(e) FROM %s GROUP BY a", pageSize),
 +                          row(1, 2, 6, 4L, 24),
 +                          row(2, 2, 6, 2L, 12),
 +                          row(4, 8, 24, 1L, 24));
 +
 +            assertRowsNet(executeNetWithPaging("SELECT a, b, e, count(b), max(e) FROM %s GROUP BY a, b", pageSize),
 +                          row(1, 2, 6, 2L, 12),
 +                          row(1, 4, 12, 2L, 24),
 +                          row(2, 2, 6, 1L, 6),
 +                          row(2, 4, 12, 1L, 12),
 +                          row(4, 8, 24, 1L, 24));
 +
 +            assertRowsNet(executeNetWithPaging("SELECT a, b, e, count(b), max(e) FROM %s", pageSize),
 +                          row(1, 2, 6, 7L, 24));
 +
 +            assertRowsNet(executeNetWithPaging("SELECT a, b, e, count(b), max(e) FROM %s WHERE b = 2 GROUP BY a, b ALLOW FILTERING",
 +                                               pageSize),
 +                          row(1, 2, 6, 2L, 12),
 +                          row(2, 2, 6, 1L, 6));
 +
 +            assertRowsNet(executeNetWithPaging("SELECT a, b, e, count(b), max(e) FROM %s WHERE b = 2 ALLOW FILTERING",
 +                                               pageSize),
 +                          row(1, 2, 6, 3L, 12));
 +
 +            // Range queries without aggregates
 +            assertRowsNet(executeNetWithPaging("SELECT a, b, c, d FROM %s GROUP BY a, b, c", pageSize),
 +                          row(1, 2, 1, 3),
 +                          row(1, 2, 2, 6),
 +                          row(1, 4, 2, 6),
 +                          row(2, 2, 3, 3),
 +                          row(2, 4, 3, 6),
 +                          row(4, 8, 2, 12));
 +
 +            assertRowsNet(executeNetWithPaging("SELECT a, b, c, d FROM %s GROUP BY a, b", pageSize),
 +                          row(1, 2, 1, 3),
 +                          row(1, 4, 2, 6),
 +                          row(2, 2, 3, 3),
 +                          row(2, 4, 3, 6),
 +                          row(4, 8, 2, 12));
 +
++            // Range queries with wildcard
++            assertRowsNet(executeNetWithPaging("SELECT * FROM %s GROUP BY a, b, c", pageSize),
++                          row(1, 2, 1, 3, 6),
++                          row(1, 2, 2, 6, 12),
++                          row(1, 4, 2, 6, 12),
++                          row(2, 2, 3, 3, 6),
++                          row(2, 4, 3, 6, 12),
++                          row(4, 8, 2, 12, 24));
++
++            assertRowsNet(executeNetWithPaging("SELECT * FROM %s GROUP BY a, b", pageSize),
++                          row(1, 2, 1, 3, 6),
++                          row(1, 4, 2, 6, 12),
++                          row(2, 2, 3, 3, 6),
++                          row(2, 4, 3, 6, 12),
++                          row(4, 8, 2, 12, 24));
++
 +            // Range query with LIMIT
 +            assertRowsNet(executeNetWithPaging("SELECT a, b, e, count(b), max(e) FROM %s GROUP BY a, b LIMIT 2",
 +                                               pageSize),
 +                          row(1, 2, 6, 2L, 12),
 +                          row(1, 4, 12, 2L, 24));
 +
 +            assertRowsNet(executeNetWithPaging("SELECT a, b, e, count(b), max(e) FROM %s LIMIT 2",
 +                                               pageSize),
 +                          row(1, 2, 6, 7L, 24));
 +
 +            // Range queries with PER PARTITION LIMIT
 +            assertRowsNet(executeNetWithPaging("SELECT a, b, e, count(b), max(e) FROM %s GROUP BY a, b PER PARTITION LIMIT 3", pageSize),
 +                          row(1, 2, 6, 2L, 12),
 +                          row(1, 4, 12, 2L, 24),
 +                          row(2, 2, 6, 1L, 6),
 +                          row(2, 4, 12, 1L, 12),
 +                          row(4, 8, 24, 1L, 24));
 +
 +            assertRowsNet(executeNetWithPaging("SELECT a, b, e, count(b), max(e) FROM %s GROUP BY a, b PER PARTITION LIMIT 1", pageSize),
 +                          row(1, 2, 6, 2L, 12),
 +                          row(2, 2, 6, 1L, 6),
 +                          row(4, 8, 24, 1L, 24));
 +
 +            // Range query with PER PARTITION LIMIT
 +            assertRowsNet(executeNetWithPaging("SELECT a, b, e, count(b), max(e) FROM %s GROUP BY a, b PER PARTITION LIMIT 1 LIMIT 2", pageSize),
 +                          row(1, 2, 6, 2L, 12),
 +                          row(2, 2, 6, 1L, 6));
 +
 +            // Range query without aggregates and with PER PARTITION LIMIT
 +            assertRowsNet(executeNetWithPaging("SELECT a, b, c, d FROM %s GROUP BY a, b, c PER PARTITION LIMIT 2", pageSize),
 +                          row(1, 2, 1, 3),
 +                          row(1, 2, 2, 6),
 +                          row(2, 2, 3, 3),
 +                          row(2, 4, 3, 6),
 +                          row(4, 8, 2, 12));
 +
 +            // Range queries without aggregates and with LIMIT
 +            assertRowsNet(executeNetWithPaging("SELECT a, b, c, d FROM %s GROUP BY a, b, c LIMIT 3", pageSize),
 +                          row(1, 2, 1, 3),
 +                          row(1, 2, 2, 6),
 +                          row(1, 4, 2, 6));
 +
 +            assertRowsNet(executeNetWithPaging("SELECT a, b, c, d FROM %s GROUP BY a, b LIMIT 3", pageSize),
 +                          row(1, 2, 1, 3),
 +                          row(1, 4, 2, 6),
 +                          row(2, 2, 3, 3));
 +
 +            // Range query without aggregates, with PER PARTITION LIMIT and with LIMIT
 +            assertRowsNet(executeNetWithPaging("SELECT a, b, c, d FROM %s GROUP BY a, b, c PER PARTITION LIMIT 2 LIMIT 3", pageSize),
 +                          row(1, 2, 1, 3),
 +                          row(1, 2, 2, 6),
 +                          row(2, 2, 3, 3));
 +
++            // Range queries with wildcard and with LIMIT
++            assertRowsNet(executeNetWithPaging("SELECT * FROM %s GROUP BY a, b, c LIMIT 3", pageSize),
++                          row(1, 2, 1, 3, 6),
++                          row(1, 2, 2, 6, 12),
++                          row(1, 4, 2, 6, 12));
++
++            assertRowsNet(executeNetWithPaging("SELECT * FROM %s GROUP BY a, b LIMIT 3", pageSize),
++                          row(1, 2, 1, 3, 6),
++                          row(1, 4, 2, 6, 12),
++                          row(2, 2, 3, 3, 6));
++
++            // Range queries with wildcard and with PER PARTITION LIMIT
++            assertRowsNet(executeNetWithPaging("SELECT * FROM %s GROUP BY a, b, c PER PARTITION LIMIT 2", pageSize),
++                          row(1, 2, 1, 3, 6),
++                          row(1, 2, 2, 6, 12),
++                          row(2, 2, 3, 3, 6),
++                          row(2, 4, 3, 6, 12),
++                          row(4, 8, 2, 12, 24));
++
++            assertRowsNet(executeNetWithPaging("SELECT * FROM %s GROUP BY a, b PER PARTITION LIMIT 1", pageSize),
++                          row(1, 2, 1, 3, 6),
++                          row(2, 2, 3, 3, 6),
++                          row(4, 8, 2, 12, 24));
++
++            // Range queries with wildcard, with PER PARTITION LIMIT and LIMIT
++            assertRowsNet(executeNetWithPaging("SELECT * FROM %s GROUP BY a, b, c PER PARTITION LIMIT 2 LIMIT 3", pageSize),
++                          row(1, 2, 1, 3, 6),
++                          row(1, 2, 2, 6, 12),
++                          row(2, 2, 3, 3, 6));
++
 +            // Range query with DISTINCT
 +            assertRowsNet(executeNetWithPaging("SELECT DISTINCT a, count(a)FROM %s GROUP BY a", pageSize),
 +                          row(1, 1L),
 +                          row(2, 1L),
 +                          row(4, 1L));
 +
 +            assertRowsNet(executeNetWithPaging("SELECT DISTINCT a, count(a)FROM %s", pageSize),
 +                          row(1, 3L));
 +
 +            // Range query with DISTINCT and LIMIT
 +            assertRowsNet(executeNetWithPaging("SELECT DISTINCT a, count(a)FROM %s GROUP BY a LIMIT 2", pageSize),
 +                          row(1, 1L),
 +                          row(2, 1L));
 +
 +            assertRowsNet(executeNetWithPaging("SELECT DISTINCT a, count(a)FROM %s LIMIT 2", pageSize),
 +                          row(1, 3L));
 +
 +            // Range query with ORDER BY
 +            assertInvalidMessage("ORDER BY is only supported when the partition key is restricted by an EQ or an IN",
 +                                 "SELECT a, b, c, count(b), max(e) FROM %s GROUP BY a, b ORDER BY b DESC, c DESC");
 +
 +            // Single partition queries
 +            assertRowsNet(executeNetWithPaging("SELECT a, b, e, count(b), max(e) FROM %s WHERE a = 1 GROUP BY a, b, c",
 +                                               pageSize),
 +                          row(1, 2, 6, 1L, 6),
 +                          row(1, 2, 12, 1L, 12),
 +                          row(1, 4, 12, 2L, 24));
 +
 +            assertRowsNet(executeNetWithPaging("SELECT a, b, e, count(b), max(e) FROM %s WHERE a = 1", pageSize),
 +                          row(1, 2, 6, 4L, 24));
 +
 +            assertRowsNet(executeNetWithPaging("SELECT a, b, e, count(b), max(e) FROM %s WHERE a = 1 AND b = 2 GROUP BY a, b, c",
 +                                               pageSize),
 +                          row(1, 2, 6, 1L, 6),
 +                          row(1, 2, 12, 1L, 12));
 +
 +            assertRowsNet(executeNetWithPaging("SELECT a, b, e, count(b), max(e) FROM %s WHERE a = 1 AND b = 2",
 +                                               pageSize),
 +                          row(1, 2, 6, 2L, 12));
 +
 +            // Single partition queries without aggregates
 +            assertRowsNet(executeNetWithPaging("SELECT a, b, c, d FROM %s WHERE a = 1 GROUP BY a, b", pageSize),
 +                          row(1, 2, 1, 3),
 +                          row(1, 4, 2, 6));
 +
 +            assertRowsNet(executeNetWithPaging("SELECT a, b, c, d FROM %s WHERE a = 1 GROUP BY a, b, c", pageSize),
 +                          row(1, 2, 1, 3),
 +                          row(1, 2, 2, 6),
 +                          row(1, 4, 2, 6));
 +
++            // Single partition queries with wildcard
++            assertRowsNet(executeNetWithPaging("SELECT * FROM %s WHERE a = 1 GROUP BY a, b, c", pageSize),
++                       row(1, 2, 1, 3, 6),
++                       row(1, 2, 2, 6, 12),
++                       row(1, 4, 2, 6, 12));
++
++            assertRowsNet(executeNetWithPaging("SELECT * FROM %s WHERE a = 1 GROUP BY a, b", pageSize),
++                       row(1, 2, 1, 3, 6),
++                       row(1, 4, 2, 6, 12));
++
 +            // Single partition query with DISTINCT
 +            assertRowsNet(executeNetWithPaging("SELECT DISTINCT a, count(a)FROM %s WHERE a = 1 GROUP BY a",
 +                                               pageSize),
 +                          row(1, 1L));
 +
 +            assertRowsNet(executeNetWithPaging("SELECT DISTINCT a, count(a)FROM %s WHERE a = 1 GROUP BY a",
 +                                               pageSize),
 +                          row(1, 1L));
 +
 +            // Single partition queries with LIMIT
 +            assertRowsNet(executeNetWithPaging("SELECT a, b, e, count(b), max(e) FROM %s WHERE a = 1 GROUP BY a, b, c LIMIT 10",
 +                                               pageSize),
 +                          row(1, 2, 6, 1L, 6),
 +                          row(1, 2, 12, 1L, 12),
 +                          row(1, 4, 12, 2L, 24));
 +
 +            assertRowsNet(executeNetWithPaging("SELECT a, b, e, count(b), max(e) FROM %s WHERE a = 1 GROUP BY a, b, c LIMIT 2",
 +                                               pageSize),
 +                          row(1, 2, 6, 1L, 6),
 +                          row(1, 2, 12, 1L, 12));
 +
 +            assertRowsNet(executeNetWithPaging("SELECT a, b, e, count(b), max(e) FROM %s WHERE a = 1 LIMIT 2",
 +                                               pageSize),
 +                          row(1, 2, 6, 4L, 24));
 +
 +            assertRowsNet(executeNetWithPaging("SELECT count(b), max(e) FROM %s WHERE a = 1 GROUP BY a, b, c LIMIT 1",
 +                                               pageSize),
 +                          row(1L, 6));
 +
 +            // Single partition query with PER PARTITION LIMIT
 +            assertRowsNet(executeNetWithPaging("SELECT a, b, e, count(b), max(e) FROM %s WHERE a = 1 GROUP BY a, b, c PER PARTITION LIMIT 2",
 +                                               pageSize),
 +                          row(1, 2, 6, 1L, 6),
 +                          row(1, 2, 12, 1L, 12));
 +
 +            // Single partition queries without aggregates and with LIMIT
 +            assertRowsNet(executeNetWithPaging("SELECT a, b, c, d FROM %s WHERE a = 1 GROUP BY a, b LIMIT 2",
 +                                               pageSize),
 +                          row(1, 2, 1, 3),
 +                          row(1, 4, 2, 6));
 +
 +            assertRowsNet(executeNetWithPaging("SELECT a, b, c, d FROM %s WHERE a = 1 GROUP BY a, b LIMIT 1",
 +                                               pageSize),
 +                          row(1, 2, 1, 3));
 +
 +            assertRowsNet(executeNetWithPaging("SELECT a, b, c, d FROM %s WHERE a = 1 GROUP BY a, b, c LIMIT 2",
 +                                               pageSize),
 +                          row(1, 2, 1, 3),
 +                          row(1, 2, 2, 6));
 +
++            // Single partition queries with wildcard and with LIMIT
++            assertRowsNet(executeNetWithPaging("SELECT * FROM %s WHERE a = 1 GROUP BY a, b, c LIMIT 2", pageSize),
++                       row(1, 2, 1, 3, 6),
++                       row(1, 2, 2, 6, 12));
++
++            assertRowsNet(executeNetWithPaging("SELECT * FROM %s WHERE a = 1 GROUP BY a, b LIMIT 1", pageSize),
++                       row(1, 2, 1, 3, 6));
++
++            // Single partition queries with wildcard and with PER PARTITION LIMIT
++            assertRowsNet(executeNetWithPaging("SELECT * FROM %s WHERE a = 1 GROUP BY a, b, c PER PARTITION LIMIT 2", pageSize),
++                       row(1, 2, 1, 3, 6),
++                       row(1, 2, 2, 6, 12));
++
++            assertRowsNet(executeNetWithPaging("SELECT * FROM %s WHERE a = 1 GROUP BY a, b PER PARTITION LIMIT 1", pageSize),
++                       row(1, 2, 1, 3, 6));
++
 +            // Single partition queries with ORDER BY
 +            assertRowsNet(executeNetWithPaging("SELECT a, b, e, count(b), max(e) FROM %s WHERE a = 1 GROUP BY a, b, c ORDER BY b DESC, c DESC",
 +                                               pageSize),
 +                          row(1, 4, 24, 2L, 24),
 +                          row(1, 2, 12, 1L, 12),
 +                          row(1, 2, 6, 1L, 6));
 +
 +            assertRowsNet(executeNetWithPaging("SELECT a, b, e, count(b), max(e) FROM %s WHERE a = 1 ORDER B

<TRUNCATED>

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org
For additional commands, e-mail: commits-help@cassandra.apache.org


[2/4] cassandra git commit: Fix wildcard GROUP BY queries

Posted by bl...@apache.org.
Fix wildcard GROUP BY queries

patch by Benjamin Lerer; reviewed by Andrés de la Peña for CASSANDRA-14209


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/515f07b5
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/515f07b5
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/515f07b5

Branch: refs/heads/trunk
Commit: 515f07b5ac75b15015401e89c379b29c788ba5a3
Parents: 630c18e
Author: Benjamin Lerer <b....@gmail.com>
Authored: Thu Feb 15 10:59:28 2018 +0100
Committer: Benjamin Lerer <b....@gmail.com>
Committed: Thu Feb 15 10:59:28 2018 +0100

----------------------------------------------------------------------
 CHANGES.txt                                     |   1 +
 .../cassandra/cql3/selection/Selection.java     |  12 +
 .../cql3/statements/SelectStatement.java        |  21 +-
 .../cql3/validation/entities/JsonTest.java      |  25 ++
 .../operations/SelectGroupByTest.java           | 345 +++++++++++++++++++
 5 files changed, 401 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/515f07b5/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index fdf045d..e858781 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 3.11.3
+ * Fix wildcard GROUP BY queries (CASSANDRA-14209)
 Merged from 2.1
  * CVE-2017-5929 Security vulnerability in Logback warning in NEWS.txt (CASSANDRA-14183)
 

http://git-wip-us.apache.org/repos/asf/cassandra/blob/515f07b5/src/java/org/apache/cassandra/cql3/selection/Selection.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/selection/Selection.java b/src/java/org/apache/cassandra/cql3/selection/Selection.java
index 5e7c6e3..93a71b8 100644
--- a/src/java/org/apache/cassandra/cql3/selection/Selection.java
+++ b/src/java/org/apache/cassandra/cql3/selection/Selection.java
@@ -147,6 +147,18 @@ public abstract class Selection
         return new SimpleSelection(cfm, all, true);
     }
 
+    public static Selection wildcardWithGroupBy(CFMetaData cfm, VariableSpecifications boundNames)
+    {
+        List<RawSelector> rawSelectors = new ArrayList<>(cfm.allColumns().size());
+        Iterator<ColumnDefinition> iter = cfm.allColumnsInSelectOrder();
+        while (iter.hasNext())
+        {
+            ColumnDefinition.Raw raw = ColumnDefinition.Raw.forColumn(iter.next());
+            rawSelectors.add(new RawSelector(raw, null));
+        }
+        return fromSelectors(cfm, rawSelectors, boundNames, true);
+    }
+
     public static Selection forColumns(CFMetaData cfm, List<ColumnDefinition> columns)
     {
         return new SimpleSelection(cfm, columns, false);

http://git-wip-us.apache.org/repos/asf/cassandra/blob/515f07b5/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java b/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
index d86a47d..a7ba6aa 100644
--- a/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
@@ -958,9 +958,7 @@ public class SelectStatement implements CQLStatement
             CFMetaData cfm = ThriftValidation.validateColumnFamilyWithCompactMode(keyspace(), columnFamily(), clientState.isNoCompactMode());
             VariableSpecifications boundNames = getBoundVariables();
 
-            Selection selection = selectClause.isEmpty()
-                                  ? Selection.wildcard(cfm)
-                                  : Selection.fromSelectors(cfm, selectClause, boundNames, !parameters.groups.isEmpty());
+            Selection selection = prepareSelection(cfm, boundNames);
 
             StatementRestrictions restrictions = prepareRestrictions(cfm, boundNames, selection, forView);
 
@@ -1008,6 +1006,23 @@ public class SelectStatement implements CQLStatement
         }
 
         /**
+         * Prepares the selection to use for the statement.
+         *
+         * @param cfm the table metadata
+         * @param boundNames the bound names
+         * @return the selection to use for the statement
+         */
+        private Selection prepareSelection(CFMetaData cfm, VariableSpecifications boundNames)
+        {
+            boolean hasGroupBy = !parameters.groups.isEmpty();
+
+            if (selectClause.isEmpty())
+                return hasGroupBy ? Selection.wildcardWithGroupBy(cfm, boundNames) : Selection.wildcard(cfm);
+
+            return Selection.fromSelectors(cfm, selectClause, boundNames, hasGroupBy);
+        }
+
+        /**
          * Prepares the restrictions.
          *
          * @param cfm the column family meta data

http://git-wip-us.apache.org/repos/asf/cassandra/blob/515f07b5/test/unit/org/apache/cassandra/cql3/validation/entities/JsonTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/validation/entities/JsonTest.java b/test/unit/org/apache/cassandra/cql3/validation/entities/JsonTest.java
index 2bd95be..2728237 100644
--- a/test/unit/org/apache/cassandra/cql3/validation/entities/JsonTest.java
+++ b/test/unit/org/apache/cassandra/cql3/validation/entities/JsonTest.java
@@ -935,6 +935,31 @@ public class JsonTest extends CQLTester
     }
 
     @Test
+    public void testJsonWithGroupBy() throws Throwable
+    {
+        // tests SELECT JSON statements
+        createTable("CREATE TABLE %s (k int, c int, v int, PRIMARY KEY (k, c))");
+        execute("INSERT INTO %s (k, c, v) VALUES (0, 0, 0)");
+        execute("INSERT INTO %s (k, c, v) VALUES (0, 1, 1)");
+        execute("INSERT INTO %s (k, c, v) VALUES (1, 0, 1)");
+
+        assertRows(execute("SELECT JSON * FROM %s GROUP BY k"),
+                   row("{\"k\": 0, \"c\": 0, \"v\": 0}"),
+                   row("{\"k\": 1, \"c\": 0, \"v\": 1}")
+        );
+
+        assertRows(execute("SELECT JSON k, c, v FROM %s GROUP BY k"),
+                   row("{\"k\": 0, \"c\": 0, \"v\": 0}"),
+                   row("{\"k\": 1, \"c\": 0, \"v\": 1}")
+        );
+
+        assertRows(execute("SELECT JSON count(*) FROM %s GROUP BY k"),
+                row("{\"count\": 2}"),
+                row("{\"count\": 1}")
+        );
+    }
+
+    @Test
     public void testSelectJsonSyntax() throws Throwable
     {
         // tests SELECT JSON statements

http://git-wip-us.apache.org/repos/asf/cassandra/blob/515f07b5/test/unit/org/apache/cassandra/cql3/validation/operations/SelectGroupByTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/validation/operations/SelectGroupByTest.java b/test/unit/org/apache/cassandra/cql3/validation/operations/SelectGroupByTest.java
index b41b81f..5c51494 100644
--- a/test/unit/org/apache/cassandra/cql3/validation/operations/SelectGroupByTest.java
+++ b/test/unit/org/apache/cassandra/cql3/validation/operations/SelectGroupByTest.java
@@ -80,6 +80,22 @@ public class SelectGroupByTest extends CQLTester
                        row(2, 4, 3, 6),
                        row(4, 8, 2, 12));
 
+            // Range queries with wildcard
+            assertRows(execute("SELECT * FROM %s GROUP BY a, b, c"),
+                       row(1, 2, 1, 3, 6),
+                       row(1, 2, 2, 6, 12),
+                       row(1, 4, 2, 6, 12),
+                       row(2, 2, 3, 3, 6),
+                       row(2, 4, 3, 6, 12),
+                       row(4, 8, 2, 12, 24));
+
+            assertRows(execute("SELECT * FROM %s GROUP BY a, b"),
+                       row(1, 2, 1, 3, 6),
+                       row(1, 4, 2, 6, 12),
+                       row(2, 2, 3, 3, 6),
+                       row(2, 4, 3, 6, 12),
+                       row(4, 8, 2, 12, 24));
+
             // Range query with LIMIT
             assertRows(execute("SELECT a, b, e, count(b), max(e) FROM %s GROUP BY a, b LIMIT 2"),
                        row(1, 2, 6, 2L, 12),
@@ -117,6 +133,17 @@ public class SelectGroupByTest extends CQLTester
                        row(1, 4, 2, 6),
                        row(2, 2, 3, 3));
 
+            // Range queries with wildcard and with LIMIT
+            assertRows(execute("SELECT * FROM %s GROUP BY a, b, c LIMIT 3"),
+                       row(1, 2, 1, 3, 6),
+                       row(1, 2, 2, 6, 12),
+                       row(1, 4, 2, 6, 12));
+
+            assertRows(execute("SELECT * FROM %s GROUP BY a, b LIMIT 3"),
+                       row(1, 2, 1, 3, 6),
+                       row(1, 4, 2, 6, 12),
+                       row(2, 2, 3, 3, 6));
+
             // Range queries without aggregates and with PER PARTITION LIMIT
             assertRows(execute("SELECT a, b, c, d FROM %s GROUP BY a, b, c PER PARTITION LIMIT 2"),
                        row(1, 2, 1, 3),
@@ -130,12 +157,31 @@ public class SelectGroupByTest extends CQLTester
                        row(2, 2, 3, 3),
                        row(4, 8, 2, 12));
 
+            // Range queries with wildcard and with PER PARTITION LIMIT
+            assertRows(execute("SELECT * FROM %s GROUP BY a, b, c PER PARTITION LIMIT 2"),
+                       row(1, 2, 1, 3, 6),
+                       row(1, 2, 2, 6, 12),
+                       row(2, 2, 3, 3, 6),
+                       row(2, 4, 3, 6, 12),
+                       row(4, 8, 2, 12, 24));
+
+            assertRows(execute("SELECT * FROM %s GROUP BY a, b PER PARTITION LIMIT 1"),
+                       row(1, 2, 1, 3, 6),
+                       row(2, 2, 3, 3, 6),
+                       row(4, 8, 2, 12, 24));
+
             // Range queries without aggregates, with PER PARTITION LIMIT and LIMIT
             assertRows(execute("SELECT a, b, c, d FROM %s GROUP BY a, b, c PER PARTITION LIMIT 2 LIMIT 3"),
                        row(1, 2, 1, 3),
                        row(1, 2, 2, 6),
                        row(2, 2, 3, 3));
 
+            // Range queries with wildcard, with PER PARTITION LIMIT and LIMIT
+            assertRows(execute("SELECT * FROM %s GROUP BY a, b, c PER PARTITION LIMIT 2 LIMIT 3"),
+                       row(1, 2, 1, 3, 6),
+                       row(1, 2, 2, 6, 12),
+                       row(2, 2, 3, 3, 6));
+
             // Range query with DISTINCT
             assertRows(execute("SELECT DISTINCT a, count(a)FROM %s GROUP BY a"),
                        row(1, 1L),
@@ -200,6 +246,16 @@ public class SelectGroupByTest extends CQLTester
                        row(1, 2, 2, 6),
                        row(1, 4, 2, 6));
 
+            // Single partition queries with wildcard
+            assertRows(execute("SELECT * FROM %s WHERE a = 1 GROUP BY a, b, c"),
+                       row(1, 2, 1, 3, 6),
+                       row(1, 2, 2, 6, 12),
+                       row(1, 4, 2, 6, 12));
+
+            assertRows(execute("SELECT * FROM %s WHERE a = 1 GROUP BY a, b"),
+                       row(1, 2, 1, 3, 6),
+                       row(1, 4, 2, 6, 12));
+
             // Single partition queries with DISTINCT
             assertRows(execute("SELECT DISTINCT a, count(a)FROM %s WHERE a = 1 GROUP BY a"),
                        row(1, 1L));
@@ -245,6 +301,14 @@ public class SelectGroupByTest extends CQLTester
                        row(1, 2, 1, 3),
                        row(1, 2, 2, 6));
 
+            // Single partition queries with wildcard and with LIMIT
+            assertRows(execute("SELECT * FROM %s WHERE a = 1 GROUP BY a, b, c LIMIT 2"),
+                       row(1, 2, 1, 3, 6),
+                       row(1, 2, 2, 6, 12));
+
+            assertRows(execute("SELECT * FROM %s WHERE a = 1 GROUP BY a, b LIMIT 1"),
+                       row(1, 2, 1, 3, 6));
+
             // Single partition queries without aggregates and with PER PARTITION LIMIT
             assertRows(execute("SELECT a, b, c, d FROM %s WHERE a = 1 GROUP BY a, b PER PARTITION LIMIT 2"),
                        row(1, 2, 1, 3),
@@ -257,6 +321,14 @@ public class SelectGroupByTest extends CQLTester
                        row(1, 2, 1, 3),
                        row(1, 2, 2, 6));
 
+            // Single partition queries with wildcard and with PER PARTITION LIMIT
+            assertRows(execute("SELECT * FROM %s WHERE a = 1 GROUP BY a, b, c PER PARTITION LIMIT 2"),
+                       row(1, 2, 1, 3, 6),
+                       row(1, 2, 2, 6, 12));
+
+            assertRows(execute("SELECT * FROM %s WHERE a = 1 GROUP BY a, b PER PARTITION LIMIT 1"),
+                       row(1, 2, 1, 3, 6));
+
             // Single partition queries with ORDER BY
             assertRows(execute("SELECT a, b, e, count(b), max(e) FROM %s WHERE a = 1 GROUP BY a, b, c ORDER BY b DESC, c DESC"),
                        row(1, 4, 24, 2L, 24),
@@ -302,6 +374,22 @@ public class SelectGroupByTest extends CQLTester
                        row(2, 4, 3, 6),
                        row(4, 8, 2, 12));
 
+            // Multi-partitions with wildcard
+            assertRows(execute("SELECT * FROM %s WHERE a IN (1, 2, 4) GROUP BY a, b, c"),
+                       row(1, 2, 1, 3, 6),
+                       row(1, 2, 2, 6, 12),
+                       row(1, 4, 2, 6, 12),
+                       row(2, 2, 3, 3, 6),
+                       row(2, 4, 3, 6, 12),
+                       row(4, 8, 2, 12, 24));
+
+            assertRows(execute("SELECT * FROM %s WHERE a IN (1, 2, 4) GROUP BY a, b"),
+                       row(1, 2, 1, 3, 6),
+                       row(1, 4, 2, 6, 12),
+                       row(2, 2, 3, 3, 6),
+                       row(2, 4, 3, 6, 12),
+                       row(4, 8, 2, 12, 24));
+
             // Multi-partitions query with DISTINCT
             assertRows(execute("SELECT DISTINCT a, count(a)FROM %s WHERE a IN (1, 2, 4) GROUP BY a"),
                        row(1, 1L),
@@ -329,6 +417,19 @@ public class SelectGroupByTest extends CQLTester
                        row(2, 4, 12, 1L, 12),
                        row(4, 8, 24, 1L, 24));
 
+            // Multi-partitions with wildcard and PER PARTITION LIMIT
+            assertRows(execute("SELECT * FROM %s WHERE a IN (1, 2, 4) GROUP BY a, b, c PER PARTITION LIMIT 2"),
+                       row(1, 2, 1, 3, 6),
+                       row(1, 2, 2, 6, 12),
+                       row(2, 2, 3, 3, 6),
+                       row(2, 4, 3, 6, 12),
+                       row(4, 8, 2, 12, 24));
+
+            assertRows(execute("SELECT * FROM %s WHERE a IN (1, 2, 4) GROUP BY a, b PER PARTITION LIMIT 1"),
+                       row(1, 2, 1, 3, 6),
+                       row(2, 2, 3, 3, 6),
+                       row(4, 8, 2, 12, 24));
+
             // Multi-partitions queries with ORDER BY
             assertRows(execute("SELECT a, b, c, count(b), max(e) FROM %s WHERE a IN (1, 2, 4) GROUP BY a, b ORDER BY b DESC, c DESC"),
                        row(4, 8, 2, 1L, 24),
@@ -351,6 +452,12 @@ public class SelectGroupByTest extends CQLTester
                        row(2, 4, 3, 6),
                        row(1, 4, 2, 12));
 
+            // Multi-partitions with wildcard, ORDER BY and LIMIT
+            assertRows(execute("SELECT * FROM %s WHERE a IN (1, 2, 4) GROUP BY a, b, c ORDER BY b DESC, c DESC LIMIT 3"),
+                       row(4, 8, 2, 12, 24),
+                       row(2, 4, 3, 6, 12),
+                       row(1, 4, 2, 12, 24));
+
             // Invalid queries
             assertInvalidMessage("Group by is currently only supported on the columns of the PRIMARY KEY, got e",
                                  "SELECT a, b, d, count(b), max(c) FROM %s WHERE a = 1 GROUP BY a, e");
@@ -538,6 +645,12 @@ public class SelectGroupByTest extends CQLTester
                    row(2, null, 2),
                    row(4, null, 3));
 
+        // Range query with wildcard
+        assertRows(execute("SELECT * FROM %s GROUP BY a, b"),
+                   row(1, null, null, 1, null),
+                   row(2, null, null, 2, null),
+                   row(4, null, null, 3, null ));
+
         // Range query with LIMIT
         assertRows(execute("SELECT a, b, s, count(b), count(s) FROM %s GROUP BY a, b LIMIT 2"),
                    row(1, null, 1, 0L, 1L),
@@ -571,6 +684,10 @@ public class SelectGroupByTest extends CQLTester
         assertRows(execute("SELECT a, b, s FROM %s WHERE a = 1 GROUP BY a, b"),
                    row(1, null, 1));
 
+        // Single partition query with wildcard
+        assertRows(execute("SELECT * FROM %s WHERE a = 1 GROUP BY a, b"),
+                   row(1, null, null, 1, null));
+
         // Single partition query with LIMIT
         assertRows(execute("SELECT a, b, s, count(b), count(s) FROM %s WHERE a = 1 GROUP BY a, b LIMIT 2"),
                    row(1, null, 1, 0L, 1L));
@@ -600,6 +717,12 @@ public class SelectGroupByTest extends CQLTester
                    row(2, null, 2),
                    row(4, null, 3));
 
+        // Multi-partitions query with wildcard
+        assertRows(execute("SELECT * FROM %s WHERE a IN (1, 2, 3, 4) GROUP BY a, b"),
+                   row(1, null, null, 1, null),
+                   row(2, null, null, 2, null),
+                   row(4, null, null, 3, null ));
+
         // Multi-partitions query with LIMIT
         assertRows(execute("SELECT a, b, s, count(b), count(s) FROM %s WHERE a IN (1, 2, 3, 4) GROUP BY a, b LIMIT 2"),
                    row(1, null, 1, 0L, 1L),
@@ -676,6 +799,21 @@ public class SelectGroupByTest extends CQLTester
                    row(4, 8, null),
                    row(3, null, 3));
 
+        // Range queries with wildcard
+        assertRows(execute("SELECT * FROM %s GROUP BY a"),
+                   row(1, 2, 1, 1, 3),
+                   row(2, 2, 3, 2, 3),
+                   row(4, 8, 2, null, 12),
+                   row(3, null, null, 3, null));
+
+        assertRows(execute("SELECT * FROM %s GROUP BY a, b"),
+                   row(1, 2, 1, 1, 3),
+                   row(1, 4, 2, 1, 12),
+                   row(2, 2, 3, 2, 3),
+                   row(2, 4, 3, 2, 6),
+                   row(4, 8, 2, null, 12),
+                   row(3, null, null, 3, null));
+
         // Range query with LIMIT
         assertRows(execute("SELECT a, b, s, count(b), count(s) FROM %s GROUP BY a LIMIT 2"),
                    row(1, 2, 1, 4L, 4L),
@@ -707,6 +845,19 @@ public class SelectGroupByTest extends CQLTester
                    row(4, 8, null),
                    row(3, null, 3));
 
+        // Range queries with wildcard and with LIMIT
+        assertRows(execute("SELECT * FROM %s GROUP BY a LIMIT 2"),
+                   row(1, 2, 1, 1, 3),
+                   row(2, 2, 3, 2, 3));
+
+        assertRows(execute("SELECT * FROM %s GROUP BY a, b LIMIT 10"),
+                   row(1, 2, 1, 1, 3),
+                   row(1, 4, 2, 1, 12),
+                   row(2, 2, 3, 2, 3),
+                   row(2, 4, 3, 2, 6),
+                   row(4, 8, 2, null, 12),
+                   row(3, null, null, 3, null));
+
         // Range queries without aggregates and with PER PARTITION LIMIT
         assertRows(execute("SELECT a, b, s FROM %s GROUP BY a, b PER PARTITION LIMIT 1"),
                    row(1, 2, 1),
@@ -714,11 +865,23 @@ public class SelectGroupByTest extends CQLTester
                    row(4, 8, null),
                    row(3, null, 3));
 
+        // Range queries with wildcard and with PER PARTITION LIMIT
+        assertRows(execute("SELECT * FROM %s GROUP BY a, b PER PARTITION LIMIT 1"),
+                   row(1, 2, 1, 1, 3),
+                   row(2, 2, 3, 2, 3),
+                   row(4, 8, 2, null, 12),
+                   row(3, null, null, 3, null));
+
         // Range queries without aggregates, with PER PARTITION LIMIT and with LIMIT
         assertRows(execute("SELECT a, b, s FROM %s GROUP BY a, b PER PARTITION LIMIT 1 LIMIT 2"),
                    row(1, 2, 1),
                    row(2, 2, 2));
 
+        // Range queries with wildcard, PER PARTITION LIMIT and LIMIT
+        assertRows(execute("SELECT * FROM %s GROUP BY a, b PER PARTITION LIMIT 1 LIMIT 2"),
+                   row(1, 2, 1, 1, 3),
+                   row(2, 2, 3, 2, 3));
+
         // Range query with DISTINCT
         assertRows(execute("SELECT DISTINCT a, s, count(a), count(s) FROM %s GROUP BY a"),
                    row(1, 1, 1L, 1L),
@@ -752,6 +915,13 @@ public class SelectGroupByTest extends CQLTester
         assertRows(execute("SELECT a, b, s FROM %s WHERE a = 4 GROUP BY a, b"),
                    row(4, 8, null));
 
+        // Single partition queries with wildcard
+        assertRows(execute("SELECT * FROM %s WHERE a = 1 GROUP BY a"),
+                   row(1, 2, 1, 1, 3));
+
+        assertRows(execute("SELECT * FROM %s WHERE a = 4 GROUP BY a, b"),
+                   row(4, 8, 2, null, 12));
+
         // Single partition query with LIMIT
         assertRows(execute("SELECT a, b, s, count(b), count(s) FROM %s WHERE a = 2 GROUP BY a, b LIMIT 1"),
                    row(2, 2, 2, 1L, 1L));
@@ -822,6 +992,21 @@ public class SelectGroupByTest extends CQLTester
                    row(3, null, 3),
                    row(4, 8, null));
 
+        // Multi-partitions queries with wildcard
+        assertRows(execute("SELECT * FROM %s WHERE a IN (1, 2, 3, 4) GROUP BY a"),
+                   row(1, 2, 1, 1, 3),
+                   row(2, 2, 3, 2, 3),
+                   row(3, null, null, 3, null),
+                   row(4, 8, 2, null, 12));
+
+        assertRows(execute("SELECT * FROM %s WHERE a IN (1, 2, 3, 4) GROUP BY a, b"),
+                   row(1, 2, 1, 1, 3),
+                   row(1, 4, 2, 1, 12),
+                   row(2, 2, 3, 2, 3),
+                   row(2, 4, 3, 2, 6),
+                   row(3, null, null, 3, null),
+                   row(4, 8, 2, null, 12));
+
         // Multi-partitions query with LIMIT
         assertRows(execute("SELECT a, b, s, count(b), count(s) FROM %s WHERE a IN (1, 2, 3, 4) GROUP BY a LIMIT 2"),
                    row(1, 2, 1, 4L, 4L),
@@ -957,6 +1142,22 @@ public class SelectGroupByTest extends CQLTester
                               row(2, 4, 3, 6),
                               row(4, 8, 2, 12));
 
+                // Range queries with wildcard
+                assertRowsNet(executeNetWithPaging("SELECT * FROM %s GROUP BY a, b, c", pageSize),
+                              row(1, 2, 1, 3, 6),
+                              row(1, 2, 2, 6, 12),
+                              row(1, 4, 2, 6, 12),
+                              row(2, 2, 3, 3, 6),
+                              row(2, 4, 3, 6, 12),
+                              row(4, 8, 2, 12, 24));
+
+                assertRowsNet(executeNetWithPaging("SELECT * FROM %s GROUP BY a, b", pageSize),
+                              row(1, 2, 1, 3, 6),
+                              row(1, 4, 2, 6, 12),
+                              row(2, 2, 3, 3, 6),
+                              row(2, 4, 3, 6, 12),
+                              row(4, 8, 2, 12, 24));
+
                 // Range query with LIMIT
                 assertRowsNet(executeNetWithPaging("SELECT a, b, e, count(b), max(e) FROM %s GROUP BY a, b LIMIT 2",
                                                    pageSize),
@@ -993,6 +1194,30 @@ public class SelectGroupByTest extends CQLTester
                               row(2, 4, 3, 6),
                               row(4, 8, 2, 12));
 
+                // Range queries with wildcard and with LIMIT
+                assertRowsNet(executeNetWithPaging("SELECT * FROM %s GROUP BY a, b, c LIMIT 3", pageSize),
+                              row(1, 2, 1, 3, 6),
+                              row(1, 2, 2, 6, 12),
+                              row(1, 4, 2, 6, 12));
+
+                assertRowsNet(executeNetWithPaging("SELECT * FROM %s GROUP BY a, b LIMIT 3", pageSize),
+                              row(1, 2, 1, 3, 6),
+                              row(1, 4, 2, 6, 12),
+                              row(2, 2, 3, 3, 6));
+
+                // Range queries with wildcard and with PER PARTITION LIMIT
+                assertRowsNet(executeNetWithPaging("SELECT * FROM %s GROUP BY a, b, c PER PARTITION LIMIT 2", pageSize),
+                              row(1, 2, 1, 3, 6),
+                              row(1, 2, 2, 6, 12),
+                              row(2, 2, 3, 3, 6),
+                              row(2, 4, 3, 6, 12),
+                              row(4, 8, 2, 12, 24));
+
+                assertRowsNet(executeNetWithPaging("SELECT * FROM %s GROUP BY a, b PER PARTITION LIMIT 1", pageSize),
+                              row(1, 2, 1, 3, 6),
+                              row(2, 2, 3, 3, 6),
+                              row(4, 8, 2, 12, 24));
+
                 // Range queries without aggregates and with LIMIT
                 assertRowsNet(executeNetWithPaging("SELECT a, b, c, d FROM %s GROUP BY a, b, c LIMIT 3", pageSize),
                               row(1, 2, 1, 3),
@@ -1010,6 +1235,12 @@ public class SelectGroupByTest extends CQLTester
                               row(1, 2, 2, 6),
                               row(2, 2, 3, 3));
 
+                // Range queries with wildcard, with PER PARTITION LIMIT and LIMIT
+                assertRowsNet(executeNetWithPaging("SELECT * FROM %s GROUP BY a, b, c PER PARTITION LIMIT 2 LIMIT 3", pageSize),
+                              row(1, 2, 1, 3, 6),
+                              row(1, 2, 2, 6, 12),
+                              row(2, 2, 3, 3, 6));
+
                 // Range query with DISTINCT
                 assertRowsNet(executeNetWithPaging("SELECT DISTINCT a, count(a)FROM %s GROUP BY a", pageSize),
                               row(1, 1L),
@@ -1060,6 +1291,16 @@ public class SelectGroupByTest extends CQLTester
                               row(1, 2, 2, 6),
                               row(1, 4, 2, 6));
 
+                // Single partition queries with wildcard
+                assertRowsNet(executeNetWithPaging("SELECT * FROM %s WHERE a = 1 GROUP BY a, b, c", pageSize),
+                           row(1, 2, 1, 3, 6),
+                           row(1, 2, 2, 6, 12),
+                           row(1, 4, 2, 6, 12));
+
+                assertRowsNet(executeNetWithPaging("SELECT * FROM %s WHERE a = 1 GROUP BY a, b", pageSize),
+                           row(1, 2, 1, 3, 6),
+                           row(1, 4, 2, 6, 12));
+
                 // Single partition query with DISTINCT
                 assertRowsNet(executeNetWithPaging("SELECT DISTINCT a, count(a)FROM %s WHERE a = 1 GROUP BY a",
                                                    pageSize),
@@ -1089,6 +1330,22 @@ public class SelectGroupByTest extends CQLTester
                                                    pageSize),
                               row(1L, 6));
 
+                // Single partition queries with wildcard and with LIMIT
+                assertRowsNet(executeNetWithPaging("SELECT * FROM %s WHERE a = 1 GROUP BY a, b, c LIMIT 2", pageSize),
+                           row(1, 2, 1, 3, 6),
+                           row(1, 2, 2, 6, 12));
+
+                assertRowsNet(executeNetWithPaging("SELECT * FROM %s WHERE a = 1 GROUP BY a, b LIMIT 1", pageSize),
+                           row(1, 2, 1, 3, 6));
+
+                // Single partition queries with wildcard and with PER PARTITION LIMIT
+                assertRowsNet(executeNetWithPaging("SELECT * FROM %s WHERE a = 1 GROUP BY a, b, c PER PARTITION LIMIT 2", pageSize),
+                           row(1, 2, 1, 3, 6),
+                           row(1, 2, 2, 6, 12));
+
+                assertRowsNet(executeNetWithPaging("SELECT * FROM %s WHERE a = 1 GROUP BY a, b PER PARTITION LIMIT 1", pageSize),
+                           row(1, 2, 1, 3, 6));
+
                 // Single partition query with PER PARTITION LIMIT
                 assertRowsNet(executeNetWithPaging("SELECT a, b, e, count(b), max(e) FROM %s WHERE a = 1 GROUP BY a, b, c PER PARTITION LIMIT 2",
                                                    pageSize),
@@ -1194,6 +1451,22 @@ public class SelectGroupByTest extends CQLTester
                               row(2, 4, 3, 6),
                               row(4, 8, 2, 12));
 
+                // Multi-partitions with wildcard
+                assertRowsNet(executeNetWithPaging("SELECT * FROM %s WHERE a IN (1, 2, 4) GROUP BY a, b, c", pageSize),
+                           row(1, 2, 1, 3, 6),
+                           row(1, 2, 2, 6, 12),
+                           row(1, 4, 2, 6, 12),
+                           row(2, 2, 3, 3, 6),
+                           row(2, 4, 3, 6, 12),
+                           row(4, 8, 2, 12, 24));
+
+                assertRowsNet(executeNetWithPaging("SELECT * FROM %s WHERE a IN (1, 2, 4) GROUP BY a, b", pageSize),
+                           row(1, 2, 1, 3, 6),
+                           row(1, 4, 2, 6, 12),
+                           row(2, 2, 3, 3, 6),
+                           row(2, 4, 3, 6, 12),
+                           row(4, 8, 2, 12, 24));
+
                 // Multi-partitions queries with DISTINCT
                 assertRowsNet(executeNetWithPaging("SELECT DISTINCT a, count(a)FROM %s WHERE a IN (1, 2, 4) GROUP BY a",
                                                    pageSize),
@@ -1329,6 +1602,12 @@ public class SelectGroupByTest extends CQLTester
                           row(2, null, 2),
                           row(4, null, 3));
 
+            // Range query with wildcard
+            assertRowsNet(executeNetWithPaging("SELECT * FROM %s GROUP BY a, b", pageSize),
+                       row(1, null, null, 1, null),
+                       row(2, null, null, 2, null),
+                       row(4, null, null, 3, null ));
+
             // Range query with LIMIT
             assertRowsNet(executeNetWithPaging("SELECT a, b, s, count(b), count(s) FROM %s GROUP BY a, b LIMIT 2",
                                                pageSize),
@@ -1382,6 +1661,10 @@ public class SelectGroupByTest extends CQLTester
             assertRowsNet(executeNetWithPaging("SELECT a, b, s FROM %s WHERE a = 1 GROUP BY a, b", pageSize),
                           row(1, null, 1));
 
+            // Single partition query with wildcard
+            assertRowsNet(executeNetWithPaging("SELECT * FROM %s WHERE a = 1 GROUP BY a, b", pageSize),
+                       row(1, null, null, 1, null));
+
             // Single partition queries with LIMIT
             assertRowsNet(executeNetWithPaging("SELECT a, b, s, count(b), count(s) FROM %s WHERE a = 1 GROUP BY a, b LIMIT 2",
                                                pageSize),
@@ -1533,6 +1816,21 @@ public class SelectGroupByTest extends CQLTester
                           row(4, 8, null),
                           row(3, null, 3));
 
+            // Range queries with wildcard
+            assertRowsNet(executeNetWithPaging("SELECT * FROM %s GROUP BY a", pageSize),
+                       row(1, 2, 1, 1, 3),
+                       row(2, 2, 3, 2, 3),
+                       row(4, 8, 2, null, 12),
+                       row(3, null, null, 3, null));
+
+            assertRowsNet(executeNetWithPaging("SELECT * FROM %s GROUP BY a, b", pageSize),
+                       row(1, 2, 1, 1, 3),
+                       row(1, 4, 2, 1, 12),
+                       row(2, 2, 3, 2, 3),
+                       row(2, 4, 3, 2, 6),
+                       row(4, 8, 2, null, 12),
+                       row(3, null, null, 3, null));
+
             // Range query with LIMIT
             assertRowsNet(executeNetWithPaging("SELECT a, b, s, count(b), count(s) FROM %s GROUP BY a LIMIT 2",
                                                pageSize),
@@ -1555,6 +1853,19 @@ public class SelectGroupByTest extends CQLTester
                           row(4, 8, null),
                           row(3, null, 3));
 
+            // Range queries with wildcard and with LIMIT
+            assertRowsNet(executeNetWithPaging("SELECT * FROM %s GROUP BY a LIMIT 2", pageSize),
+                       row(1, 2, 1, 1, 3),
+                       row(2, 2, 3, 2, 3));
+
+            assertRowsNet(executeNetWithPaging("SELECT * FROM %s GROUP BY a, b LIMIT 10", pageSize),
+                       row(1, 2, 1, 1, 3),
+                       row(1, 4, 2, 1, 12),
+                       row(2, 2, 3, 2, 3),
+                       row(2, 4, 3, 2, 6),
+                       row(4, 8, 2, null, 12),
+                       row(3, null, null, 3, null));
+
             // Range queries with PER PARTITION LIMIT
             assertRowsNet(executeNetWithPaging("SELECT a, b, s, count(b), count(s) FROM %s GROUP BY a, b PER PARTITION LIMIT 2", pageSize),
                           row(1, 2, 1, 2L, 2L),
@@ -1570,6 +1881,13 @@ public class SelectGroupByTest extends CQLTester
                           row(4, 8, null, 1L, 0L),
                           row(3, null, 3, 0L, 1L));
 
+            // Range queries with wildcard and PER PARTITION LIMIT
+            assertRowsNet(executeNetWithPaging("SELECT * FROM %s GROUP BY a, b PER PARTITION LIMIT 1", pageSize),
+                       row(1, 2, 1, 1, 3),
+                       row(2, 2, 3, 2, 3),
+                       row(4, 8, 2, null, 12),
+                       row(3, null, null, 3, null));
+
             // Range queries with PER PARTITION LIMIT and LIMIT
             assertRowsNet(executeNetWithPaging("SELECT a, b, s, count(b), count(s) FROM %s GROUP BY a, b PER PARTITION LIMIT 2 LIMIT 3", pageSize),
                           row(1, 2, 1, 2L, 2L),
@@ -1581,6 +1899,11 @@ public class SelectGroupByTest extends CQLTester
                           row(2, 2, 2, 1L, 1L),
                           row(4, 8, null, 1L, 0L));
 
+            // Range queries with wildcard, PER PARTITION LIMIT and LIMIT
+            assertRowsNet(executeNetWithPaging("SELECT * FROM %s GROUP BY a, b PER PARTITION LIMIT 1 LIMIT 2", pageSize),
+                       row(1, 2, 1, 1, 3),
+                       row(2, 2, 3, 2, 3));
+
             // Range query without aggregates and with PER PARTITION LIMIT
             assertRowsNet(executeNetWithPaging("SELECT a, b, s FROM %s GROUP BY a, b PER PARTITION LIMIT 1", pageSize),
                           row(1, 2, 1),
@@ -1635,6 +1958,13 @@ public class SelectGroupByTest extends CQLTester
             assertRowsNet(executeNetWithPaging("SELECT a, b, s FROM %s WHERE a = 4 GROUP BY a, b", pageSize),
                           row(4, 8, null));
 
+            // Single partition queries with wildcard
+            assertRowsNet(executeNetWithPaging("SELECT * FROM %s WHERE a = 1 GROUP BY a", pageSize),
+                       row(1, 2, 1, 1, 3));
+
+            assertRowsNet(executeNetWithPaging("SELECT * FROM %s WHERE a = 4 GROUP BY a, b", pageSize),
+                       row(4, 8, 2, null, 12));
+
             // Single partition queries with LIMIT
             assertRowsNet(executeNetWithPaging("SELECT a, b, s, count(b), count(s) FROM %s WHERE a = 2 GROUP BY a, b LIMIT 1",
                                                pageSize),
@@ -1726,6 +2056,21 @@ public class SelectGroupByTest extends CQLTester
                           row(3, null, 3),
                           row(4, 8, null));
 
+            // Multi-partitions queries with wildcard
+            assertRowsNet(executeNetWithPaging("SELECT * FROM %s WHERE a IN (1, 2, 3, 4) GROUP BY a", pageSize),
+                       row(1, 2, 1, 1, 3),
+                       row(2, 2, 3, 2, 3),
+                       row(3, null, null, 3, null),
+                       row(4, 8, 2, null, 12));
+
+            assertRowsNet(executeNetWithPaging("SELECT * FROM %s WHERE a IN (1, 2, 3, 4) GROUP BY a, b", pageSize),
+                       row(1, 2, 1, 1, 3),
+                       row(1, 4, 2, 1, 12),
+                       row(2, 2, 3, 2, 3),
+                       row(2, 4, 3, 2, 6),
+                       row(3, null, null, 3, null),
+                       row(4, 8, 2, null, 12));
+
             // Multi-partitions queries with LIMIT
             assertRowsNet(executeNetWithPaging("SELECT a, b, s, count(b), count(s) FROM %s WHERE a IN (1, 2, 3, 4) GROUP BY a LIMIT 2",
                                                pageSize),


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org
For additional commands, e-mail: commits-help@cassandra.apache.org


[4/4] cassandra git commit: Merge branch cassandra-3.11 into trunk

Posted by bl...@apache.org.
Merge branch cassandra-3.11 into trunk


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/f74b0ea7
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/f74b0ea7
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/f74b0ea7

Branch: refs/heads/trunk
Commit: f74b0ea752419c6b08cf6be63ace55948fdf0a83
Parents: 6544040 515f07b
Author: Benjamin Lerer <b....@gmail.com>
Authored: Thu Feb 15 11:01:48 2018 +0100
Committer: Benjamin Lerer <b....@gmail.com>
Committed: Thu Feb 15 11:04:24 2018 +0100

----------------------------------------------------------------------
 CHANGES.txt                                     |   3 +
 .../cassandra/cql3/selection/Selection.java     |  14 +
 .../cql3/statements/SelectStatement.java        |  37 +-
 .../cql3/validation/entities/JsonTest.java      |  25 ++
 .../operations/SelectGroupByTest.java           | 345 +++++++++++++++++++
 5 files changed, 415 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/f74b0ea7/CHANGES.txt
----------------------------------------------------------------------
diff --cc CHANGES.txt
index 5fcb335,e858781..c37901a
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@@ -1,198 -1,7 +1,201 @@@
 +4.0
 + * Add a few options to nodetool verify (CASSANDRA-14201)
 + * CVE-2017-5929 Security vulnerability and redefine default log rotation policy (CASSANDRA-14183)
 + * Use JVM default SSL validation algorithm instead of custom default (CASSANDRA-13259)
 + * Better document in code InetAddressAndPort usage post 7544, incorporate port into UUIDGen node (CASSANDRA-14226)
 + * Fix sstablemetadata date string for minLocalDeletionTime (CASSANDRA-14132)
 + * Make it possible to change neverPurgeTombstones during runtime (CASSANDRA-14214)
 + * Remove GossipDigestSynVerbHandler#doSort() (CASSANDRA-14174)
 + * Add nodetool clientlist (CASSANDRA-13665)
 + * Revert ProtocolVersion changes from CASSANDRA-7544 (CASSANDRA-14211)
 + * Non-disruptive seed node list reload (CASSANDRA-14190)
 + * Nodetool tablehistograms to print statics for all the tables (CASSANDRA-14185)
 + * Migrate dtests to use pytest and python3 (CASSANDRA-14134)
 + * Allow storage port to be configurable per node (CASSANDRA-7544)
 + * Make sub-range selection for non-frozen collections return null instead of empty (CASSANDRA-14182)
 + * BloomFilter serialization format should not change byte ordering (CASSANDRA-9067)
 + * Remove unused on-heap BloomFilter implementation (CASSANDRA-14152)
 + * Delete temp test files on exit (CASSANDRA-14153)
 + * Make PartitionUpdate and Mutation immutable (CASSANDRA-13867)
 + * Fix CommitLogReplayer exception for CDC data (CASSANDRA-14066)
 + * Fix cassandra-stress startup failure (CASSANDRA-14106)
 + * Remove initialDirectories from CFS (CASSANDRA-13928)
 + * Fix trivial log format error (CASSANDRA-14015)
 + * Allow sstabledump to do a json object per partition (CASSANDRA-13848)
 + * Add option to optimise merkle tree comparison across replicas (CASSANDRA-3200)
 + * Remove unused and deprecated methods from AbstractCompactionStrategy (CASSANDRA-14081)
 + * Fix Distribution.average in cassandra-stress (CASSANDRA-14090)
 + * Support a means of logging all queries as they were invoked (CASSANDRA-13983)
 + * Presize collections (CASSANDRA-13760)
 + * Add GroupCommitLogService (CASSANDRA-13530)
 + * Parallelize initial materialized view build (CASSANDRA-12245)
 + * Fix flaky SecondaryIndexManagerTest.assert[Not]MarkedAsBuilt (CASSANDRA-13965)
 + * Make LWTs send resultset metadata on every request (CASSANDRA-13992)
 + * Fix flaky indexWithFailedInitializationIsNotQueryableAfterPartialRebuild (CASSANDRA-13963)
 + * Introduce leaf-only iterator (CASSANDRA-9988)
 + * Upgrade Guava to 23.3 and Airline to 0.8 (CASSANDRA-13997)
 + * Allow only one concurrent call to StatusLogger (CASSANDRA-12182)
 + * Refactoring to specialised functional interfaces (CASSANDRA-13982)
 + * Speculative retry should allow more friendly params (CASSANDRA-13876)
 + * Throw exception if we send/receive repair messages to incompatible nodes (CASSANDRA-13944)
 + * Replace usages of MessageDigest with Guava's Hasher (CASSANDRA-13291)
 + * Add nodetool cmd to print hinted handoff window (CASSANDRA-13728)
 + * Fix some alerts raised by static analysis (CASSANDRA-13799)
 + * Checksum sstable metadata (CASSANDRA-13321, CASSANDRA-13593)
 + * Add result set metadata to prepared statement MD5 hash calculation (CASSANDRA-10786)
 + * Refactor GcCompactionTest to avoid boxing (CASSANDRA-13941)
 + * Expose recent histograms in JmxHistograms (CASSANDRA-13642)
 + * Fix buffer length comparison when decompressing in netty-based streaming (CASSANDRA-13899)
 + * Properly close StreamCompressionInputStream to release any ByteBuf (CASSANDRA-13906)
 + * Add SERIAL and LOCAL_SERIAL support for cassandra-stress (CASSANDRA-13925)
 + * LCS needlessly checks for L0 STCS candidates multiple times (CASSANDRA-12961)
 + * Correctly close netty channels when a stream session ends (CASSANDRA-13905)
 + * Update lz4 to 1.4.0 (CASSANDRA-13741)
 + * Optimize Paxos prepare and propose stage for local requests (CASSANDRA-13862)
 + * Throttle base partitions during MV repair streaming to prevent OOM (CASSANDRA-13299)
 + * Use compaction threshold for STCS in L0 (CASSANDRA-13861)
 + * Fix problem with min_compress_ratio: 1 and disallow ratio < 1 (CASSANDRA-13703)
 + * Add extra information to SASI timeout exception (CASSANDRA-13677)
 + * Add incremental repair support for --hosts, --force, and subrange repair (CASSANDRA-13818)
 + * Rework CompactionStrategyManager.getScanners synchronization (CASSANDRA-13786)
 + * Add additional unit tests for batch behavior, TTLs, Timestamps (CASSANDRA-13846)
 + * Add keyspace and table name in schema validation exception (CASSANDRA-13845)
 + * Emit metrics whenever we hit tombstone failures and warn thresholds (CASSANDRA-13771)
 + * Make netty EventLoopGroups daemon threads (CASSANDRA-13837)
 + * Race condition when closing stream sessions (CASSANDRA-13852)
 + * NettyFactoryTest is failing in trunk on macOS (CASSANDRA-13831)
 + * Allow changing log levels via nodetool for related classes (CASSANDRA-12696)
 + * Add stress profile yaml with LWT (CASSANDRA-7960)
 + * Reduce memory copies and object creations when acting on ByteBufs (CASSANDRA-13789)
 + * Simplify mx4j configuration (Cassandra-13578)
 + * Fix trigger example on 4.0 (CASSANDRA-13796)
 + * Force minumum timeout value (CASSANDRA-9375)
 + * Use netty for streaming (CASSANDRA-12229)
 + * Use netty for internode messaging (CASSANDRA-8457)
 + * Add bytes repaired/unrepaired to nodetool tablestats (CASSANDRA-13774)
 + * Don't delete incremental repair sessions if they still have sstables (CASSANDRA-13758)
 + * Fix pending repair manager index out of bounds check (CASSANDRA-13769)
 + * Don't use RangeFetchMapCalculator when RF=1 (CASSANDRA-13576)
 + * Don't optimise trivial ranges in RangeFetchMapCalculator (CASSANDRA-13664)
 + * Use an ExecutorService for repair commands instead of new Thread(..).start() (CASSANDRA-13594)
 + * Fix race / ref leak in anticompaction (CASSANDRA-13688)
 + * Expose tasks queue length via JMX (CASSANDRA-12758)
 + * Fix race / ref leak in PendingRepairManager (CASSANDRA-13751)
 + * Enable ppc64le runtime as unsupported architecture (CASSANDRA-13615)
 + * Improve sstablemetadata output (CASSANDRA-11483)
 + * Support for migrating legacy users to roles has been dropped (CASSANDRA-13371)
 + * Introduce error metrics for repair (CASSANDRA-13387)
 + * Refactoring to primitive functional interfaces in AuthCache (CASSANDRA-13732)
 + * Update metrics to 3.1.5 (CASSANDRA-13648)
 + * batch_size_warn_threshold_in_kb can now be set at runtime (CASSANDRA-13699)
 + * Avoid always rebuilding secondary indexes at startup (CASSANDRA-13725)
 + * Upgrade JMH from 1.13 to 1.19 (CASSANDRA-13727)
 + * Upgrade SLF4J from 1.7.7 to 1.7.25 (CASSANDRA-12996)
 + * Default for start_native_transport now true if not set in config (CASSANDRA-13656)
 + * Don't add localhost to the graph when calculating where to stream from (CASSANDRA-13583)
 + * Make CDC availability more deterministic via hard-linking (CASSANDRA-12148)
 + * Allow skipping equality-restricted clustering columns in ORDER BY clause (CASSANDRA-10271)
 + * Use common nowInSec for validation compactions (CASSANDRA-13671)
 + * Improve handling of IR prepare failures (CASSANDRA-13672)
 + * Send IR coordinator messages synchronously (CASSANDRA-13673)
 + * Flush system.repair table before IR finalize promise (CASSANDRA-13660)
 + * Fix column filter creation for wildcard queries (CASSANDRA-13650)
 + * Add 'nodetool getbatchlogreplaythrottle' and 'nodetool setbatchlogreplaythrottle' (CASSANDRA-13614)
 + * fix race condition in PendingRepairManager (CASSANDRA-13659)
 + * Allow noop incremental repair state transitions (CASSANDRA-13658)
 + * Run repair with down replicas (CASSANDRA-10446)
 + * Added started & completed repair metrics (CASSANDRA-13598)
 + * Added started & completed repair metrics (CASSANDRA-13598)
 + * Improve secondary index (re)build failure and concurrency handling (CASSANDRA-10130)
 + * Improve calculation of available disk space for compaction (CASSANDRA-13068)
 + * Change the accessibility of RowCacheSerializer for third party row cache plugins (CASSANDRA-13579)
 + * Allow sub-range repairs for a preview of repaired data (CASSANDRA-13570)
 + * NPE in IR cleanup when columnfamily has no sstables (CASSANDRA-13585)
 + * Fix Randomness of stress values (CASSANDRA-12744)
 + * Allow selecting Map values and Set elements (CASSANDRA-7396)
 + * Fast and garbage-free Streaming Histogram (CASSANDRA-13444)
 + * Update repairTime for keyspaces on completion (CASSANDRA-13539)
 + * Add configurable upper bound for validation executor threads (CASSANDRA-13521)
 + * Bring back maxHintTTL propery (CASSANDRA-12982)
 + * Add testing guidelines (CASSANDRA-13497)
 + * Add more repair metrics (CASSANDRA-13531)
 + * RangeStreamer should be smarter when picking endpoints for streaming (CASSANDRA-4650)
 + * Avoid rewrapping an exception thrown for cache load functions (CASSANDRA-13367)
 + * Log time elapsed for each incremental repair phase (CASSANDRA-13498)
 + * Add multiple table operation support to cassandra-stress (CASSANDRA-8780)
 + * Fix incorrect cqlsh results when selecting same columns multiple times (CASSANDRA-13262)
 + * Fix WriteResponseHandlerTest is sensitive to test execution order (CASSANDRA-13421)
 + * Improve incremental repair logging (CASSANDRA-13468)
 + * Start compaction when incremental repair finishes (CASSANDRA-13454)
 + * Add repair streaming preview (CASSANDRA-13257)
 + * Cleanup isIncremental/repairedAt usage (CASSANDRA-13430)
 + * Change protocol to allow sending key space independent of query string (CASSANDRA-10145)
 + * Make gc_log and gc_warn settable at runtime (CASSANDRA-12661)
 + * Take number of files in L0 in account when estimating remaining compaction tasks (CASSANDRA-13354)
 + * Skip building views during base table streams on range movements (CASSANDRA-13065)
 + * Improve error messages for +/- operations on maps and tuples (CASSANDRA-13197)
 + * Remove deprecated repair JMX APIs (CASSANDRA-11530)
 + * Fix version check to enable streaming keep-alive (CASSANDRA-12929)
 + * Make it possible to monitor an ideal consistency level separate from actual consistency level (CASSANDRA-13289)
 + * Outbound TCP connections ignore internode authenticator (CASSANDRA-13324)
 + * Upgrade junit from 4.6 to 4.12 (CASSANDRA-13360)
 + * Cleanup ParentRepairSession after repairs (CASSANDRA-13359)
 + * Upgrade snappy-java to 1.1.2.6 (CASSANDRA-13336)
 + * Incremental repair not streaming correct sstables (CASSANDRA-13328)
 + * Upgrade the jna version to 4.3.0 (CASSANDRA-13300)
 + * Add the currentTimestamp, currentDate, currentTime and currentTimeUUID functions (CASSANDRA-13132)
 + * Remove config option index_interval (CASSANDRA-10671)
 + * Reduce lock contention for collection types and serializers (CASSANDRA-13271)
 + * Make it possible to override MessagingService.Verb ids (CASSANDRA-13283)
 + * Avoid synchronized on prepareForRepair in ActiveRepairService (CASSANDRA-9292)
 + * Adds the ability to use uncompressed chunks in compressed files (CASSANDRA-10520)
 + * Don't flush sstables when streaming for incremental repair (CASSANDRA-13226)
 + * Remove unused method (CASSANDRA-13227)
 + * Fix minor bugs related to #9143 (CASSANDRA-13217)
 + * Output warning if user increases RF (CASSANDRA-13079)
 + * Remove pre-3.0 streaming compatibility code for 4.0 (CASSANDRA-13081)
 + * Add support for + and - operations on dates (CASSANDRA-11936)
 + * Fix consistency of incrementally repaired data (CASSANDRA-9143)
 + * Increase commitlog version (CASSANDRA-13161)
 + * Make TableMetadata immutable, optimize Schema (CASSANDRA-9425)
 + * Refactor ColumnCondition (CASSANDRA-12981)
 + * Parallelize streaming of different keyspaces (CASSANDRA-4663)
 + * Improved compactions metrics (CASSANDRA-13015)
 + * Speed-up start-up sequence by avoiding un-needed flushes (CASSANDRA-13031)
 + * Use Caffeine (W-TinyLFU) for on-heap caches (CASSANDRA-10855)
 + * Thrift removal (CASSANDRA-11115)
 + * Remove pre-3.0 compatibility code for 4.0 (CASSANDRA-12716)
 + * Add column definition kind to dropped columns in schema (CASSANDRA-12705)
 + * Add (automate) Nodetool Documentation (CASSANDRA-12672)
 + * Update bundled cqlsh python driver to 3.7.0 (CASSANDRA-12736)
 + * Reject invalid replication settings when creating or altering a keyspace (CASSANDRA-12681)
 + * Clean up the SSTableReader#getScanner API wrt removal of RateLimiter (CASSANDRA-12422)
 + * Use new token allocation for non bootstrap case as well (CASSANDRA-13080)
 + * Avoid byte-array copy when key cache is disabled (CASSANDRA-13084)
 + * Require forceful decommission if number of nodes is less than replication factor (CASSANDRA-12510)
 + * Allow IN restrictions on column families with collections (CASSANDRA-12654)
 + * Log message size in trace message in OutboundTcpConnection (CASSANDRA-13028)
 + * Add timeUnit Days for cassandra-stress (CASSANDRA-13029)
 + * Add mutation size and batch metrics (CASSANDRA-12649)
 + * Add method to get size of endpoints to TokenMetadata (CASSANDRA-12999)
 + * Expose time spent waiting in thread pool queue (CASSANDRA-8398)
 + * Conditionally update index built status to avoid unnecessary flushes (CASSANDRA-12969)
 + * cqlsh auto completion: refactor definition of compaction strategy options (CASSANDRA-12946)
 + * Add support for arithmetic operators (CASSANDRA-11935)
 + * Add histogram for delay to deliver hints (CASSANDRA-13234)
 + * Fix cqlsh automatic protocol downgrade regression (CASSANDRA-13307)
 + * Changing `max_hint_window_in_ms` at runtime (CASSANDRA-11720)
 + * Trivial format error in StorageProxy (CASSANDRA-13551)
 + * Nodetool repair can hang forever if we lose the notification for the repair completing/failing (CASSANDRA-13480)
 + * Anticompaction can cause noisy log messages (CASSANDRA-13684)
 + * Switch to client init for sstabledump (CASSANDRA-13683)
 + * CQLSH: Don't pause when capturing data (CASSANDRA-13743)
 + * nodetool clearsnapshot requires --all to clear all snapshots (CASSANDRA-13391)
 + * Correctly count range tombstones in traces and tombstone thresholds (CASSANDRA-8527)
 +
+ 3.11.3
+  * Fix wildcard GROUP BY queries (CASSANDRA-14209)
 -Merged from 2.1
 - * CVE-2017-5929 Security vulnerability in Logback warning in NEWS.txt (CASSANDRA-14183)
++
  
  3.11.2
   * Fix ReadCommandTest (CASSANDRA-14234)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/f74b0ea7/src/java/org/apache/cassandra/cql3/selection/Selection.java
----------------------------------------------------------------------
diff --cc src/java/org/apache/cassandra/cql3/selection/Selection.java
index 80494ba,93a71b8..aaef468
--- a/src/java/org/apache/cassandra/cql3/selection/Selection.java
+++ b/src/java/org/apache/cassandra/cql3/selection/Selection.java
@@@ -24,15 -24,21 +24,16 @@@ import com.google.common.base.MoreObjec
  import com.google.common.base.Predicate;
  import com.google.common.collect.Iterables;
  import com.google.common.collect.Iterators;
++import com.google.common.collect.Lists;
  
 -import org.apache.cassandra.config.CFMetaData;
 -import org.apache.cassandra.config.ColumnDefinition;
  import org.apache.cassandra.cql3.*;
  import org.apache.cassandra.cql3.functions.Function;
 -import org.apache.cassandra.db.Clustering;
 -import org.apache.cassandra.db.DecoratedKey;
 -import org.apache.cassandra.db.aggregation.AggregationSpecification;
 -import org.apache.cassandra.db.aggregation.GroupMaker;
 -import org.apache.cassandra.db.context.CounterContext;
 +import org.apache.cassandra.db.filter.ColumnFilter;
  import org.apache.cassandra.db.marshal.UTF8Type;
 -import org.apache.cassandra.db.rows.Cell;
  import org.apache.cassandra.exceptions.InvalidRequestException;
 +import org.apache.cassandra.schema.ColumnMetadata;
 +import org.apache.cassandra.schema.TableMetadata;
  import org.apache.cassandra.transport.ProtocolVersion;
 -import org.apache.cassandra.utils.ByteBufferUtil;
  
  public abstract class Selection
  {
@@@ -99,16 -140,35 +100,29 @@@
          return new ResultSet.ResultMetadata(Arrays.asList(jsonSpec));
      }
  
 -    public static Selection wildcard(CFMetaData cfm)
 +    public static Selection wildcard(TableMetadata table, boolean isJson)
      {
 -        List<ColumnDefinition> all = new ArrayList<>(cfm.allColumns().size());
 -        Iterators.addAll(all, cfm.allColumnsInSelectOrder());
 -        return new SimpleSelection(cfm, all, true);
 +        List<ColumnMetadata> all = new ArrayList<>(table.columns().size());
 +        Iterators.addAll(all, table.allColumnsInSelectOrder());
 +        return new SimpleSelection(table, all, Collections.emptySet(), true, isJson);
      }
  
 -    public static Selection wildcardWithGroupBy(CFMetaData cfm, VariableSpecifications boundNames)
++    public static Selection wildcardWithGroupBy(TableMetadata table,
++                                                VariableSpecifications boundNames,
++                                                boolean isJson)
+     {
 -        List<RawSelector> rawSelectors = new ArrayList<>(cfm.allColumns().size());
 -        Iterator<ColumnDefinition> iter = cfm.allColumnsInSelectOrder();
 -        while (iter.hasNext())
 -        {
 -            ColumnDefinition.Raw raw = ColumnDefinition.Raw.forColumn(iter.next());
 -            rawSelectors.add(new RawSelector(raw, null));
 -        }
 -        return fromSelectors(cfm, rawSelectors, boundNames, true);
 -    }
 -
 -    public static Selection forColumns(CFMetaData cfm, List<ColumnDefinition> columns)
 -    {
 -        return new SimpleSelection(cfm, columns, false);
++        return fromSelectors(table,
++                             Lists.newArrayList(table.allColumnsInSelectOrder()),
++                             boundNames,
++                             Collections.emptySet(),
++                             Collections.emptySet(),
++                             true,
++                             isJson);
+     }
+ 
 -    public int addColumnForOrdering(ColumnDefinition c)
 +    public static Selection forColumns(TableMetadata table, List<ColumnMetadata> columns)
      {
 -        columns.add(c);
 -        metadata.addNonSerializedColumn(c);
 -        return columns.size() - 1;
 +        return new SimpleSelection(table, columns, Collections.emptySet(), false, false);
      }
  
      public void addFunctionsTo(List<Function> functions)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/f74b0ea7/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
----------------------------------------------------------------------
diff --cc src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
index 3754ee6,a7ba6aa..ae206a5
--- a/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
@@@ -929,36 -948,19 +929,32 @@@ public class SelectStatement implement
              this.perPartitionLimit = perPartitionLimit;
          }
  
 -        public ParsedStatement.Prepared prepare(ClientState clientState) throws InvalidRequestException
 +        public ParsedStatement.Prepared prepare() throws InvalidRequestException
          {
 -            return prepare(false, clientState);
 +            return prepare(false);
          }
  
 -        public ParsedStatement.Prepared prepare(boolean forView, ClientState clientState) throws InvalidRequestException
 +        public ParsedStatement.Prepared prepare(boolean forView) throws InvalidRequestException
          {
 -            CFMetaData cfm = ThriftValidation.validateColumnFamilyWithCompactMode(keyspace(), columnFamily(), clientState.isNoCompactMode());
 +            TableMetadata table = Schema.instance.validateTable(keyspace(), columnFamily());
              VariableSpecifications boundNames = getBoundVariables();
  
 -            Selection selection = prepareSelection(cfm, boundNames);
 +            List<Selectable> selectables = RawSelector.toSelectables(selectClause, table);
 +            boolean containsOnlyStaticColumns = selectOnlyStaticColumns(table, selectables);
 +
 +            StatementRestrictions restrictions = prepareRestrictions(table, boundNames, containsOnlyStaticColumns, forView);
 +
 +            // If we order post-query, the sorted column needs to be in the ResultSet for sorting,
 +            // even if we don't ultimately ship them to the client (CASSANDRA-4911).
 +            Map<ColumnMetadata, Boolean> orderingColumns = getOrderingColumns(table);
 +            Set<ColumnMetadata> resultSetOrderingColumns = restrictions.keyIsInRelation() ? orderingColumns.keySet()
 +                                                                                          : Collections.emptySet();
  
-             Selection selection = selectables.isEmpty()
-                     ? Selection.wildcard(table, parameters.isJson)
-                     : Selection.fromSelectors(table,
-                                               selectables,
-                                               boundNames,
-                                               resultSetOrderingColumns,
-                                               restrictions.nonPKRestrictedColumns(false),
-                                               !parameters.groups.isEmpty(),
-                                               parameters.isJson);
 -            StatementRestrictions restrictions = prepareRestrictions(cfm, boundNames, selection, forView);
++            Selection selection = prepareSelection(table,
++                                                   selectables,
++                                                   boundNames,
++                                                   resultSetOrderingColumns,
++                                                   restrictions);
  
              if (parameters.isDistinct)
              {
@@@ -1000,41 -1002,24 +996,64 @@@
                                                         prepareLimit(boundNames, limit, keyspace(), limitReceiver()),
                                                         prepareLimit(boundNames, perPartitionLimit, keyspace(), perPartitionLimitReceiver()));
  
 -            return new ParsedStatement.Prepared(stmt, boundNames, boundNames.getPartitionKeyBindIndexes(cfm));
 +            return new ParsedStatement.Prepared(stmt, boundNames, boundNames.getPartitionKeyBindIndexes(table));
 +        }
 +
++        private Selection prepareSelection(TableMetadata table,
++                                           List<Selectable> selectables,
++                                           VariableSpecifications boundNames,
++                                           Set<ColumnMetadata> resultSetOrderingColumns,
++                                           StatementRestrictions restrictions)
++        {
++            boolean hasGroupBy = !parameters.groups.isEmpty();
++
++            if (selectables.isEmpty()) // wildcard query
++            {
++                return hasGroupBy ? Selection.wildcardWithGroupBy(table, boundNames, parameters.isJson)
++                                  : Selection.wildcard(table, parameters.isJson);
++            }
++
++            return Selection.fromSelectors(table,
++                                           selectables,
++                                           boundNames,
++                                           resultSetOrderingColumns,
++                                           restrictions.nonPKRestrictedColumns(false),
++                                           hasGroupBy,
++                                           parameters.isJson);
+         }
+ 
          /**
 -         * Prepares the selection to use for the statement.
 +         * Checks if the specified selectables select only partition key columns or static columns
           *
 -         * @param cfm the table metadata
 -         * @param boundNames the bound names
 -         * @return the selection to use for the statement
 +         * @param table the table metadata
 +         * @param selectables the selectables to check
 +         * @return {@code true} if the specified selectables select only partition key columns or static columns,
 +         * {@code false} otherwise.
           */
 -        private Selection prepareSelection(CFMetaData cfm, VariableSpecifications boundNames)
 +        private boolean selectOnlyStaticColumns(TableMetadata table, List<Selectable> selectables)
          {
 -            boolean hasGroupBy = !parameters.groups.isEmpty();
 +            if (table.isStaticCompactTable() || !table.hasStaticColumns() || selectables.isEmpty())
 +                return false;
  
 -            if (selectClause.isEmpty())
 -                return hasGroupBy ? Selection.wildcardWithGroupBy(cfm, boundNames) : Selection.wildcard(cfm);
 +            return Selectable.selectColumns(selectables, (column) -> column.isStatic())
 +                    && !Selectable.selectColumns(selectables, (column) -> !column.isPartitionKey() && !column.isStatic());
 +        }
 +
 +        /**
 +         * Returns the columns used to order the data.
 +         * @return the columns used to order the data.
 +         */
 +        private Map<ColumnMetadata, Boolean> getOrderingColumns(TableMetadata table)
 +        {
 +            if (parameters.orderings.isEmpty())
 +                return Collections.emptyMap();
  
 -            return Selection.fromSelectors(cfm, selectClause, boundNames, hasGroupBy);
 +            Map<ColumnMetadata, Boolean> orderingColumns = new LinkedHashMap<>();
 +            for (Map.Entry<ColumnMetadata.Raw, Boolean> entry : parameters.orderings.entrySet())
 +            {
 +                orderingColumns.put(entry.getKey().prepare(table), entry.getValue());
 +            }
 +            return orderingColumns;
          }
  
          /**

http://git-wip-us.apache.org/repos/asf/cassandra/blob/f74b0ea7/test/unit/org/apache/cassandra/cql3/validation/entities/JsonTest.java
----------------------------------------------------------------------


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org
For additional commands, e-mail: commits-help@cassandra.apache.org