cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alek...@apache.org
Subject [1/2] git commit: Handle CQL3 SELECT duplicate IN restrictions on clustering columns
Date Sat, 17 Aug 2013 15:47:30 GMT
Updated Branches:
  refs/heads/cassandra-2.0.0 0ad0031fd -> 21771dfbd


Handle CQL3 SELECT duplicate IN restrictions on clustering columns

patch by Aleksey Yeschenko; reviewed by Jonathan Ellis for
CASSANDRA-5856


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

Branch: refs/heads/cassandra-2.0.0
Commit: 3529ac711e5588918afcc8b514aa03c67a9adac7
Parents: 4140977
Author: Aleksey Yeschenko <aleksey@apache.org>
Authored: Sat Aug 17 18:40:09 2013 +0300
Committer: Aleksey Yeschenko <aleksey@apache.org>
Committed: Sat Aug 17 18:40:09 2013 +0300

----------------------------------------------------------------------
 CHANGES.txt                                     |  2 ++
 .../cql3/statements/SelectStatement.java        | 33 +++++++-------------
 2 files changed, 14 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/3529ac71/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index f44cdb9..60e5cdc 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -17,6 +17,8 @@
    (CASSANDRA-5718)
  * Add KeyCacheHitRate metric to CF metrics (CASSANDRA-5868)
  * cqlsh: add support for multiline comments (CASSANDRA-5798)
+ * Handle CQL3 SELECT duplicate IN restrictions on clustering columns
+   (CASSANDRA-5856)
 Merged from 1.1:
  * Correctly validate sparse composite cells in scrub (CASSANDRA-5855)
 

http://git-wip-us.apache.org/repos/asf/cassandra/blob/3529ac71/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 4f559e5..44a1e64 100644
--- a/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
@@ -350,12 +350,6 @@ public class SelectStatement implements CQLStatement
             }
             else
             {
-                // The IN query might not have listed the values in comparator order, so
we need to re-sort
-                // the bounds lists to make sure the slices works correctly
-                Comparator<ByteBuffer> cmp = isReversed ? cfDef.cfm.comparator.reverseComparator
: cfDef.cfm.comparator;
-                Collections.sort(startBounds, cmp);
-                Collections.sort(endBounds, cmp);
-
                 List<ColumnSlice> l = new ArrayList<ColumnSlice>(startBounds.size());
                 for (int i = 0; i < startBounds.size(); i++)
                 {
@@ -368,12 +362,7 @@ public class SelectStatement implements CQLStatement
                 slices = l.toArray(new ColumnSlice[l.size()]);
             }
 
-            SliceQueryFilter filter = new SliceQueryFilter(slices,
-                                                           isReversed,
-                                                           getLimit(),
-                                                           toGroup,
-                                                           multiplier);
-            return filter;
+            return new SliceQueryFilter(slices, isReversed, getLimit(), toGroup, multiplier);
         }
         else
         {
@@ -581,12 +570,12 @@ public class SelectStatement implements CQLStatement
         return false;
     }
 
-    private static List<ByteBuffer> buildBound(Bound bound,
-                                               Collection<CFDefinition.Name> names,
-                                               Restriction[] restrictions,
-                                               boolean isReversed,
-                                               ColumnNameBuilder builder,
-                                               List<ByteBuffer> variables) throws InvalidRequestException
+    private List<ByteBuffer> buildBound(Bound bound,
+                                        Collection<CFDefinition.Name> names,
+                                        Restriction[] restrictions,
+                                        boolean isReversed,
+                                        ColumnNameBuilder builder,
+                                        List<ByteBuffer> variables) throws InvalidRequestException
     {
         // The end-of-component of composite doesn't depend on whether the
         // component type is reversed or not (i.e. the ReversedType is applied
@@ -616,7 +605,9 @@ public class SelectStatement implements CQLStatement
                 {
                     // IN query, we only support it on the clustering column
                     assert name.position == names.size() - 1;
-                    List<ByteBuffer> l = new ArrayList<ByteBuffer>(r.eqValues.size());
+                    // The IN query might not have listed the values in comparator order,
so we need to re-sort
+                    // the bounds lists to make sure the slices works correctly (also, to
avoid duplicates).
+                    TreeSet<ByteBuffer> s = new TreeSet<ByteBuffer>(isReversed
? cfDef.cfm.comparator.reverseComparator : cfDef.cfm.comparator);
                     for (Term t : r.eqValues)
                     {
                         ByteBuffer val = t.bindAndGet(variables);
@@ -624,9 +615,9 @@ public class SelectStatement implements CQLStatement
                             throw new InvalidRequestException(String.format("Invalid null
clustering key part %s", name));
                         ColumnNameBuilder copy = builder.copy().add(val);
                         // See below for why this
-                        l.add((bound == Bound.END && copy.remainingCount() > 0)
? copy.buildAsEndOfRange() : copy.build());
+                        s.add((bound == Bound.END && copy.remainingCount() > 0)
? copy.buildAsEndOfRange() : copy.build());
                     }
-                    return l;
+                    return new ArrayList<ByteBuffer>(s);
                 }
 
                 ByteBuffer val = r.eqValues.get(0).bindAndGet(variables);


Mime
View raw message