Cannot perform slice reads in reverse direction against tables with clustering 
columns in mixed order

patch by Aleksey Yeschenko; reviewed by Alex Petrov for CASSANDRA-14899


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

Branch: refs/heads/cassandra-3.0
Commit: cf6f7920f7742bb9a17a23ad37499d9213807d81
Parents: dcd92a9
Author: Aleksey Yeshchenko <alek...@apple.com>
Authored: Thu Nov 15 14:54:05 2018 +0000
Committer: Aleksey Yeshchenko <alek...@apple.com>
Committed: Tue Nov 20 15:19:28 2018 +0000

----------------------------------------------------------------------
 CHANGES.txt                                     |  5 ++++
 .../restrictions/PrimaryKeyRestrictionSet.java  | 24 +++++++++++--------
 .../SelectMultiColumnRelationTest.java          | 25 ++++++++++++++++++++
 3 files changed, 44 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/cf6f7920/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 71c57ea..bca036d 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,7 +1,10 @@
 2.2.14
+ * Cannot perform slice reads in reverse direction against tables with 
clustering columns
+   in mixed order (CASSANDRA-14899)
  * Fix incorrect cqlsh results when selecting same columns multiple times 
(CASSANDRA-13262)
  * Returns null instead of NaN or Infinity in JSON strings (CASSANDRA-14377)
 
+
 2.2.13
  * Fix bug that prevented compaction of SSTables after full repairs 
(CASSANDRA-14423)
  * Incorrect counting of pending messages in OutboundTcpConnection 
(CASSANDRA-11551)
@@ -15,6 +18,7 @@ Merged from 2.1:
  * Check checksum before decompressing data (CASSANDRA-14284)
  * CVE-2017-5929 Security vulnerability in Logback warning in NEWS.txt 
(CASSANDRA-14183)
 
+
 2.2.12
  * Fix the inspectJvmOptions startup check (CASSANDRA-14112)
  * Fix race that prevents submitting compaction for a table when executor is 
full (CASSANDRA-13801)
@@ -25,6 +29,7 @@ Merged from 2.1:
  * More PEP8 compliance for cqlsh (CASSANDRA-14021)
  * RPM package spec: fix permissions for installed jars and config files 
(CASSANDRA-14181)
 
+
 2.2.11
  * Safely handle empty buffers when outputting to JSON (CASSANDRA-13868)
  * Copy session properties on cqlsh.py do_login (CASSANDRA-13847)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/cf6f7920/src/java/org/apache/cassandra/cql3/restrictions/PrimaryKeyRestrictionSet.java
----------------------------------------------------------------------
diff --git 
a/src/java/org/apache/cassandra/cql3/restrictions/PrimaryKeyRestrictionSet.java 
b/src/java/org/apache/cassandra/cql3/restrictions/PrimaryKeyRestrictionSet.java
index 2549bdf..5136fee 100644
--- 
a/src/java/org/apache/cassandra/cql3/restrictions/PrimaryKeyRestrictionSet.java
+++ 
b/src/java/org/apache/cassandra/cql3/restrictions/PrimaryKeyRestrictionSet.java
@@ -20,8 +20,6 @@ package org.apache.cassandra.cql3.restrictions;
 import java.nio.ByteBuffer;
 import java.util.*;
 
-import com.google.common.collect.Lists;
-
 import org.apache.cassandra.config.CFMetaData;
 import org.apache.cassandra.config.ColumnDefinition;
 import org.apache.cassandra.cql3.QueryOptions;
@@ -195,14 +193,12 @@ final class PrimaryKeyRestrictionSet extends 
AbstractPrimaryKeyRestrictions impl
                 // It is clearly a hack but it does not make a lot of sense to 
refactor 2.2 for that as the problem is
                 // already solved in 3.0.
                 List<Composite> composites = filterAndSort(setEocs(r, bound, 
builder.build()));
-                return Lists.transform(composites, new 
com.google.common.base.Function<Composite, Composite>()
-                {
-                    @Override
-                    public Composite apply(Composite composite)
-                    {
-                        return composite.isEmpty() ? Composites.EMPTY: 
composite;
-                    }
-                });
+
+                for (Composite c : composites)
+                    if (c.isEmpty())
+                        return normalizeEmptyComposites(composites);
+
+                return composites;
             }
 
             r.appendBoundTo(cfm, builder, bound, options);
@@ -239,6 +235,14 @@ final class PrimaryKeyRestrictionSet extends 
AbstractPrimaryKeyRestrictions impl
         return new ArrayList<>(set);
     }
 
+    private List<Composite> normalizeEmptyComposites(List<Composite> 
composites)
+    {
+        List<Composite> transformed = new ArrayList<>(composites.size());
+        for (Composite c : composites)
+            transformed.add(c.isEmpty() ? Composites.EMPTY : c);
+        return transformed;
+    }
+
     /**
      * Sets EOCs for the composites returned by the specified slice 
restriction for the given bound.
      *

http://git-wip-us.apache.org/repos/asf/cassandra/blob/cf6f7920/test/unit/org/apache/cassandra/cql3/validation/operations/SelectMultiColumnRelationTest.java
----------------------------------------------------------------------
diff --git 
a/test/unit/org/apache/cassandra/cql3/validation/operations/SelectMultiColumnRelationTest.java
 
b/test/unit/org/apache/cassandra/cql3/validation/operations/SelectMultiColumnRelationTest.java
index 0975662..4e5a1e6 100644
--- 
a/test/unit/org/apache/cassandra/cql3/validation/operations/SelectMultiColumnRelationTest.java
+++ 
b/test/unit/org/apache/cassandra/cql3/validation/operations/SelectMultiColumnRelationTest.java
@@ -1886,6 +1886,31 @@ public class SelectMultiColumnRelationTest extends 
CQLTester
         }
     }
 
+    @Test
+    public void testMixedOrderColumnsInReverse() throws Throwable
+    {
+        createTable("CREATE TABLE %s (a int, b int, c int, PRIMARY KEY (a, b, 
c)) WITH CLUSTERING ORDER BY (b ASC, c DESC);");
+
+        execute("INSERT INTO %s (a, b, c) VALUES (0, 1, 3)");
+        execute("INSERT INTO %s (a, b, c) VALUES (0, 1, 2)");
+        execute("INSERT INTO %s (a, b, c) VALUES (0, 1, 1)");
+
+        execute("INSERT INTO %s (a, b, c) VALUES (0, 2, 3)");
+        execute("INSERT INTO %s (a, b, c) VALUES (0, 2, 2)");
+        execute("INSERT INTO %s (a, b, c) VALUES (0, 2, 1)");
+
+        execute("INSERT INTO %s (a, b, c) VALUES (0, 3, 3)");
+        execute("INSERT INTO %s (a, b, c) VALUES (0, 3, 2)");
+        execute("INSERT INTO %s (a, b, c) VALUES (0, 3, 1)");
+
+        assertRows(execute("SELECT b, c FROM %s WHERE a = 0 AND (b, c) >= (2, 
2) ORDER BY b DESC, c ASC;"),
+                   row(3, 1),
+                   row(3, 2),
+                   row(3, 3),
+                   row(2, 2),
+                   row(2, 3));
+    }
+
     /**
      * Check select on tuple relations, see CASSANDRA-8613
      * migrated from cql_tests.py:TestCQL.simple_tuple_query_test()


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

Reply via email to