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.le...@gmail.com> Authored: Thu Feb 15 10:59:28 2018 +0100 Committer: Benjamin Lerer <b.le...@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-unsubscr...@cassandra.apache.org For additional commands, e-mail: commits-h...@cassandra.apache.org