cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ble...@apache.org
Subject [1/3] cassandra git commit: Fix regression in select count with limit
Date Mon, 12 Oct 2015 19:45:37 GMT
Repository: cassandra
Updated Branches:
  refs/heads/trunk 20026a84c -> d8994896c


Fix regression in select count with limit

patch by Benjamin Lerer; reviewed by Sylvain Lebresne for CASSANDRA-10487


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

Branch: refs/heads/trunk
Commit: 20c0acc149c2e1a921ca1e7d64a017207077687b
Parents: 0c051a4
Author: blerer <benjamin.lerer@datastax.com>
Authored: Mon Oct 12 21:37:06 2015 +0200
Committer: blerer <benjamin.lerer@datastax.com>
Committed: Mon Oct 12 21:37:06 2015 +0200

----------------------------------------------------------------------
 CHANGES.txt                                                   | 3 ++-
 NEWS.txt                                                      | 3 +++
 .../org/apache/cassandra/cql3/statements/SelectStatement.java | 4 ++++
 .../cassandra/cql3/validation/operations/AggregationTest.java | 7 +++++++
 4 files changed, 16 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/20c0acc1/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index efae4ab..0714076 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,3 +1,5 @@
+2.2.4
+ * Fix the regression when using LIMIT with aggregates (CASSANDRA-10487)
 2.2.3
  * Avoid NoClassDefFoundError during DataDescriptor initialization on windows (CASSANDRA-10412)
  * Preserve case of quoted Role & User names (CASSANDRA-10394)
@@ -8,7 +10,6 @@ Merged from 2.1:
  * Allow LOCAL_JMX to be easily overridden (CASSANDRA-10275)
  * Mark nodes as dead even if they've already left (CASSANDRA-10205)
  * Update internal python driver used by cqlsh (CASSANDRA-10161)
-
 2.2.2
  * cqlsh prompt includes name of keyspace after failed `use` statement (CASSANDRA-10369)
  * Configurable page size in cqlsh (CASSANDRA-9855)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/20c0acc1/NEWS.txt
----------------------------------------------------------------------
diff --git a/NEWS.txt b/NEWS.txt
index 69f2412..5808cdf 100644
--- a/NEWS.txt
+++ b/NEWS.txt
@@ -75,6 +75,9 @@ New features
 
 New features
 ------------
+   - The LIMIT clause applies now only to the number of rows returned to the user,
+     not to the number of row queried. By consequence, queries using aggregates will not
+     be impacted by the LIMIT clause anymore.
    - Very large batches will now be rejected (defaults to 50kb). This
      can be customized by modifying batch_size_fail_threshold_in_kb.
    - Selecting columns,scalar functions, UDT fields, writetime or ttl together

http://git-wip-us.apache.org/repos/asf/cassandra/blob/20c0acc1/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 3edb7d0..e6ac6c0 100644
--- a/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
@@ -536,6 +536,10 @@ public class SelectStatement implements CQLStatement
 
     private int updateLimitForQuery(int limit)
     {
+        // If the query is for an aggregate, we do not want to limit the number of rows retrieved.
The LIMIT
+        // clause apply to the number of rows returned to the user and not to the number
of rows retrieved.
+        if (selection.isAggregate())
+            return Integer.MAX_VALUE;
         // Internally, we don't support exclusive bounds for slices. Instead, we query one
more element if necessary
         // and exclude it later (in processColumnFamily)
         return restrictions.isNonCompositeSliceWithExclusiveBounds() && limit !=
Integer.MAX_VALUE

http://git-wip-us.apache.org/repos/asf/cassandra/blob/20c0acc1/test/unit/org/apache/cassandra/cql3/validation/operations/AggregationTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/validation/operations/AggregationTest.java
b/test/unit/org/apache/cassandra/cql3/validation/operations/AggregationTest.java
index b2ecd04..1649654 100644
--- a/test/unit/org/apache/cassandra/cql3/validation/operations/AggregationTest.java
+++ b/test/unit/org/apache/cassandra/cql3/validation/operations/AggregationTest.java
@@ -90,6 +90,10 @@ public class AggregationTest extends CQLTester
         assertRows(execute("SELECT COUNT(*) FROM %s"), row(4L));
         assertRows(execute("SELECT COUNT(1) FROM %s"), row(4L));
         assertRows(execute("SELECT COUNT(b), count(c), count(e), count(f) FROM %s"), row(4L,
3L, 3L, 3L));
+        // Makes sure that LIMIT does not affect the result of aggregates
+        assertRows(execute("SELECT COUNT(b), count(c), count(e), count(f) FROM %s LIMIT 2"),
row(4L, 3L, 3L, 3L));
+        assertRows(execute("SELECT COUNT(b), count(c), count(e), count(f) FROM %s WHERE a
= 1 LIMIT 2"),
+                   row(4L, 3L, 3L, 3L));
     }
 
     @Test
@@ -129,6 +133,9 @@ public class AggregationTest extends CQLTester
         assertRows(execute("SELECT COUNT(1) FROM %s"), row(4L));
         assertRows(execute("SELECT max(b), b, COUNT(*) FROM %s"), row(5, 1, 4L));
         assertRows(execute("SELECT max(b), COUNT(1), b FROM %s"), row(5, 4L, 1));
+        // Makes sure that LIMIT does not affect the result of aggregates
+        assertRows(execute("SELECT max(b), COUNT(1), b FROM %s LIMIT 2"), row(5, 4L, 1));
+        assertRows(execute("SELECT max(b), COUNT(1), b FROM %s WHERE a = 1 LIMIT 2"), row(5,
4L, 1));
     }
 
     @Test


Mime
View raw message